public abstract class AbstractIterator<T>
extends java.lang.Object
implements com.google.common.collect.PeekingIterator<T>
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractIterator.State |
Modifier and Type | Field and Description |
---|---|
protected T |
next |
protected AbstractIterator.State |
state |
Modifier | Constructor and Description |
---|---|
protected |
AbstractIterator()
Constructor for use by subclasses.
|
Modifier and Type | Method and Description |
---|---|
protected abstract T |
computeNext()
Returns the next element.
|
protected T |
endOfData()
Implementations of
computeNext() must invoke this method when
there are no elements left in the iteration. |
boolean |
hasNext() |
T |
next() |
T |
peek()
Returns the next element in the iteration without advancing the iteration,
according to the contract of
PeekingIterator.peek() . |
void |
remove() |
protected boolean |
tryToComputeNext() |
protected AbstractIterator.State state
protected T next
protected abstract T computeNext()
endOfData()
when there are no elements left in the iteration. Failure to
do so could result in an infinite loop.
The initial invocation of hasNext()
or next()
calls
this method, as does the first invocation of hasNext
or next
following each successful call to next
. Once the
implementation either invokes endOfData
or throws an exception,
computeNext
is guaranteed to never be called again.
If this method throws an exception, it will propagate outward to the
hasNext
or next
invocation that invoked this method. Any
further attempts to use the iterator will result in an IllegalStateException
.
The implementation of this method may not invoke the hasNext
,
next
, or peek()
methods on this instance; if it does, an
IllegalStateException
will result.
endOfData
was called
during execution, the return value will be ignored.java.lang.RuntimeException
- if any unrecoverable error happens. This exception
will propagate outward to the hasNext()
, next()
, or
peek()
invocation that invoked this method. Any further
attempts to use the iterator will result in an
IllegalStateException
.protected final T endOfData()
computeNext()
must invoke this method when
there are no elements left in the iteration.null
; a convenience so your computeNext
implementation can use the simple statement return endOfData();
public final boolean hasNext()
hasNext
in interface java.util.Iterator<T>
protected boolean tryToComputeNext()
public final T next()
public void remove()
public final T peek()
PeekingIterator.peek()
.
Implementations of AbstractIterator
that wish to expose this
functionality should implement PeekingIterator
.
peek
in interface com.google.common.collect.PeekingIterator<T>
Copyright © 2009-2022 The Apache Software Foundation