java.lang.Object
gnu.java.util.DoubleEnumeration
- All Implemented Interfaces:
- java.util.Enumeration
- public class DoubleEnumeration
- extends java.lang.Object
- implements java.util.Enumeration
This is a helper class that combines two Enumerations.
It returns the elements of the first Enumeration until it has
no more elements and then returns the elements of the second
Enumeration.
In the default case:
doubleEnum = new DoubleEnumeration(enum1, enum2);
while (doubleEnum.hasMoreElements()) {
Object o = doubleEnum.nextElement();
do_something(o);
}
it calls hasMoreElements of the Enumerations as few times as
possible.
The references to the Enumerations are cleared as soon as they have no
more elements to help garbage collecting.
|
Field Summary |
private java.util.Enumeration |
e1
The first enumeration. |
private java.util.Enumeration |
e2
The second enumeration. |
private boolean |
hasChecked
This is true, if it is sure that hasMore indicates wether there are
more elements. |
private boolean |
hasMore
This is true as long as one of the enumerations has more
elements. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
hasMore
private boolean hasMore
- This is true as long as one of the enumerations has more
elements.
Only valid when hasChecked is true.
Set in
hasMoreElements()
hasChecked
private boolean hasChecked
- This is true, if it is sure that hasMore indicates wether there are
more elements.
Set to true in
hasMoreElements().
Set to false in getNextElement().
e1
private java.util.Enumeration e1
- The first enumeration.
e2
private java.util.Enumeration e2
- The second enumeration.
DoubleEnumeration
public DoubleEnumeration(java.util.Enumeration e1,
java.util.Enumeration e2)
- Creates a new Enumeration combining the given two enumerations.
The enumerations mustn't be accessed by other classes.
hasMoreElements
public boolean hasMoreElements()
- Returns true, if at least one of the two enumerations has more
elements.
- Specified by:
hasMoreElements in interface java.util.Enumeration
nextElement
public java.lang.Object nextElement()
- Returns the next element. This returns the next element of the
first enumeration, if it has more elements, otherwise the next
element of the second enumeration. If both enumeration don't have
any elements it throws a
NoSuchElementException.
- Specified by:
nextElement in interface java.util.Enumeration