Class ArrayIterator

  • All Implemented Interfaces:
    java.util.Iterator<java.lang.Object>

    public class ArrayIterator
    extends java.lang.Object
    implements java.util.Iterator<java.lang.Object>

    An Iterator wrapper for an Object[]. This will allow us to deal with all array like structures in a consistent manner.

    WARNING : this class's operations are NOT synchronized. It is meant to be used in a single thread, newly created for each use in the #foreach() directive. If this is used or shared, synchronize in the next() method.

    Since:
    1.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Object array
      The objects to iterate over.
      private int pos
      The current position and size in the array.
      private int size
      The size of the array.
    • Constructor Summary

      Constructors 
      Constructor Description
      ArrayIterator​(java.lang.Object arr)
      Creates a new iterator instance for the specified array.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean hasNext()
      Check to see if there is another element in the array.
      java.lang.Object next()
      Move to next element in the array.
      • 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, remove
    • Field Detail

      • array

        private final java.lang.Object array
        The objects to iterate over.
      • size

        private final int size
        The size of the array.
      • pos

        private int pos
        The current position and size in the array.
    • Constructor Detail

      • ArrayIterator

        public ArrayIterator​(java.lang.Object arr)
        Creates a new iterator instance for the specified array.
        Parameters:
        arr - The array for which an iterator is desired.
    • Method Detail

      • hasNext

        public boolean hasNext()
        Check to see if there is another element in the array.
        Specified by:
        hasNext in interface java.util.Iterator<java.lang.Object>
        Returns:
        Whether there is another element.
      • next

        public java.lang.Object next()
        Move to next element in the array.
        Specified by:
        next in interface java.util.Iterator<java.lang.Object>
        Returns:
        The next object in the array.