com.ccg.util
Class EnumerationIterator

java.lang.Object
  extended by com.ccg.util.EnumerationIterator
All Implemented Interfaces:
Iterator

public final class EnumerationIterator
extends Object
implements Iterator

Makes a Iterator out of a Enumeration.

This simple class provides the wrapper methods around a Enumeration object such that it can be passed as a Iterator when these conditions arise.

For example, if you are updating a old method "fooOld" which takes a enumeration as a parameter, and it would like to make use of a old method "fooOld" which requires a Iterator, you might use this class in the following manner:


 public void fooOld(Enumeration e) {
        // Convert enumeration to iterator and invoke old method
   fooNew(new EnumerationIterator(e));
 }

 public void fooNew(Iterator i) {
    ... // New API code that updates to fooOld wants to use
 }
 

Since:
1.0
Version:
$Revision: 1.1 $
Author:
$Author: pkb $

Constructor Summary
EnumerationIterator(Enumeration i)
          Constructs a Iterator object from a Enumeration.
 
Method Summary
 boolean hasNext()
          Determine if the Iterator has more elements left in it.
 Object next()
          Get the next element from the Iterator.
 void remove()
          Implementation of the 'remove' method from the Iterator interface.
 String toString()
          Get string representation of object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EnumerationIterator

public EnumerationIterator(Enumeration i)
Constructs a Iterator object from a Enumeration.

Parameters:
i - The Enumeration to make a Iterator out of - must not be null.
Since:
1.0
Method Detail

hasNext

public boolean hasNext()
Determine if the Iterator has more elements left in it.

Specified by:
hasNext in interface Iterator
Returns:
true if there are more elements left in the iterator.
Since:
1.0

next

public Object next()
Get the next element from the Iterator.

As this method retrieves the next element of the iterator, one should only use it if the hasNext method returned true.

Specified by:
next in interface Iterator
Returns:
Next object in iterator.
Since:
1.0

remove

public void remove()
Implementation of the 'remove' method from the Iterator interface.

The Iterator interface requires that all implementations provide a 'remove' method. However, the 'remove' method is not required to do anything. Since a Enumeration does not have a corresponding function, this does nothing.

Specified by:
remove in interface Iterator
Since:
1.0

toString

public String toString()
Get string representation of object.

Overrides:
toString in class Object
Returns:
String representation of object.
Since:
1.0


Copyright 1998-1998-2006 null. All Rights Reserved.