org.clapper.util.misc
Class EnumerationIterator<T>

java.lang.Object
  extended by org.clapper.util.misc.EnumerationIterator<T>
All Implemented Interfaces:
java.lang.Iterable<T>, java.util.Iterator<T>

public class EnumerationIterator<T>
extends java.lang.Object
implements java.util.Iterator<T>, java.lang.Iterable<T>

The EnumerationIterator class is an adapter that makes a java.util.Enumeration object look and behave like a java.util.Iterator objects. The EnumerationIterator class implements the Iterator interface and wraps an existing Enumeration object. This class is the conceptual opposite of the Collections.enumeration() method in the java.util package.

You can also use an instance of this class to wrap an Enumeration for use in a JDK 1.5-style for each loop. For instance:

 Vector v = ...
 for (String s : new EnumerationIterator (v.elements()))
     ...
 

Version:
$Revision: 6735 $
Author:
Copyright © 2004-2007 Brian M. Clapper
See Also:
Iterator, Enumeration

Constructor Summary
EnumerationIterator(java.util.Enumeration<T> enumeration)
          Allocate a new EnumerationIterator object that will forward its calls to the specified Enumeration.
 
Method Summary
 boolean hasNext()
          Determine whether the underlying Enumeration has more elements.
 java.util.Iterator<T> iterator()
          Returns this iterator.
 T next()
          Get the next element from the underlying Enumeration.
 void remove()
          Removes from the underlying collection the last element returned by the iterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnumerationIterator

public EnumerationIterator(java.util.Enumeration<T> enumeration)
Allocate a new EnumerationIterator object that will forward its calls to the specified Enumeration.

Parameters:
enumeration - The Enumeration to which to forward calls
Method Detail

hasNext

public boolean hasNext()
Determine whether the underlying Enumeration has more elements.

Specified by:
hasNext in interface java.util.Iterator<T>
Returns:
true if and only if a call to next() will return an element, false otherwise.
See Also:
next(), Enumeration.hasMoreElements()

iterator

public java.util.Iterator<T> iterator()
Returns this iterator. Necessary for the Iterable interface.

Specified by:
iterator in interface java.lang.Iterable<T>
Returns:
this object

next

public T next()
       throws java.util.NoSuchElementException
Get the next element from the underlying Enumeration.

Specified by:
next in interface java.util.Iterator<T>
Returns:
the next element from the underlying Enumeration
Throws:
java.util.NoSuchElementException - No more elements exist
See Also:
Iterator.next()

remove

public void remove()
            throws java.lang.IllegalStateException,
                   java.lang.UnsupportedOperationException
Removes from the underlying collection the last element returned by the iterator. Not supported by this class.

Specified by:
remove in interface java.util.Iterator<T>
Throws:
java.lang.IllegalStateException - doesn't
java.lang.UnsupportedOperationException - unconditionally


Copyright © 2004-2007 Brian M. Clapper. All Rights Reserved.