org.apache.commons.collections.iterators
Class EnumerationIterator<E>

java.lang.Object
  extended by org.apache.commons.collections.iterators.EnumerationIterator<E>
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:
Commons Collections 1.0
Version:
$Revision: 1.1.1.1 $ $Date: 2005/05/23 04:34:52 $
Author:
James Strachan, Matt Hall, John Watkinson, Daniel Rall

Constructor Summary
EnumerationIterator()
          Constructs a new EnumerationIterator that will not function until setEnumeration(Enumeration) is called.
EnumerationIterator(Enumeration<E> enumeration)
          Constructs a new EnumerationIterator that provides an iterator view of the given enumeration.
EnumerationIterator(Enumeration<E> enumeration, Collection<E> collection)
          Constructs a new EnumerationIterator that will remove elements from the specified collection.
 
Method Summary
 Enumeration<E> getEnumeration()
          Returns the underlying enumeration.
 boolean hasNext()
          Returns true if the underlying enumeration has more elements.
 E next()
          Returns the next object from the enumeration.
 void remove()
          Removes the last retrieved element if a collection is attached.
 void setEnumeration(Enumeration<E> enumeration)
          Sets the underlying enumeration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnumerationIterator

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


EnumerationIterator

public EnumerationIterator(Enumeration<E> enumeration)
Constructs a new EnumerationIterator that provides an iterator view of the given enumeration.

Parameters:
enumeration - the enumeration to use

EnumerationIterator

public EnumerationIterator(Enumeration<E> enumeration,
                           Collection<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 form
Method Detail

hasNext

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

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

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

getEnumeration

public Enumeration<E> getEnumeration()
Returns the underlying enumeration.

Returns:
the underlying enumeration

setEnumeration

public void setEnumeration(Enumeration<E> enumeration)
Sets the underlying enumeration.

Parameters:
enumeration - the new underlying enumeration


Copyright © 2005-2005 Apache Software Foundation, Matt Hall, John Watkinson. All Rights Reserved.