KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > util > collection > JoinedEnumeration


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.util.collection;
4
5 import java.util.Enumeration JavaDoc;
6 import java.util.NoSuchElementException JavaDoc;
7
8 /**
9  * Joins two enumerations.
10  */

11 public class JoinedEnumeration implements Enumeration JavaDoc {
12
13     private Enumeration JavaDoc mOne;
14     private Enumeration JavaDoc mTwo;
15
16     public JoinedEnumeration(Enumeration JavaDoc enumeration1, Enumeration JavaDoc enumeration2) {
17         mOne = enumeration1;
18         mTwo = enumeration2;
19     }
20
21     public boolean hasMoreElements() {
22         if (mOne != null) {
23             if (mOne.hasMoreElements()) {
24                 return true;
25             }
26             mOne = null;
27         }
28         return mTwo.hasMoreElements();
29     }
30
31     public Object JavaDoc nextElement() {
32         if (mOne != null)
33             try {
34                 return mOne.nextElement();
35             } catch (NoSuchElementException JavaDoc _ex) {
36                 mOne = null;
37             }
38         return mTwo.nextElement();
39     }
40
41 }
42
Popular Tags