0N/A/*
3261N/A * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
0N/A * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
0N/A *
0N/A * The original version of this source code and documentation
0N/A * is copyrighted and owned by Taligent, Inc., a wholly-owned
0N/A * subsidiary of IBM. These materials are provided under terms
0N/A * of a License Agreement between Taligent and Sun. This technology
0N/A * is protected by multiple US and International patents.
0N/A *
0N/A * This notice and attribution to Taligent may not be removed.
0N/A * Taligent is a registered trademark of Taligent, Inc.
0N/A *
0N/A */
0N/A
0N/Apackage java.util;
0N/A
0N/Aimport sun.util.ResourceBundleEnumeration;
0N/A
0N/A/**
0N/A * <code>ListResourceBundle</code> is an abstract subclass of
0N/A * <code>ResourceBundle</code> that manages resources for a locale
0N/A * in a convenient and easy to use list. See <code>ResourceBundle</code> for
0N/A * more information about resource bundles in general.
0N/A *
0N/A * <P>
0N/A * Subclasses must override <code>getContents</code> and provide an array,
0N/A * where each item in the array is a pair of objects.
0N/A * The first element of each pair is the key, which must be a
0N/A * <code>String</code>, and the second element is the value associated with
0N/A * that key.
0N/A *
0N/A * <p>
0N/A * The following <a name="sample">example</a> shows two members of a resource
0N/A * bundle family with the base name "MyResources".
0N/A * "MyResources" is the default member of the bundle family, and
0N/A * "MyResources_fr" is the French member.
0N/A * These members are based on <code>ListResourceBundle</code>
0N/A * (a related <a href="PropertyResourceBundle.html#sample">example</a> shows
0N/A * how you can add a bundle to this family that's based on a properties file).
0N/A * The keys in this example are of the form "s1" etc. The actual
0N/A * keys are entirely up to your choice, so long as they are the same as
0N/A * the keys you use in your program to retrieve the objects from the bundle.
0N/A * Keys are case-sensitive.
0N/A * <blockquote>
0N/A * <pre>
0N/A *
0N/A * public class MyResources extends ListResourceBundle {
0N/A * protected Object[][] getContents() {
3191N/A * return new Object[][] {
0N/A * // LOCALIZE THIS
0N/A * {"s1", "The disk \"{1}\" contains {0}."}, // MessageFormat pattern
0N/A * {"s2", "1"}, // location of {0} in pattern
0N/A * {"s3", "My Disk"}, // sample disk name
0N/A * {"s4", "no files"}, // first ChoiceFormat choice
0N/A * {"s5", "one file"}, // second ChoiceFormat choice
0N/A * {"s6", "{0,number} files"}, // third ChoiceFormat choice
0N/A * {"s7", "3 Mar 96"}, // sample date
0N/A * {"s8", new Dimension(1,5)} // real object, not just string
0N/A * // END OF MATERIAL TO LOCALIZE
0N/A * };
0N/A * }
0N/A * }
0N/A *
0N/A * public class MyResources_fr extends ListResourceBundle {
0N/A * protected Object[][] getContents() {
0N/A * return new Object[][] = {
0N/A * // LOCALIZE THIS
0N/A * {"s1", "Le disque \"{1}\" {0}."}, // MessageFormat pattern
0N/A * {"s2", "1"}, // location of {0} in pattern
0N/A * {"s3", "Mon disque"}, // sample disk name
0N/A * {"s4", "ne contient pas de fichiers"}, // first ChoiceFormat choice
0N/A * {"s5", "contient un fichier"}, // second ChoiceFormat choice
0N/A * {"s6", "contient {0,number} fichiers"}, // third ChoiceFormat choice
0N/A * {"s7", "3 mars 1996"}, // sample date
0N/A * {"s8", new Dimension(1,3)} // real object, not just string
0N/A * // END OF MATERIAL TO LOCALIZE
0N/A * };
0N/A * }
0N/A * }
0N/A * </pre>
0N/A * </blockquote>
0N/A * @see ResourceBundle
0N/A * @see PropertyResourceBundle
0N/A * @since JDK1.1
0N/A */
0N/Apublic abstract class ListResourceBundle extends ResourceBundle {
0N/A /**
0N/A * Sole constructor. (For invocation by subclass constructors, typically
0N/A * implicit.)
0N/A */
0N/A public ListResourceBundle() {
0N/A }
0N/A
0N/A // Implements java.util.ResourceBundle.handleGetObject; inherits javadoc specification.
0N/A public final Object handleGetObject(String key) {
0N/A // lazily load the lookup hashtable.
0N/A if (lookup == null) {
0N/A loadLookup();
0N/A }
0N/A if (key == null) {
0N/A throw new NullPointerException();
0N/A }
0N/A return lookup.get(key); // this class ignores locales
0N/A }
0N/A
0N/A /**
0N/A * Returns an <code>Enumeration</code> of the keys contained in
0N/A * this <code>ResourceBundle</code> and its parent bundles.
0N/A *
0N/A * @return an <code>Enumeration</code> of the keys contained in
0N/A * this <code>ResourceBundle</code> and its parent bundles.
0N/A * @see #keySet()
0N/A */
0N/A public Enumeration<String> getKeys() {
0N/A // lazily load the lookup hashtable.
0N/A if (lookup == null) {
0N/A loadLookup();
0N/A }
0N/A
0N/A ResourceBundle parent = this.parent;
0N/A return new ResourceBundleEnumeration(lookup.keySet(),
0N/A (parent != null) ? parent.getKeys() : null);
0N/A }
0N/A
0N/A /**
0N/A * Returns a <code>Set</code> of the keys contained
0N/A * <em>only</em> in this <code>ResourceBundle</code>.
0N/A *
0N/A * @return a <code>Set</code> of the keys contained only in this
0N/A * <code>ResourceBundle</code>
0N/A * @since 1.6
0N/A * @see #keySet()
0N/A */
0N/A protected Set<String> handleKeySet() {
0N/A if (lookup == null) {
0N/A loadLookup();
0N/A }
0N/A return lookup.keySet();
0N/A }
0N/A
0N/A /**
0N/A * Returns an array in which each item is a pair of objects in an
0N/A * <code>Object</code> array. The first element of each pair is
0N/A * the key, which must be a <code>String</code>, and the second
0N/A * element is the value associated with that key. See the class
0N/A * description for details.
0N/A *
0N/A * @return an array of an <code>Object</code> array representing a
0N/A * key-value pair.
0N/A */
0N/A abstract protected Object[][] getContents();
0N/A
0N/A // ==================privates====================
0N/A
0N/A /**
0N/A * We lazily load the lookup hashtable. This function does the
0N/A * loading.
0N/A */
0N/A private synchronized void loadLookup() {
0N/A if (lookup != null)
0N/A return;
0N/A
0N/A Object[][] contents = getContents();
3323N/A HashMap<String,Object> temp = new HashMap<>(contents.length);
0N/A for (int i = 0; i < contents.length; ++i) {
0N/A // key must be non-null String, value must be non-null
0N/A String key = (String) contents[i][0];
0N/A Object value = contents[i][1];
0N/A if (key == null || value == null) {
0N/A throw new NullPointerException();
0N/A }
0N/A temp.put(key, value);
0N/A }
0N/A lookup = temp;
0N/A }
0N/A
0N/A private Map<String,Object> lookup = null;
0N/A}