Package com.saicone.types.iterator
Class ArrayIterator<T>
java.lang.Object
com.saicone.types.AnyIterator<T>
com.saicone.types.iterator.ArrayIterator<T>
- Type Parameters:
T
- the array type.
- All Implemented Interfaces:
Iterator<T>
,ListIterator<T>
Abstract class to iterate into any array.
Accepts any type of primitive and object array.
Accepts any type of primitive and object array.
-
Field Summary
Fields inherited from class com.saicone.types.AnyIterator
value
-
Constructor Summary
ConstructorsConstructorDescriptionArrayIterator
(@NotNull Object value) Constructs an array iterator with provided array object.ArrayIterator
(@NotNull Object value, int currentIndex) Constructs an array iterator with provided array object and starting index. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add value to array at specified index.void
get
(int index) Returns the value of the indexed component in the specified array object.boolean
hasNext()
boolean
boolean
Check if the current array iterator corresponds to an object array.next()
int
static <T> @NotNull ArrayIterator
<T> 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.previous()
int
void
remove()
void
remove
(int index) Remove value form array at specified index.void
Set value to array at specified index.void
int
size()
Returns the length of the specified array object, as an int.Methods inherited from class com.saicone.types.AnyIterator
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
-
Constructor Details
-
ArrayIterator
Constructs an array iterator with provided array object.- Parameters:
value
- the array to iterate.
-
ArrayIterator
Constructs an array iterator with provided array object and starting index.- Parameters:
value
- the array to iterate.currentIndex
- the index to start the iteration.
-
-
Method Details
-
of
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
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
-
hasPrevious
public boolean hasPrevious()- Specified by:
hasPrevious
in interfaceListIterator<T>
-
previous
- Specified by:
previous
in interfaceListIterator<T>
-
nextIndex
public int nextIndex()- Specified by:
nextIndex
in interfaceListIterator<T>
-
previousIndex
public int previousIndex()- Specified by:
previousIndex
in interfaceListIterator<T>
-
remove
public void remove() -
remove
public void remove(int index) Remove value form array at specified index.- Parameters:
index
- the index to remove.
-
set
- Specified by:
set
in interfaceListIterator<T>
-
set
Set value to array at specified index.- Parameters:
index
- the index to set.t
- the value to set.
-
add
- Specified by:
add
in interfaceListIterator<T>
-
add
Add value to array at specified index.- Parameters:
index
- the index to add.t
- the value to add.
-