Class SimpleEnumerator<E>

java.lang.Object
com.tangosol.util.Base
com.tangosol.util.SimpleEnumerator<E>
All Implemented Interfaces:
Enumeration<E>, Iterator<E>
Direct Known Subclasses:
SortedEnumerator

public class SimpleEnumerator<E> extends Base implements Enumeration<E>, Iterator<E>
Provide a generic implementation of an array enumerator.
Version:
0.50, 09/05/97, 1.00, 08/07/98
Author:
Cameron Purdy
  • Field Details

    • m_aoItem

      protected E[] m_aoItem
      Array of items to enumerate.
    • m_iItem

      protected int m_iItem
      Iterator position: next item to return.
    • m_ofLimit

      protected int m_ofLimit
      Iterator end position (beyond last).
    • m_fForward

      protected boolean m_fForward
      Iterator direction.
  • Constructor Details

    • SimpleEnumerator

      public SimpleEnumerator(E[] aoItem)
      Construct the simple enumerator based on an array of objects.
      Parameters:
      aoItem - array of objects to enumerate
    • SimpleEnumerator

      public SimpleEnumerator(E[] aoItem, int ofStart, int cItems)
      Construct the simple enumerator based on an array of objects.
      Parameters:
      aoItem - array of objects to enumerate
      ofStart - the first object position
      cItems - the number of objects to enumerate
    • SimpleEnumerator

      public SimpleEnumerator(E[] aoItem, int ofStart, int cItems, boolean fForward, boolean fCopy)
      Construct the simple enumerator based on an array of objects, making a copy of the array if specified.
      Parameters:
      aoItem - array of objects to enumerate
      ofStart - the first object position
      cItems - the number of objects to enumerate
      fForward - true to iterate forwards, false to iterate from the end backwards to the beginning
      fCopy - pass true to make a copy of the array or false if the array's contents will not change
    • SimpleEnumerator

      public SimpleEnumerator(Enumeration<E> enmr)
      Construct a simple enumerator based on another Enumeration. This forces an initial pass through the elements of the passed enumerator, making a copy of that data, thus capturing a "point in time" view of an Enumeration which may be backed by mutable data. In other words, this constructs a "safe enumerator" based on a "not-safe enumerator".
      Parameters:
      enmr - the java.util.Enumeration to enumerate
    • SimpleEnumerator

      public SimpleEnumerator(Iterator<E> iter)
      Construct a simple enumerator based on another Iterator. This forces an initial pass through the elements of the passed enumerator, making a copy of that data, thus capturing a "point in time" view of an Iterator which may be backed by mutable data. In other words, this constructs a "safe enumerator" based on a "not-safe enumerator".
      Parameters:
      iter - the java.util.Iterator to enumerate
    • SimpleEnumerator

      public SimpleEnumerator(Collection<E> col)
      Construct a simple enumerator based on a collection.
      Parameters:
      col - the java.util.Collection to enumerate
  • Method Details

    • hasMoreElements

      public boolean hasMoreElements()
      Tests if this enumeration contains more elements.
      Specified by:
      hasMoreElements in interface Enumeration<E>
      Returns:
      true if the enumeration contains more elements, false otherwise
    • nextElement

      public E nextElement()
      Returns the next element of this enumeration.
      Specified by:
      nextElement in interface Enumeration<E>
      Returns:
      the next element in the enumeration
    • hasNext

      public boolean hasNext()
      Tests if this Iterator contains more elements.
      Specified by:
      hasNext in interface Iterator<E>
      Returns:
      true if the Iterator contains more elements, false otherwise
    • next

      public E next()
      Returns the next element of this Iterator.
      Specified by:
      next in interface Iterator<E>
      Returns:
      the next element in the Iterator
    • remove

      public void remove()
      Remove the last-returned element that was returned by the Iterator. This method always throws UnsupportedOperationException because the Iterator is immutable.
      Specified by:
      remove in interface Iterator<E>
    • toArray

      public static <T> T[] toArray(Enumeration<T> enmr)
      Turns an enumeration into an array.
      Parameters:
      enmr - the enumerator
      Returns:
      an array of the objects from the enumerator
    • toArray

      public static <T> T[] toArray(Enumeration<T> enmr, T[] ao)
      Turns an enumeration into an array. The behavior of this method differs from the simple toArray(Enumeration) method in the same way that the Collection.toArray(Object[]) method differs from the Collection.toArray() method.
      Parameters:
      enmr - the enumerator
      ao - the array into which the elements of the Enumeration are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose
      Returns:
      an array of the objects from the enumerator
    • toArray

      public static <T> T[] toArray(Iterator<T> iter)
      Turns an Iterator into an array.
      Parameters:
      iter - the Iterator
      Returns:
      an array of the objects
    • toArray

      public static <T> T[] toArray(Iterator<T> iter, T[] ao)
      Turns an Iterator into an array. The behavior of this method differs from the simple toArray(Iterator) method in the same way that the Collection.toArray(Object[]) method differs from the Collection.toArray() method.
      Parameters:
      iter - the Iterator
      ao - the array into which the elements of the Iterator are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose
      Returns:
      an array of the objects from the Iterator
    • toArray

      public Object[] toArray()
      Return the remaining contents of this SimpleEnumerator as an array.
      Returns:
      an array containing all of the elements in this enumerator
    • toArray

      public <T> T[] toArray(T[] ao)
      Return the remaining contents of this SimpleEnumerator as an array of the type specified by the passed array, and use that passed array to store the values if it is big enough, putting a null in the first unused element if the size of the passed array is bigger than the number of remaining elements in this enumerator, as per the contract of the Collection.toArray(Object[]) method.
      Parameters:
      ao - the array into which the elements of the Enumeration are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose
      Returns:
      an array containing the elements of the collection
      Throws:
      ArrayStoreException - if the runtime type of the specified array is not a supertype of the runtime type of every element in this collection