Class GenericIterator<T>

java.lang.Object
org.javimmutable.collections.iterators.AbstractSplitableIterator<T>
org.javimmutable.collections.iterators.GenericIterator<T>
All Implemented Interfaces:
Iterator<T>, SplitableIterator<T>

@ThreadSafe public class GenericIterator<T> extends AbstractSplitableIterator<T>
A mutable class implementing the SplitableIterator interface in a reusable way. Maintains a current position in the collection it iterates over and delegates to a "state" object provided by the collection to move forward inside the collection. To implement spliterator functionality for parallel streams it limits itself to a specific subset of the collection by way of an offset (current position) and limit (stopping position).
  • Constructor Details

  • Method Details

    • hasNext

      public boolean hasNext()
    • next

      public T next()
    • isSplitAllowed

      public boolean isSplitAllowed()
      Description copied from interface: SplitableIterator
      Tests to determine if this Iterator is capable of splitting into two new Iterators.
    • splitIterator

      @Nonnull public SplitIterator<T> splitIterator()
      Description copied from interface: SplitableIterator
      Whenever isSplitAllowed returns true this method can be used to create two new SplitableIterators that collectively visit all the same elements as this Iterator. Whenever isSplitAllowed returns false this method throws UnsupportedOperationException.
      Returns:
      two new SplitableIterators spanning the same elements as this
    • singleValueState

      public static <T> GenericIterator.State<T> singleValueState(GenericIterator.State<T> parent, T value, int offset, int limit)
      Returns a State for iterating a single value.
    • singleValueIterable

      public static <T> GenericIterator.Iterable<T> singleValueIterable(T value)
      Returns an Iterable for iterating a single value.
    • multiValueState

      public static <T> GenericIterator.State<T> multiValueState(@Nullable GenericIterator.State<T> parent, @Nonnull Indexed<T> values, int offset, int limit)
      Returns a State for iterating multiple values stored in an Indexed collection.
    • multiIterableState

      public static <T> GenericIterator.State<T> multiIterableState(@Nullable GenericIterator.State<T> parent, @Nonnull Indexed<? extends GenericIterator.Iterable<T>> children, int offset, int limit)
      Returns a State for iterating multiple collections (Iterables) that are themselves stored in an Indexed collection.
    • transformState

      public static <A, B> GenericIterator.State<B> transformState(@Nullable GenericIterator.State<B> parent, @Nullable GenericIterator.State<A> source, @Nonnull Func1<A,B> transforminator)
      Returns a State for iterating over another State's values but transforming each of those values using a function before returning to its caller.
    • transformIterable

      public static <A, B> GenericIterator.Iterable<B> transformIterable(@Nonnull GenericIterator.Iterable<A> source, @Nonnull Func1<A,B> transforminator)
      Returns an Iterable for iterating over another Iterable's values but transforming each of those values using a function before returning to its caller.