Class AbstractGuavaIterator<T>
- java.lang.Object
-
- org.apache.cassandra.utils.AbstractGuavaIterator<T>
-
- All Implemented Interfaces:
com.google.common.collect.PeekingIterator<T>
,java.util.Iterator<T>
- Direct Known Subclasses:
KeyRangeIterator
,RangeIterator
@NotThreadSafe public abstract class AbstractGuavaIterator<T> extends java.lang.Object implements com.google.common.collect.PeekingIterator<T>
This is fork of the Guava AbstractIterator, the only difference is that the next variable is now protected so that the KeyRangeIterator.skipTo method can avoid early state changed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractGuavaIterator.State
-
Field Summary
Fields Modifier and Type Field Description protected T
next
protected AbstractGuavaIterator.State
state
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractGuavaIterator()
Constructor for use by subclasses.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract T
computeNext()
Returns the next element.protected T
endOfData()
Implementations ofcomputeNext()
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 ofPeekingIterator.peek()
.void
remove()
protected boolean
tryToComputeNext()
-
-
-
Field Detail
-
state
protected AbstractGuavaIterator.State state
-
next
protected T next
-
-
Method Detail
-
computeNext
protected abstract T 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 ofhasNext
ornext
following each successful call tonext
. Once the implementation either invokesendOfData
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
ornext
invocation 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, anIllegalStateException
will result.- Returns:
- the next element if there was one. If
endOfData
was called during execution, the return value will be ignored. - Throws:
java.lang.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
protected final T endOfData()
Implementations ofcomputeNext()
must invoke this method when there are no elements left in the iteration.- Returns:
null
; a convenience so yourcomputeNext
implementation can use the simple statementreturn endOfData();
-
hasNext
public final boolean hasNext()
- Specified by:
hasNext
in interfacejava.util.Iterator<T>
-
tryToComputeNext
protected boolean tryToComputeNext()
-
next
public final T next()
-
remove
public void remove()
-
peek
public final T peek()
Returns the next element in the iteration without advancing the iteration, according to the contract ofPeekingIterator.peek()
.Implementations of
AbstractIterator
that wish to expose this functionality should implementPeekingIterator
.- Specified by:
peek
in interfacecom.google.common.collect.PeekingIterator<T>
-
-