01: /*
02: * @(#)ResourceBundleEnumeration.java 1.6 06/10/10
03: *
04: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package java.util;
28:
29: /**
30: * Implements an Enumeration that combines elements from a Set and
31: * an Enumeration. Used by ListResourceBundle and PropertyResourceBundle.
32: */
33: class ResourceBundleEnumeration implements Enumeration {
34:
35: Set set;
36: Iterator iterator;
37: Enumeration enumeration; // may remain null
38:
39: /**
40: * Constructs a resource bundle enumeration.
41: * @param set an set providing some elements of the enumeration
42: * @param enumeration an enumeration providing more elements of the enumeration.
43: * enumeration may be null.
44: */
45: ResourceBundleEnumeration(Set set, Enumeration enumeration) {
46: this .set = set;
47: this .iterator = set.iterator();
48: this .enumeration = enumeration;
49: }
50:
51: Object next = null;
52:
53: public boolean hasMoreElements() {
54: if (next == null) {
55: if (iterator.hasNext()) {
56: next = iterator.next();
57: } else if (enumeration != null) {
58: while (next == null && enumeration.hasMoreElements()) {
59: next = enumeration.nextElement();
60: if (set.contains(next)) {
61: next = null;
62: }
63: }
64: }
65: }
66: return next != null;
67: }
68:
69: public Object nextElement() {
70: if (hasMoreElements()) {
71: Object result = next;
72: next = null;
73: return result;
74: } else {
75: throw new NoSuchElementException();
76: }
77: }
78: }
|