FileDocCategorySizeDatePackage
Enumerator.javaAPI DocApache Tomcat 6.0.144751Fri Jul 20 04:20:36 BST 2007org.apache.catalina.util

Enumerator

public final class Enumerator extends Object implements Enumeration
Adapter class that wraps an Enumeration around a Java2 collection classes object Iterator so that existing APIs returning Enumerations can easily run on top of the new collections. Constructors are provided to easliy create such wrappers.
author
Craig R. McClanahan
version
$Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $

Fields Summary
private Iterator
iterator
The Iterator over which the Enumeration represented by this class actually operates.
Constructors Summary
public Enumerator(Collection collection)
Return an Enumeration over the values of the specified Collection.

param
collection Collection whose values should be enumerated


        this(collection.iterator());

    
public Enumerator(Collection collection, boolean clone)
Return an Enumeration over the values of the specified Collection.

param
collection Collection whose values should be enumerated
param
clone true to clone iterator


        this(collection.iterator(), clone);

    
public Enumerator(Iterator iterator)
Return an Enumeration over the values returned by the specified Iterator.

param
iterator Iterator to be wrapped


        super();
        this.iterator = iterator;

    
public Enumerator(Iterator iterator, boolean clone)
Return an Enumeration over the values returned by the specified Iterator.

param
iterator Iterator to be wrapped
param
clone true to clone iterator


        super();
        if (!clone) {
            this.iterator = iterator;
        } else {
            List list = new ArrayList();
            while (iterator.hasNext()) {
                list.add(iterator.next());
            }
            this.iterator = list.iterator();   
        }

    
public Enumerator(Map map)
Return an Enumeration over the values of the specified Map.

param
map Map whose values should be enumerated


        this(map.values().iterator());

    
public Enumerator(Map map, boolean clone)
Return an Enumeration over the values of the specified Map.

param
map Map whose values should be enumerated
param
clone true to clone iterator


        this(map.values().iterator(), clone);

    
Methods Summary
public booleanhasMoreElements()
Tests if this enumeration contains more elements.

return
true if and only if this enumeration object contains at least one more element to provide, false otherwise



    // --------------------------------------------------------- Public Methods


                                     
       

        return (iterator.hasNext());

    
public java.lang.ObjectnextElement()
Returns the next element of this enumeration if this enumeration has at least one more element to provide.

return
the next element of this enumeration
exception
NoSuchElementException if no more elements exist


        return (iterator.next());