Path: blob/master/src/java.base/share/classes/sun/util/ResourceBundleEnumeration.java
41152 views
/*1* Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.util;2627import java.util.Enumeration;28import java.util.Iterator;29import java.util.NoSuchElementException;30import java.util.Set;3132/**33* Implements an Enumeration that combines elements from a Set and34* an Enumeration. Used by ListResourceBundle and PropertyResourceBundle.35*/36public class ResourceBundleEnumeration implements Enumeration<String> {3738Set<String> set;39Iterator<String> iterator;40Enumeration<String> enumeration; // may remain null4142/**43* Constructs a resource bundle enumeration.44* @param set an set providing some elements of the enumeration45* @param enumeration an enumeration providing more elements of the enumeration.46* enumeration may be null.47*/48public ResourceBundleEnumeration(Set<String> set, Enumeration<String> enumeration) {49this.set = set;50this.iterator = set.iterator();51this.enumeration = enumeration;52}5354String next = null;5556public boolean hasMoreElements() {57if (next == null) {58if (iterator.hasNext()) {59next = iterator.next();60} else if (enumeration != null) {61while (next == null && enumeration.hasMoreElements()) {62next = enumeration.nextElement();63if (set.contains(next)) {64next = null;65}66}67}68}69return next != null;70}7172public String nextElement() {73if (hasMoreElements()) {74String result = next;75next = null;76return result;77} else {78throw new NoSuchElementException();79}80}81}828384