Class ArrayIterator<E>

  • All Implemented Interfaces:
    java.util.Enumeration<E>, java.util.Iterator<E>, java.util.ListIterator<E>, EnumerationIterator<E>

    public final class ArrayIterator<E>
    extends java.lang.Object
    implements java.util.ListIterator<E>, EnumerationIterator<E>
    A read-only iterator over an array.
    Author:
    David M. Lloyd
    • Constructor Summary

      Constructors 
      Constructor Description
      ArrayIterator​(E[] elements)
      Construct a new instance.
      ArrayIterator​(E[] elements, boolean descending)
      Construct a new instance.
      ArrayIterator​(E[] elements, boolean descending, int startIdx)
      Construct a new instance.
      ArrayIterator​(E[] elements, int startIdx)
      Construct a new instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(E e)
      Unsupported.
      boolean hasNext()
      Determine if there are more elements to iterate over in the direction of this iterator.
      boolean hasPrevious()
      Determine if there are more elements to iterate over in the reverse direction of this iterator.
      E next()
      Get the next element in the direction of this iterator.
      int nextIndex()
      Get the next index in the direction of this iterator.
      E previous()
      Get the next element in the reverse direction of this iterator.
      int previousIndex()
      Get the next index in the reverse direction of this iterator.
      void remove()
      Unsupported.
      void set​(E e)
      Unsupported.
      • 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 Detail

      • ArrayIterator

        public ArrayIterator​(E[] elements)
        Construct a new instance.
        Parameters:
        elements - the elements to iterate over
      • ArrayIterator

        public ArrayIterator​(E[] elements,
                             boolean descending)
        Construct a new instance.
        Parameters:
        elements - the elements to iterate over
        descending - true to iterate in descending order, false otherwise
      • ArrayIterator

        public ArrayIterator​(E[] elements,
                             int startIdx)
        Construct a new instance.
        Parameters:
        elements - the elements to iterate over
        startIdx - the starting index (must be within the bounds of elements)
      • ArrayIterator

        public ArrayIterator​(E[] elements,
                             boolean descending,
                             int startIdx)
        Construct a new instance.
        Parameters:
        elements - the elements to iterate over
        descending - true to iterate in descending order, false otherwise
        startIdx - the starting index (must be within the bounds of elements)
    • Method Detail

      • hasPrevious

        public boolean hasPrevious()
        Determine if there are more elements to iterate over in the reverse direction of this iterator.
        Specified by:
        hasPrevious in interface java.util.ListIterator<E>
        Returns:
        true if there are more elements, false otherwise
      • hasNext

        public boolean hasNext()
        Determine if there are more elements to iterate over in the direction of this iterator.
        Specified by:
        hasNext in interface java.util.Iterator<E>
        Specified by:
        hasNext in interface java.util.ListIterator<E>
        Returns:
        true if there are more elements, false otherwise
      • previous

        public E previous()
        Get the next element in the reverse direction of this iterator.
        Specified by:
        previous in interface java.util.ListIterator<E>
        Returns:
        the next element
      • next

        public E next()
        Get the next element in the direction of this iterator.
        Specified by:
        next in interface java.util.Iterator<E>
        Specified by:
        next in interface java.util.ListIterator<E>
        Returns:
        the next element
      • nextIndex

        public int nextIndex()
        Get the next index in the direction of this iterator.
        Specified by:
        nextIndex in interface java.util.ListIterator<E>
        Returns:
        the next index
      • previousIndex

        public int previousIndex()
        Get the next index in the reverse direction of this iterator.
        Specified by:
        previousIndex in interface java.util.ListIterator<E>
        Returns:
        the next index
      • remove

        public void remove()
        Unsupported.
        Specified by:
        remove in interface java.util.Iterator<E>
        Specified by:
        remove in interface java.util.ListIterator<E>
      • set

        public void set​(E e)
        Unsupported.
        Specified by:
        set in interface java.util.ListIterator<E>
        Parameters:
        e - ignored
      • add

        public void add​(E e)
        Unsupported.
        Specified by:
        add in interface java.util.ListIterator<E>
        Parameters:
        e - ignored