ArrayIterator
org.clapper.util.misc

Class ArrayIterator<T>

  • All Implemented Interfaces:
    Iterator<T>


    public class ArrayIterator<T>extends Objectimplements 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

      Methods 
      Modifier and TypeMethod and Description
      intgetNextIndex()
      Get the index of the next element to be retrieved.
      booleanhasNext()
      Determine whether the underlying Iterator has more elements.
      Tnext()
      Get the next element from the underlying array.
      Tprevious()
      Get the previous element from the underlying array.
      voidremove()
      Required by the Iterator interface, but not supported by this class.
    • 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 Iterator<T>
        Returns:
        true if and only if a call to next() will return an element, false otherwise.
        See Also:
        next()
      • previous

        public T previous()           throws 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:
        NoSuchElementException - Attempt to move internal index before the first array element
        See Also:
        next()

SCaVis 2.1 © jWork.ORG