Class EnumerationIterator<E>

java.lang.Object
org.apache.commons.collections4.iterators.EnumerationIterator<E>
Type Parameters:
E - the type of elements returned by this iterator.
All Implemented Interfaces:
Iterator<E>

public class EnumerationIterator<E> extends Object implements Iterator<E>
Adapter to make Enumeration instances appear to be Iterator instances.
Since:
1.0
  • Constructor Details Link icon

    • EnumerationIterator Link icon

      Constructs a new EnumerationIterator that will not function until setEnumeration(Enumeration) is called.
    • EnumerationIterator Link icon

      public EnumerationIterator(Enumeration<? extends E> enumeration)
      Constructs a new EnumerationIterator that provides an iterator view of the given enumeration.
      Parameters:
      enumeration - the enumeration to use
    • EnumerationIterator Link icon

      public EnumerationIterator(Enumeration<? extends E> enumeration, Collection<? super E> collection)
      Constructs a new EnumerationIterator that will remove elements from the specified collection.
      Parameters:
      enumeration - the enumeration to use
      collection - the collection to remove elements from
  • Method Details Link icon

    • getEnumeration Link icon

      public Enumeration<? extends E> getEnumeration()
      Returns the underlying enumeration.
      Returns:
      the underlying enumeration
    • hasNext Link icon

      public boolean hasNext()
      Returns true if the underlying enumeration has more elements.
      Specified by:
      hasNext in interface Iterator<E>
      Returns:
      true if the underlying enumeration has more elements
      Throws:
      NullPointerException - if the underlying enumeration is null
    • next Link icon

      public E next()
      Returns the next object from the enumeration.
      Specified by:
      next in interface Iterator<E>
      Returns:
      the next object from the enumeration
      Throws:
      NullPointerException - if the enumeration is null
    • remove Link icon

      public void remove()
      Removes the last retrieved element if a collection is attached.

      Functions if an associated Collection is known. If so, the first occurrence of the last returned object from this iterator will be removed from the collection.

      Specified by:
      remove in interface Iterator<E>
      Throws:
      IllegalStateException - next() not called.
      UnsupportedOperationException - if no associated collection
    • setEnumeration Link icon

      public void setEnumeration(Enumeration<? extends E> enumeration)
      Sets the underlying enumeration.
      Parameters:
      enumeration - the new underlying enumeration