Class AbstractGuavaIterator<T>
- All Implemented Interfaces:
com.google.common.collect.PeekingIterator<T>,Iterator<T>
- Direct Known Subclasses:
KeyRangeIterator,RangeIterator
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor for use by subclasses. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract TReturns the next element.protected final TImplementations ofcomputeNext()must invoke this method when there are no elements left in the iteration.final booleanhasNext()final Tnext()final Tpeek()Returns the next element in the iteration without advancing the iteration, according to the contract ofPeekingIterator.peek().voidremove()protected booleanMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining
-
Field Details
-
state
-
next
-
-
Constructor Details
-
AbstractGuavaIterator
protected AbstractGuavaIterator()Constructor for use by subclasses.
-
-
Method Details
-
computeNext
Returns the next element. Note: the implementation must callendOfData()when there are no elements left in the iteration. Failure to do so could result in an infinite loop.The initial invocation of
hasNext()ornext()calls this method, as does the first invocation ofhasNextornextfollowing each successful call tonext. Once the implementation either invokesendOfDataor throws an exception,computeNextis guaranteed to never be called again.If this method throws an exception, it will propagate outward to the
hasNextornextinvocation that invoked this method. Any further attempts to use the iterator will result in anIllegalStateException.The implementation of this method may not invoke the
hasNext,next, orpeek()methods on this instance; if it does, anIllegalStateExceptionwill result.- Returns:
- the next element if there was one. If
endOfDatawas called during execution, the return value will be ignored. - Throws:
RuntimeException- if any unrecoverable error happens. This exception will propagate outward to thehasNext(),next(), orpeek()invocation that invoked this method. Any further attempts to use the iterator will result in anIllegalStateException.
-
endOfData
Implementations ofcomputeNext()must invoke this method when there are no elements left in the iteration.- Returns:
null; a convenience so yourcomputeNextimplementation can use the simple statementreturn endOfData();
-
hasNext
public final boolean hasNext() -
tryToComputeNext
protected boolean tryToComputeNext() -
next
-
remove
public void remove() -
peek
Returns the next element in the iteration without advancing the iteration, according to the contract ofPeekingIterator.peek().Implementations of
AbstractIteratorthat wish to expose this functionality should implementPeekingIterator.- Specified by:
peekin interfacecom.google.common.collect.PeekingIterator<T>
-