jdk/src/java.base/share/classes/sun/util/resources/OpenListResourceBundle.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 25859 3317bb8137f4
child 34774 03b4e6dc367b
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents: 14765
diff changeset
     2
 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * The original version of this source code and documentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * is copyrighted and owned by Taligent, Inc., a wholly-owned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * subsidiary of IBM. These materials are provided under terms
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * of a License Agreement between Taligent and Sun. This technology
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * is protected by multiple US and International patents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * This notice and attribution to Taligent may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Taligent is a registered trademark of Taligent, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
package sun.util.resources;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.util.HashMap;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
    45
import java.util.HashSet;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.util.ResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import sun.util.ResourceBundleEnumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * Subclass of <code>ResourceBundle</code> which mimics
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <code>ListResourceBundle</code>, but provides more hooks
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * for specialized subclass behavior. For general description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * see {@link java.util.ListResourceBundle}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * This class leaves handleGetObject non-final, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * adds a method createMap which allows subclasses to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * use specialized Map implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
public abstract class OpenListResourceBundle extends ResourceBundle {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Sole constructor.  (For invocation by subclass constructors, typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * implicit.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    protected OpenListResourceBundle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    // Implements java.util.ResourceBundle.handleGetObject; inherits javadoc specification.
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14342
diff changeset
    70
    @Override
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents: 14765
diff changeset
    71
    protected Object handleGetObject(String key) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        if (key == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        loadLookupTablesIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        return lookup.get(key); // this class ignores locales
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Implementation of ResourceBundle.getKeys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14342
diff changeset
    83
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public Enumeration<String> getKeys() {
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents: 14765
diff changeset
    85
        ResourceBundle parentBundle = this.parent;
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents: 14765
diff changeset
    86
        return new ResourceBundleEnumeration(handleKeySet(),
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents: 14765
diff changeset
    87
                (parentBundle != null) ? parentBundle.getKeys() : null);
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents: 14765
diff changeset
    88
     }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14342
diff changeset
    91
     * Returns a set of keys provided in this resource bundle,
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14342
diff changeset
    92
     * including no parents.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents: 14765
diff changeset
    94
    @Override
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents: 14765
diff changeset
    95
    protected Set<String> handleKeySet() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        loadLookupTablesIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return lookup.keySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   100
    @Override
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   101
    public Set<String> keySet() {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   102
        if (keyset != null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   103
            return keyset;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   104
        }
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14342
diff changeset
   105
        Set<String> ks = createSet();
16852
60207b2b4b42 8011172: JSR 310 DateTime API Updates II
sherman
parents: 14765
diff changeset
   106
        ks.addAll(handleKeySet());
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   107
        if (parent != null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   108
            ks.addAll(parent.keySet());
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   109
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   110
        synchronized (this) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   111
            if (keyset == null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   112
                keyset = ks;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   113
            }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   114
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   115
        return keyset;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   116
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   117
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * See ListResourceBundle class description.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   121
    protected abstract Object[][] getContents();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Load lookup tables if they haven't been loaded already.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    void loadLookupTablesIfNecessary() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (lookup == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            loadLookup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * We lazily load the lookup hashtable.  This function does the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * loading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   136
    private void loadLookup() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        Object[][] contents = getContents();
11130
c7093e306a34 7117487: Warnings Cleanup: some i18n classes in java.util and sun.util
okutsu
parents: 5506
diff changeset
   138
        Map<String, Object> temp = createMap(contents.length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        for (int i = 0; i < contents.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            // key must be non-null String, value must be non-null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            String key = (String) contents[i][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            Object value = contents[i][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            if (key == null || value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            temp.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   148
        synchronized (this) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   149
            if (lookup == null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   150
                lookup = temp;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   151
            }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   152
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * Lets subclasses provide specialized Map implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Default uses HashMap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14342
diff changeset
   159
    protected <K, V> Map<K, V> createMap(int size) {
11130
c7093e306a34 7117487: Warnings Cleanup: some i18n classes in java.util and sun.util
okutsu
parents: 5506
diff changeset
   160
        return new HashMap<>(size);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14342
diff changeset
   163
    protected <E> Set<E> createSet() {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14342
diff changeset
   164
        return new HashSet<>();
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14342
diff changeset
   165
    }
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14342
diff changeset
   166
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   167
    private volatile Map<String, Object> lookup = null;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11130
diff changeset
   168
    private volatile Set<String> keyset;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
}