Class EnumerationIterator
- java.lang.Object
-
- org.apache.commons.collections.iterators.EnumerationIterator
-
- All Implemented Interfaces:
Iterator
public class EnumerationIterator extends Object implements Iterator
Adapter to makeEnumeration
instances appear to beIterator
instances.- Since:
- Commons Collections 1.0
- Version:
- $Revision: 646777 $ $Date: 2008-04-10 14:33:15 +0200 (Thu, 10 Apr 2008) $
- Author:
- James Strachan, Daniel Rall
-
-
Constructor Summary
Constructors Constructor Description EnumerationIterator()
Constructs a newEnumerationIterator
that will not function untilsetEnumeration(Enumeration)
is called.EnumerationIterator(Enumeration enumeration)
Constructs a newEnumerationIterator
that provides an iterator view of the given enumeration.EnumerationIterator(Enumeration enumeration, Collection collection)
Constructs a newEnumerationIterator
that will remove elements from the specified collection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Enumeration
getEnumeration()
Returns the underlying enumeration.boolean
hasNext()
Returns true if the underlying enumeration has more elements.Object
next()
Returns the next object from the enumeration.void
remove()
Removes the last retrieved element if a collection is attached.void
setEnumeration(Enumeration enumeration)
Sets the underlying enumeration.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining
-
-
-
-
Constructor Detail
-
EnumerationIterator
public EnumerationIterator()
Constructs a newEnumerationIterator
that will not function untilsetEnumeration(Enumeration)
is called.
-
EnumerationIterator
public EnumerationIterator(Enumeration enumeration)
Constructs a newEnumerationIterator
that provides an iterator view of the given enumeration.- Parameters:
enumeration
- the enumeration to use
-
EnumerationIterator
public EnumerationIterator(Enumeration enumeration, Collection collection)
Constructs a newEnumerationIterator
that will remove elements from the specified collection.- Parameters:
enumeration
- the enumeration to usecollection
- 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 interfaceIterator
- Returns:
- true if the underlying enumeration has more elements
- Throws:
NullPointerException
- if the underlying enumeration is null
-
next
public Object next()
Returns the next object from the enumeration.- Specified by:
next
in interfaceIterator
- 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 interfaceIterator
- Throws:
IllegalStateException
-next()
not called.UnsupportedOperationException
- if no associated collection
-
getEnumeration
public Enumeration getEnumeration()
Returns the underlying enumeration.- Returns:
- the underlying enumeration
-
setEnumeration
public void setEnumeration(Enumeration enumeration)
Sets the underlying enumeration.- Parameters:
enumeration
- the new underlying enumeration
-
-