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 Details

    • hasValue

      default boolean hasValue()
    • value

      default T 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 to advance() to reach a value.
    • advanceUntilHasValue

      static <T> GenericIterator.State<T> advanceUntilHasValue(GenericIterator.State<T> state)
      Chains calls to advance() until wither a value is reached or null is returned. If already at a value just returns the state.
    • advanceToNextValue

      static <T> GenericIterator.State<T> advanceToNextValue(GenericIterator.State<T> state)
      Advances past current value (if any) and then chains calls to advance() until wither a value is reached or null is returned.