swim.util.Cursor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swim-util Show documentation
Show all versions of swim-util Show documentation
Extended collection, iterator, and builder interfaces, lightweight cache sets and maps, and other foundational utilities
// Copyright 2015-2019 SWIM.AI inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package swim.util;
import java.util.ListIterator;
import java.util.Map;
public interface Cursor extends ListIterator {
boolean isEmpty();
T head();
void step();
void skip(long count);
@Override
boolean hasNext();
long nextIndexLong();
@Override
default int nextIndex() {
final long k = nextIndexLong();
final int i = (int) k;
if (i != k) {
throw new IndexOutOfBoundsException("index overflow");
}
return i;
}
@Override
T next();
boolean hasPrevious();
long previousIndexLong();
@Override
default int previousIndex() {
final long k = previousIndexLong();
final int i = (int) k;
if (i != k) {
throw new IndexOutOfBoundsException("index overflow");
}
return i;
}
T previous();
@Override
default void set(T object) {
throw new UnsupportedOperationException();
}
@Override
default void add(T object) {
throw new UnsupportedOperationException();
}
@Override
default void remove() {
throw new UnsupportedOperationException();
}
default void load() throws InterruptedException {
// stub
}
static Cursor empty() {
return new CursorEmpty();
}
static Cursor unary(T value) {
return new CursorUnary(value);
}
static Cursor array(Object[] array, int index, int limit) {
return new CursorArray(array, index, limit);
}
static Cursor array(Object[] array, int index) {
return new CursorArray(array, index, array.length);
}
static Cursor array(Object[] array) {
return new CursorArray(array, 0, array.length);
}
static Cursor keys(Cursor extends Map.Entry extends K, ?>> entries) {
return new CursorKeys(entries);
}
static Cursor values(Cursor extends Map.Entry, ? extends V>> entries) {
return new CursorValues(entries);
}
}