Documentation of 'org.clapper.util.misc.ArrayIterator' Java class
ArrayIterator
org.clapper.util.misc

Class ArrayIterator<T>

  • All Implemented Interfaces:
    java.util.Iterator<T>


    public class ArrayIterator<T>
    extends java.lang.Object
    implements java.util.Iterator<T>
    The ArrayIterator class provides a bridge between an array of objects and an Iterator. It's useful in cases where you have an array, but you need an Iterator; using an instance of ArrayIterator saves copying the array's contents into a Collection, just to get an Iterator.
    See Also:
    Iterator
    • Constructor Summary

      Constructors 
      Constructor and Description
      ArrayIterator(T[] array)
      Allocate a new ArrayIterator object that will iterate over the specified array of objects.
      ArrayIterator(T[] array, int index)
      Allocate a new ArrayIterator object that will iterate over the specified array of objects, starting at a particular index.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      int getNextIndex()
      Get the index of the next element to be retrieved.
      boolean hasNext()
      Determine whether the underlying Iterator has more elements.
      T next()
      Get the next element from the underlying array.
      T previous()
      Get the previous element from the underlying array.
      void remove()
      Required by the Iterator interface, but not supported by this class.
      • Methods inherited from class java.lang.Object

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

        forEachRemaining
    • Constructor Detail

      • ArrayIterator

        public ArrayIterator(T[] array)
        Allocate a new ArrayIterator object that will iterate over the specified array of objects.
        Parameters:
        array - The array over which to iterate
      • ArrayIterator

        public ArrayIterator(T[] array,
                             int index)
        Allocate a new ArrayIterator object that will iterate over the specified array of objects, starting at a particular index. The index isn't checked for validity until next() is called.
        Parameters:
        array - The array over which to iterate
        index - The index at which to start
    • Method Detail

      • getNextIndex

        public int getNextIndex()
        Get the index of the next element to be retrieved. This index value might be past the end of the array.
        Returns:
        the index
      • hasNext

        public boolean hasNext()
        Determine whether the underlying Iterator has more elements.
        Specified by:
        hasNext in interface java.util.Iterator<T>
        Returns:
        true if and only if a call to next() will return an element, false otherwise.
        See Also:
        next()
      • next

        public T next()
               throws java.util.NoSuchElementException
        Get the next element from the underlying array.
        Specified by:
        next in interface java.util.Iterator<T>
        Returns:
        the next element from the underlying array
        Throws:
        java.util.NoSuchElementException - No more elements exist
        See Also:
        previous(), Iterator.next()
      • previous

        public T previous()
                   throws java.util.NoSuchElementException
        Get the previous element from the underlying array. This method decrements the iterator's internal index by one, and returns the corresponding element.
        Returns:
        the previous element from the underlying array
        Throws:
        java.util.NoSuchElementException - Attempt to move internal index before the first array element
        See Also:
        next()
      • remove

        public void remove()
        Required by the Iterator interface, but not supported by this class.
        Specified by:
        remove in interface java.util.Iterator<T>
        Throws:
        java.lang.UnsupportedOperationException - unconditionally

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.