/*---------------------------------------------------------------------------*\
$Id: 7e70963f810139a9f26080e0a71ab04eefbc5b4c $
---------------------------------------------------------------------------
This software is released under a BSD-style license:
Copyright (c) 2004-2007 Brian M. Clapper. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. The end-user documentation included with the redistribution, if any,
must include the following acknowlegement:
"This product includes software developed by Brian M. Clapper
(bmc@clapper.org, http://www.clapper.org/bmc/). That software is
copyright (c) 2004-2007 Brian M. Clapper."
Alternately, this acknowlegement may appear in the software itself,
if wherever such third-party acknowlegements normally appear.
3. Neither the names "clapper.org", "clapper.org Java Utility Library",
nor any of the names of the project contributors may be used to
endorse or promote products derived from this software without prior
written permission. For written permission, please contact
bmc@clapper.org.
4. Products derived from this software may not be called "clapper.org
Java Utility Library", nor may "clapper.org" appear in their names
without prior written permission of Brian M. Clapper.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
NO EVENT SHALL BRIAN M. CLAPPER BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\*---------------------------------------------------------------------------*/
package org.clapper.util.misc;
import java.util.Iterator;
import java.util.Enumeration;
import java.util.NoSuchElementException;
/**
* 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()))
* ...
*
*
* @see java.util.Iterator
* @see java.util.Enumeration
*
* @version $Revision$
*
* @author Copyright © 2004-2007 Brian M. Clapper
*/
public class EnumerationIterator implements Iterator, Iterable
{
/*----------------------------------------------------------------------*\
Private Data Elements
\*----------------------------------------------------------------------*/
/**
* The underlying Enumeration.
*/
private Enumeration enumeration = null;
/*----------------------------------------------------------------------*\
Constructor
\*----------------------------------------------------------------------*/
/**
* Allocate a new EnumerationIterator object that will
* forward its calls to the specified Enumeration.
*
* @param enumeration The Enumeration to which to forward calls
*/
public EnumerationIterator (Enumeration enumeration)
{
this.enumeration = enumeration;
}
/*----------------------------------------------------------------------*\
Public Methods
\*----------------------------------------------------------------------*/
/**
* Determine whether the underlying Enumeration has more
* elements.
*
* @return true if and only if a call to
* next() will return an element,
* false otherwise.
*
* @see #next()
* @see Enumeration#hasMoreElements
*/
public boolean hasNext()
{
return enumeration.hasMoreElements();
}
/**
* Returns this iterator. Necessary for the Iterable interface.
*
* @return this object
*/
public Iterator iterator()
{
return this;
}
/**
* Get the next element from the underlying Enumeration.
*
* @return the next element from the underlying Enumeration
*
* @exception NoSuchElementException No more elements exist
*
* @see Iterator#next
*/
public T next() throws NoSuchElementException
{
return enumeration.nextElement();
}
/**
* Removes from the underlying collection the last element returned by
* the iterator. Not supported by this class.
*
* @throws IllegalStateException doesn't
* @throws UnsupportedOperationException unconditionally
*/
public void remove()
throws IllegalStateException,
UnsupportedOperationException
{
throw new UnsupportedOperationException();
}
}
Ads help maintain this website.