KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > util > ResourceBundleEnumeration


1 /*
2  * @(#)ResourceBundleEnumeration.java 1.5 04/05/05
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.util;
9
10 /**
11  * Implements an Enumeration that combines elements from a Set and
12  * an Enumeration. Used by ListResourceBundle and PropertyResourceBundle.
13  */

14 class ResourceBundleEnumeration implements Enumeration JavaDoc<String JavaDoc> {
15
16     Set JavaDoc<String JavaDoc> set;
17     Iterator JavaDoc<String JavaDoc> iterator;
18     Enumeration JavaDoc<String JavaDoc> enumeration; // may remain null
19

20     /**
21      * Constructs a resource bundle enumeration.
22      * @param set an set providing some elements of the enumeration
23      * @param enumeration an enumeration providing more elements of the enumeration.
24      * enumeration may be null.
25      */

26     ResourceBundleEnumeration(Set JavaDoc<String JavaDoc> set, Enumeration JavaDoc<String JavaDoc> enumeration) {
27         this.set = set;
28         this.iterator = set.iterator();
29         this.enumeration = enumeration;
30     }
31
32     String JavaDoc next = null;
33             
34     public boolean hasMoreElements() {
35         if (next == null) {
36             if (iterator.hasNext()) {
37                 next = iterator.next();
38             } else if (enumeration != null) {
39                 while (next == null && enumeration.hasMoreElements()) {
40                     next = enumeration.nextElement();
41                     if (set.contains(next)) {
42                         next = null;
43                     }
44                 }
45             }
46         }
47         return next != null;
48     }
49
50     public String JavaDoc nextElement() {
51         if (hasMoreElements()) {
52             String JavaDoc result = next;
53             next = null;
54             return result;
55         } else {
56             throw new NoSuchElementException JavaDoc();
57         }
58     }
59 }
60
Popular Tags