Package org.threadly.util
Class ArrayIterator<T>
- java.lang.Object
-
- org.threadly.util.ArrayIterator<T>
-
- Type Parameters:
T
- The type of object to iterate over
- All Implemented Interfaces:
java.util.Iterator<T>
public class ArrayIterator<T> extends java.lang.Object implements java.util.Iterator<T>
Implementation ofIterator
which will go over an Object array. Like most Iterators this class is NOT thread safe.- Since:
- 5.38
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasNext()
static <T> java.lang.Iterable<T>
makeIterable(T[] array)
Use as a convience whenIterable
is the desired interface.static <T> java.lang.Iterable<T>
makeIterable(T[] array, boolean newInstanceOnCall)
Use as a convience whenIterable
is the desired interface.static <T> java.util.Iterator<T>
makeIterator(T[] array)
Construct a newIterator
that will start at position zero of the provided array.T
next()
void
reset()
Reset the iterator back to position0
.
-
-
-
Method Detail
-
makeIterator
public static <T> java.util.Iterator<T> makeIterator(T[] array)
Construct a newIterator
that will start at position zero of the provided array.- Type Parameters:
T
- The type of object to iterate over- Parameters:
array
- Array to iterate over- Returns:
- An
Iterator
that will go over the provided array
-
makeIterable
public static <T> java.lang.Iterable<T> makeIterable(T[] array)
Use as a convience whenIterable
is the desired interface. This is equivalent to callingmakeIterable(Object[], boolean)
with atrue
to specify new instances on iteration.- Type Parameters:
T
- The type of object to iterate over- Parameters:
array
- Array to be iterated over- Returns:
- An
Iterable
that will go over the array
-
makeIterable
public static <T> java.lang.Iterable<T> makeIterable(T[] array, boolean newInstanceOnCall)
Use as a convience whenIterable
is the desired interface. If the returnedIterable
wont be invoked concurrently, then this can be called to reuse theIterator
instance by simply passingfalse
fornewInstanceOnCall
. Iftrue
is specified then a new instance will be returned on every invocation, allowing for the iterator to be created concurrently and not have the state of each iterator be impacted. Iffalse
is provided then the returnedIterator
will be reset each time.- Type Parameters:
T
- The type of object to iterate over- Parameters:
array
- Array to be iterated overnewInstanceOnCall
-true
to create new instances on each invocation ofIterable.iterator()
- Returns:
- An
Iterable
that will go over the array
-
hasNext
public boolean hasNext()
- Specified by:
hasNext
in interfacejava.util.Iterator<T>
-
reset
public void reset()
Reset the iterator back to position0
.
-
-