Class 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 of Iterator 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 when Iterable is the desired interface.
      static <T> java.lang.Iterable<T> makeIterable​(T[] array, boolean newInstanceOnCall)
      Use as a convience when Iterable is the desired interface.
      static <T> java.util.Iterator<T> makeIterator​(T[] array)
      Construct a new Iterator that will start at position zero of the provided array.
      T next()  
      void reset()
      Reset the iterator back to position 0.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining, remove
    • Method Detail

      • makeIterator

        public static <T> java.util.Iterator<T> makeIterator​(T[] array)
        Construct a new Iterator 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 when Iterable is the desired interface. This is equivalent to calling makeIterable(Object[], boolean) with a true 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 when Iterable is the desired interface. If the returned Iterable wont be invoked concurrently, then this can be called to reuse the Iterator instance by simply passing false for newInstanceOnCall. If true 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. If false is provided then the returned Iterator will be reset each time.
        Type Parameters:
        T - The type of object to iterate over
        Parameters:
        array - Array to be iterated over
        newInstanceOnCall - true to create new instances on each invocation of Iterable.iterator()
        Returns:
        An Iterable that will go over the array
      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<T>
      • next

        public T next()
        Specified by:
        next in interface java.util.Iterator<T>
      • reset

        public void reset()
        Reset the iterator back to position 0.