com.springsource.util.common
Class IterableEnumeration<T>
java.lang.Object
com.springsource.util.common.IterableEnumeration<T>
- Type Parameters:
T
- the element type of the enumeration
- All Implemented Interfaces:
- java.lang.Iterable<T>
public class IterableEnumeration<T>
- extends java.lang.Object
- implements java.lang.Iterable<T>
An IterableEnumeration
wraps an Enumeration
in an
implementation of Iterable
thereby allowing the Enumeration
to be used in a for-each loop.
Enumeration enumeration = ...
IterableEnumeration foos = new IterableEnumeration(enumeration);
for (Foo foo : foos) {
// Do something with foo
}
Note: as Enumerations
do not support entry removal
the IterableEnumeration.EnumerationIterator
returned by iterator()
does not support the optional
remove
method: invocation of the method will result in an
UnsupportedOperationException
being thrown.
Concurrent Semantics
This class is not thread-safe.
- Since:
- Jersey
Field Summary |
private java.util.Iterator<T> |
iterator
|
Constructor Summary |
IterableEnumeration(java.util.Enumeration<T> enumeration)
Creates a new IterableEnumeration backed by the supplied Enumeration |
Method Summary |
java.util.Iterator<T> |
iterator()
Returns the Enumeration -backed Iterator . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
iterator
private final java.util.Iterator<T> iterator
IterableEnumeration
public IterableEnumeration(java.util.Enumeration<T> enumeration)
- Creates a new
IterableEnumeration
backed by the supplied Enumeration
- Parameters:
enumeration
- The Enumeration
to be made iterable.
iterator
public java.util.Iterator<T> iterator()
- Returns the
Enumeration
-backed Iterator
.
Note: as Enumerations
do not support entry removal
the returned IterableEnumeration.EnumerationIterator
does not support the optional
remove
method: invocation of the method will result in an
UnsupportedOperationException
being thrown.
- Specified by:
iterator
in interface java.lang.Iterable<T>