Package com.saicone.types.iterator
Class ArrayIterator<T>
- java.lang.Object
-
- com.saicone.types.TypeIterator<T>
-
- com.saicone.types.iterator.ArrayIterator<T>
-
- Type Parameters:
T
- the array type.
- All Implemented Interfaces:
Iterator<T>
public abstract class ArrayIterator<T> extends TypeIterator<T>
Abstract class to iterate into any array.
Accepts any type of primitive and object array.
-
-
Field Summary
-
Fields inherited from class com.saicone.types.TypeIterator
value
-
-
Constructor Summary
Constructors Constructor Description ArrayIterator(@NotNull Object value)
Constructs an array iterator with provided array object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description T
get(int index)
Returns the value of the indexed component in the specified array object.boolean
hasNext()
boolean
isObjectArray()
Check if the current array iterator corresponds to an object array.T
next()
static <T> @NotNull ArrayIterator<T>
of(@NotNull Object value)
Create a read-only array iterator.static <T> @NotNull ArrayIterator<T>
of(@NotNull Object value, @NotNull TypeParser<T> parser)
Create a read-only array iterator with associated type parser.void
remove()
void
remove(int index)
Remove value form array at specified index.int
size()
Returns the length of the specified array object, as an int.-
Methods inherited from class com.saicone.types.TypeIterator
getValue, setValue
-
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
-
-
-
-
Method Detail
-
of
@NotNull public static <T> @NotNull ArrayIterator<T> of(@NotNull @NotNull Object value)
Create a read-only array iterator.- Type Parameters:
T
- the array type.- Parameters:
value
- the array to iterate.- Returns:
- an array iterator.
-
of
@NotNull public static <T> @NotNull ArrayIterator<T> of(@NotNull @NotNull Object value, @NotNull @NotNull TypeParser<T> parser)
Create a read-only array iterator with associated type parser.- Type Parameters:
T
- the type of type parser.- Parameters:
value
- the array to iterate.parser
- the parser to use while iteration.- Returns:
- a parsed type array iterator.
-
isObjectArray
public boolean isObjectArray()
Check if the current array iterator corresponds to an object array.- Returns:
- true if the current array is an object array.
-
size
public int size()
Returns the length of the specified array object, as an int.- Returns:
- the length of the array.
-
get
public T get(int index)
Returns the value of the indexed component in the specified array object. The value is automatically wrapped in an object if it has a primitive type.- Parameters:
index
- the index.- Returns:
- the (possibly wrapped) value of the indexed component in the specified array.
-
hasNext
public boolean hasNext()
-
next
public T next()
-
remove
public void remove()
-
remove
public void remove(int index)
Remove value form array at specified index.- Parameters:
index
- the index.
-
-