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>

public abstract class ArrayIterator<T> extends AnyIterator<T> implements ListIterator<T>
Abstract class to iterate into any array.
Accepts any type of primitive and object array.
  • Constructor Details

    • ArrayIterator

      public ArrayIterator(@NotNull @NotNull Object value)
      Constructs an array iterator with provided array object.
      Parameters:
      value - the array to iterate.
    • ArrayIterator

      public ArrayIterator(@NotNull @NotNull Object value, int currentIndex)
      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

      @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()
      Specified by:
      hasNext in interface Iterator<T>
      Specified by:
      hasNext in interface ListIterator<T>
    • next

      public T next()
      Specified by:
      next in interface Iterator<T>
      Specified by:
      next in interface ListIterator<T>
    • hasPrevious

      public boolean hasPrevious()
      Specified by:
      hasPrevious in interface ListIterator<T>
    • previous

      public T previous()
      Specified by:
      previous in interface ListIterator<T>
    • nextIndex

      public int nextIndex()
      Specified by:
      nextIndex in interface ListIterator<T>
    • previousIndex

      public int previousIndex()
      Specified by:
      previousIndex in interface ListIterator<T>
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<T>
      Specified by:
      remove in interface ListIterator<T>
    • remove

      public void remove(int index)
      Remove value form array at specified index.
      Parameters:
      index - the index to remove.
    • set

      public void set(T t)
      Specified by:
      set in interface ListIterator<T>
    • set

      public void set(int index, T t)
      Set value to array at specified index.
      Parameters:
      index - the index to set.
      t - the value to set.
    • add

      public void add(T t)
      Specified by:
      add in interface ListIterator<T>
    • add

      public void add(int index, T t)
      Add value to array at specified index.
      Parameters:
      index - the index to add.
      t - the value to add.