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>
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).
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Interface for collections that can be iterated over by GenericIterator using State objects to track the progress of the iteration.static interface
Interface for objects that track the current position of an iteration in progress. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
hasNext()
boolean
Tests to determine if this Iterator is capable of splitting into two new Iterators.static <T> GenericIterator.State
<T> multiIterableState
(GenericIterator.State<T> parent, 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.static <T> GenericIterator.State
<T> multiValueState
(GenericIterator.State<T> parent, Indexed<T> values, int offset, int limit) Returns a State for iterating multiple values stored in an Indexed collection.next()
static <T> GenericIterator.Iterable
<T> singleValueIterable
(T value) Returns an Iterable for iterating a single value.static <T> GenericIterator.State
<T> singleValueState
(GenericIterator.State<T> parent, T value, int offset, int limit) Returns a State for iterating a single value.Whenever isSplitAllowed returns true this method can be used to create two new SplitableIterators that collectively visit all the same elements as this Iterator.static <A,
B> GenericIterator.Iterable <B> transformIterable
(GenericIterator.Iterable<A> source, 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.static <A,
B> GenericIterator.State <B> transformState
(GenericIterator.State<B> parent, GenericIterator.State<A> source, 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.Methods inherited from class org.javimmutable.collections.iterators.AbstractSplitableIterator
spliterator
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Constructor Details
-
GenericIterator
-
-
Method Details
-
hasNext
public boolean hasNext() -
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
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
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.
-