Interface GenericIterator.State<T>
- Enclosing class:
GenericIterator<T>
public static interface GenericIterator.State<T>
Interface for objects that track the current position of an iteration in progress.
Unlike an Iterator which "looks ahead" to the next position (hasNext/next) a
State object "lives in the moment" and knows the current position (hasValue/value)
and doesn't know if a next value exists until told to go there (advance).
These do not need to be thread safe.
-
Method Summary
Modifier and TypeMethodDescriptionadvance()
Try to move forward to the next position.static <T> GenericIterator.State
<T> advanceToNextValue
(GenericIterator.State<T> state) Advances past current value (if any) and then chains calls toadvance()
until wither a value is reached or null is returned.static <T> GenericIterator.State
<T> advanceUntilHasValue
(GenericIterator.State<T> state) Chains calls toadvance()
until wither a value is reached or null is returned.default boolean
hasValue()
default T
value()
-
Method Details
-
hasValue
default boolean hasValue() -
value
-
advance
Try to move forward to the next position. Returns either a valid state (if next position exists) or null (if there is no next position). The returned State might be this State object or a new State, or null. The returned State might have a value or it might be empty and in need of another call toadvance()
to reach a value. -
advanceUntilHasValue
Chains calls toadvance()
until wither a value is reached or null is returned. If already at a value just returns the state. -
advanceToNextValue
Advances past current value (if any) and then chains calls toadvance()
until wither a value is reached or null is returned.
-