Path: blob/master/src/java.base/share/classes/sun/util/resources/TimeZoneNamesBundle.java
41159 views
/*1* Copyright (c) 2005, 2018, 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*/2425/*26* (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved27* (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved28*29* The original version of this source code and documentation30* is copyrighted and owned by Taligent, Inc., a wholly-owned31* subsidiary of IBM. These materials are provided under terms32* of a License Agreement between Taligent and Sun. This technology33* is protected by multiple US and International patents.34*35* This notice and attribution to Taligent may not be removed.36* Taligent is a registered trademark of Taligent, Inc.37*38*/3940package sun.util.resources;4142import java.util.Map;43import java.util.LinkedHashMap;44import java.util.LinkedHashSet;45import java.util.MissingResourceException;46import java.util.Objects;47import java.util.Set;4849/**50* Subclass of <code>ResourceBundle</code> with special51* functionality for time zone names. The additional functionality:52* <ul>53* <li>Preserves the order of entries in the <code>getContents</code>54* array for the enumeration returned by <code>getKeys</code>.55* <li>Inserts the time zone ID (the key of the bundle entries) into56* the string arrays returned by <code>handleGetObject</code>.57* </ul>58* All <code>TimeZoneNames</code> resource bundles must extend this59* class and implement the <code>getContents</code> method.60*/61public abstract class TimeZoneNamesBundle extends OpenListResourceBundle {6263/**64* Maps time zone IDs to locale-specific names.65* The value returned is an array of five strings:66* <ul>67* <li>The time zone ID (same as the key, not localized).68* <li>The long name of the time zone in standard time (localized).69* <li>The short name of the time zone in standard time (localized).70* <li>The long name of the time zone in daylight savings time (localized).71* <li>The short name of the time zone in daylight savings time (localized).72* <li>The long name of the time zone in generic form (localized).73* <li>The short name of the time zone in generic form (localized).74* </ul>75* The localized names come from the subclasses's76* <code>getContents</code> implementations, while the time zone77* ID is inserted into the returned array by this method.78*/79@Override80public Object handleGetObject(String key) {81Object val = super.handleGetObject(key);82if (val instanceof String[]) {83String[] contents = (String[]) val;84int clen = contents.length;85String[] tmpobj = new String[7];86tmpobj[0] = key;87System.arraycopy(contents, 0, tmpobj, 1, clen);88return tmpobj;89}90return val;91}9293/**94* Use LinkedHashMap to preserve the order of bundle entries.95*/96@Override97protected <K, V> Map<K, V> createMap(int size) {98return new LinkedHashMap<>(size);99}100101/**102* Use LinkedHashSet to preserve the key order.103* @param <E> the type of elements104* @return a Set105*/106@Override107protected <E> Set<E> createSet() {108return new LinkedHashSet<>();109}110111/**112* Provides key/value mappings for a specific113* resource bundle. Each entry of the array114* returned must be an array with two elements:115* <ul>116* <li>The key, which must be a string.117* <li>The value, which must be an array of118* four strings:119* <ul>120* <li>The long name of the time zone in standard time.121* <li>The short name of the time zone in standard time.122* <li>The long name of the time zone in daylight savings time.123* <li>The short name of the time zone in daylight savings time.124* </ul>125* </ul>126*/127protected abstract Object[][] getContents();128}129130131