jdk/src/share/classes/sun/util/resources/TimeZoneNamesBundle.java
changeset 14765 0987999ed367
parent 11130 c7093e306a34
child 14926 1cb5d2255451
equal deleted inserted replaced
14764:6dd2370b4cd3 14765:0987999ed367
    40 
    40 
    41 package sun.util.resources;
    41 package sun.util.resources;
    42 
    42 
    43 import java.util.Map;
    43 import java.util.Map;
    44 import java.util.LinkedHashMap;
    44 import java.util.LinkedHashMap;
       
    45 import java.util.LinkedHashSet;
       
    46 import java.util.MissingResourceException;
       
    47 import java.util.Set;
    45 
    48 
    46 /**
    49 /**
    47  * Subclass of <code>ResourceBundle</code> with special
    50  * Subclass of <code>ResourceBundle</code> with special
    48  * functionality for time zone names. The additional functionality:
    51  * functionality for time zone names. The additional functionality:
    49  * <ul>
    52  * <ul>
    56  * class and implement the <code>getContents</code> method.
    59  * class and implement the <code>getContents</code> method.
    57  */
    60  */
    58 public abstract class TimeZoneNamesBundle extends OpenListResourceBundle {
    61 public abstract class TimeZoneNamesBundle extends OpenListResourceBundle {
    59 
    62 
    60     /**
    63     /**
       
    64      * Returns a String array containing time zone names. The String array has
       
    65      * at most size elements.
       
    66      *
       
    67      * @param key  the time zone ID for which names are obtained
       
    68      * @param size the requested size of array for names
       
    69      * @return a String array containing names
       
    70      */
       
    71     public String[] getStringArray(String key, int size) {
       
    72         String[] names = handleGetObject(key, size);
       
    73         if ((names == null || names.length != size) && parent != null) {
       
    74             names = ((TimeZoneNamesBundle)parent).getStringArray(key, size);
       
    75         }
       
    76         if (names == null) {
       
    77             throw new MissingResourceException("no time zone names", getClass().getName(), key);
       
    78         }
       
    79         return names;
       
    80 
       
    81     }
       
    82 
       
    83     /**
    61      * Maps time zone IDs to locale-specific names.
    84      * Maps time zone IDs to locale-specific names.
    62      * The value returned is an array of five strings:
    85      * The value returned is an array of five strings:
    63      * <ul>
    86      * <ul>
    64      * <li>The time zone ID (same as the key, not localized).
    87      * <li>The time zone ID (same as the key, not localized).
    65      * <li>The long name of the time zone in standard time (localized).
    88      * <li>The long name of the time zone in standard time (localized).
    69      * </ul>
    92      * </ul>
    70      * The localized names come from the subclasses's
    93      * The localized names come from the subclasses's
    71      * <code>getContents</code> implementations, while the time zone
    94      * <code>getContents</code> implementations, while the time zone
    72      * ID is inserted into the returned array by this method.
    95      * ID is inserted into the returned array by this method.
    73      */
    96      */
       
    97     @Override
    74     public Object handleGetObject(String key) {
    98     public Object handleGetObject(String key) {
       
    99         return handleGetObject(key, 5);
       
   100     }
       
   101 
       
   102     private String[] handleGetObject(String key, int n) {
    75         String[] contents = (String[]) super.handleGetObject(key);
   103         String[] contents = (String[]) super.handleGetObject(key);
    76         if (contents == null) {
   104         if (contents == null) {
    77             return null;
   105             return null;
    78         }
   106         }
    79 
   107         int clen = Math.min(n, contents.length);
    80         int clen = contents.length;
       
    81         String[] tmpobj = new String[clen+1];
   108         String[] tmpobj = new String[clen+1];
    82         tmpobj[0] = key;
   109         tmpobj[0] = key;
    83         System.arraycopy(contents, 0, tmpobj, 1, clen);
   110         System.arraycopy(contents, 0, tmpobj, 1, clen);
    84         return tmpobj;
   111         return tmpobj;
    85     }
   112     }
    86 
   113 
    87     /**
   114     /**
    88      * Use LinkedHashMap to preserve order of bundle entries.
   115      * Use LinkedHashMap to preserve the order of bundle entries.
    89      */
   116      */
    90     @Override
   117     @Override
    91     protected Map<String, Object> createMap(int size) {
   118     protected <K, V> Map<K, V> createMap(int size) {
    92         return new LinkedHashMap<>(size);
   119         return new LinkedHashMap<>(size);
       
   120     }
       
   121 
       
   122     /**
       
   123      * Use LinkedHashSet to preserve the key order.
       
   124      * @param <E> the type of elements
       
   125      * @return a Set
       
   126      */
       
   127     @Override
       
   128     protected <E> Set<E> createSet() {
       
   129         return new LinkedHashSet<>();
    93     }
   130     }
    94 
   131 
    95     /**
   132     /**
    96      * Provides key/value mappings for a specific
   133      * Provides key/value mappings for a specific
    97      * resource bundle. Each entry of the array
   134      * resource bundle. Each entry of the array