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 ofIteratorwhich 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 booleanhasNext()static <T> java.lang.Iterable<T>makeIterable(T[] array)Use as a convience whenIterableis the desired interface.static <T> java.lang.Iterable<T>makeIterable(T[] array, boolean newInstanceOnCall)Use as a convience whenIterableis the desired interface.static <T> java.util.Iterator<T>makeIterator(T[] array)Construct a newIteratorthat will start at position zero of the provided array.Tnext()voidreset()Reset the iterator back to position0.
-
-
-
Method Detail
-
makeIterator
public static <T> java.util.Iterator<T> makeIterator(T[] array)
Construct a newIteratorthat 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
Iteratorthat will go over the provided array
-
makeIterable
public static <T> java.lang.Iterable<T> makeIterable(T[] array)
Use as a convience whenIterableis the desired interface. This is equivalent to callingmakeIterable(Object[], boolean)with atrueto specify new instances on iteration.- Type Parameters:
T- The type of object to iterate over- Parameters:
array- Array to be iterated over- Returns:
- An
Iterablethat will go over the array
-
makeIterable
public static <T> java.lang.Iterable<T> makeIterable(T[] array, boolean newInstanceOnCall)Use as a convience whenIterableis the desired interface. If the returnedIterablewont be invoked concurrently, then this can be called to reuse theIteratorinstance by simply passingfalsefornewInstanceOnCall. Iftrueis 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. Iffalseis provided then the returnedIteratorwill be reset each time.- Type Parameters:
T- The type of object to iterate over- Parameters:
array- Array to be iterated overnewInstanceOnCall-trueto create new instances on each invocation ofIterable.iterator()- Returns:
- An
Iterablethat will go over the array
-
hasNext
public boolean hasNext()
- Specified by:
hasNextin interfacejava.util.Iterator<T>
-
reset
public void reset()
Reset the iterator back to position0.
-
-