@GwtCompatible public abstract class AbstractSequentialIterator<T> extends UnmodifiableIterator<T>
Iterator
interface for sequences whose next element can always be derived from the
previous element. Null elements are not supported, nor is the
UnmodifiableIterator.remove()
method.
Example:
Iterator<Integer> powersOfTwo =
new AbstractSequentialIterator<Integer>(1) {
protected Integer computeNext(Integer previous) {
return (previous == 1 << 30) ? null : previous * 2;
}
};
AbstractLinkedIterator
since 8.0)Modifier | Constructor and Description |
---|---|
protected |
AbstractSequentialIterator(T firstOrNull)
Creates a new iterator with the given first element, or, if
firstOrNull is null, creates a new empty iterator. |
Modifier and Type | Method and Description |
---|---|
protected abstract T |
computeNext(T previous)
Returns the element that follows
previous , or returns null
if no elements remain. |
boolean |
hasNext()
Returns
true if the iteration has more elements. |
T |
next()
Returns the next element in the iteration.
|
remove
protected AbstractSequentialIterator(@Nullable T firstOrNull)
firstOrNull
is null, creates a new empty iterator.protected abstract T computeNext(T previous)
previous
, or returns null
if no elements remain. This method is invoked during each call to
next()
in order to compute the result of a future call to
next()
.public final boolean hasNext()
java.util.Iterator
true
if the iteration has more elements.
(In other words, returns true
if Iterator.next()
would
return an element rather than throwing an exception.)true
if the iteration has more elementspublic final T next()
java.util.Iterator
Copyright © 2010-2013. All Rights Reserved.