< prev index next >

make/jdk/src/classes/build/tools/cldrconverter/Bundle.java

Print this page




  33 import java.util.List;
  34 import java.util.Map;
  35 import java.util.Objects;
  36 
  37 class Bundle {
  38     static enum Type {
  39         LOCALENAMES, CURRENCYNAMES, TIMEZONENAMES, CALENDARDATA, FORMATDATA;
  40 
  41         static EnumSet<Type> ALL_TYPES = EnumSet.of(LOCALENAMES,
  42                                                     CURRENCYNAMES,
  43                                                     TIMEZONENAMES,
  44                                                     CALENDARDATA,
  45                                                     FORMATDATA);
  46     }
  47 
  48     private final static Map<String, Bundle> bundles = new HashMap<>();
  49 
  50     private final static String[] NUMBER_PATTERN_KEYS = {
  51         "NumberPatterns/decimal",
  52         "NumberPatterns/currency",
  53         "NumberPatterns/percent",
  54         "NumberPatterns/accounting"
  55     };
  56 
  57     private final static String[] COMPACT_NUMBER_PATTERN_KEYS = {
  58             "short.CompactNumberPatterns",
  59             "long.CompactNumberPatterns"};
  60 
  61     private final static String[] NUMBER_ELEMENT_KEYS = {
  62         "NumberElements/decimal",
  63         "NumberElements/group",
  64         "NumberElements/list",
  65         "NumberElements/percent",
  66         "NumberElements/zero",
  67         "NumberElements/pattern",
  68         "NumberElements/minus",
  69         "NumberElements/exponential",
  70         "NumberElements/permille",
  71         "NumberElements/infinity",
  72         "NumberElements/nan"
  73     };
  74 


 206         }
 207         // Duplicate myMap as parentsMap for "root" so that the
 208         // fallback works. This is a hack, though.
 209         if ("root".equals(cldrBundles[0])) {
 210             assert parentsMap.isEmpty();
 211             parentsMap.putAll(myMap);
 212         }
 213 
 214         // merge individual strings into arrays
 215 
 216         // if myMap has any of the NumberPatterns members
 217         for (String k : NUMBER_PATTERN_KEYS) {
 218             if (myMap.containsKey(k)) {
 219                 String[] numberPatterns = new String[NUMBER_PATTERN_KEYS.length];
 220                 for (int i = 0; i < NUMBER_PATTERN_KEYS.length; i++) {
 221                     String key = NUMBER_PATTERN_KEYS[i];
 222                     String value = (String) myMap.remove(key);
 223                     if (value == null) {
 224                         value = (String) parentsMap.remove(key);
 225                     }
 226                     if (value == null || value.isEmpty()) {
 227                         if (!key.endsWith("accounting")) {
 228                             // print warning unless it is for "accounting",
 229                             // which may be missing.
 230                             CLDRConverter.warning("empty pattern for " + key);
 231                         }
 232                     }
 233                     numberPatterns[i] = value;
 234                 }
 235                 myMap.put("NumberPatterns", numberPatterns);
 236                 break;
 237             }
 238         }
 239 
 240         for (String k : COMPACT_NUMBER_PATTERN_KEYS) {
 241             List<String> patterns = (List<String>) myMap.remove(k);
 242             if (patterns != null) {
 243                 // Replace any null entry with empty strings.
 244                 String[] arrPatterns = patterns.stream()
 245                         .map(s -> s == null ? "" : s).toArray(String[]::new);
 246                 myMap.put(k, arrPatterns);
 247             }
 248         }
 249 
 250         // if myMap has any of NUMBER_ELEMENT_KEYS, create a complete NumberElements.
 251         String defaultScript = (String) myMap.get("DefaultNumberingSystem");




  33 import java.util.List;
  34 import java.util.Map;
  35 import java.util.Objects;
  36 
  37 class Bundle {
  38     static enum Type {
  39         LOCALENAMES, CURRENCYNAMES, TIMEZONENAMES, CALENDARDATA, FORMATDATA;
  40 
  41         static EnumSet<Type> ALL_TYPES = EnumSet.of(LOCALENAMES,
  42                                                     CURRENCYNAMES,
  43                                                     TIMEZONENAMES,
  44                                                     CALENDARDATA,
  45                                                     FORMATDATA);
  46     }
  47 
  48     private final static Map<String, Bundle> bundles = new HashMap<>();
  49 
  50     private final static String[] NUMBER_PATTERN_KEYS = {
  51         "NumberPatterns/decimal",
  52         "NumberPatterns/currency",
  53         "NumberPatterns/percent"

  54     };
  55 
  56     private final static String[] COMPACT_NUMBER_PATTERN_KEYS = {
  57             "short.CompactNumberPatterns",
  58             "long.CompactNumberPatterns"};
  59 
  60     private final static String[] NUMBER_ELEMENT_KEYS = {
  61         "NumberElements/decimal",
  62         "NumberElements/group",
  63         "NumberElements/list",
  64         "NumberElements/percent",
  65         "NumberElements/zero",
  66         "NumberElements/pattern",
  67         "NumberElements/minus",
  68         "NumberElements/exponential",
  69         "NumberElements/permille",
  70         "NumberElements/infinity",
  71         "NumberElements/nan"
  72     };
  73 


 205         }
 206         // Duplicate myMap as parentsMap for "root" so that the
 207         // fallback works. This is a hack, though.
 208         if ("root".equals(cldrBundles[0])) {
 209             assert parentsMap.isEmpty();
 210             parentsMap.putAll(myMap);
 211         }
 212 
 213         // merge individual strings into arrays
 214 
 215         // if myMap has any of the NumberPatterns members
 216         for (String k : NUMBER_PATTERN_KEYS) {
 217             if (myMap.containsKey(k)) {
 218                 String[] numberPatterns = new String[NUMBER_PATTERN_KEYS.length];
 219                 for (int i = 0; i < NUMBER_PATTERN_KEYS.length; i++) {
 220                     String key = NUMBER_PATTERN_KEYS[i];
 221                     String value = (String) myMap.remove(key);
 222                     if (value == null) {
 223                         value = (String) parentsMap.remove(key);
 224                     }
 225                     if (value.length() == 0) {
 226                         CLDRConverter.warning("empty pattern for " + key);




 227                     }
 228                     numberPatterns[i] = value;
 229                 }
 230                 myMap.put("NumberPatterns", numberPatterns);
 231                 break;
 232             }
 233         }
 234 
 235         for (String k : COMPACT_NUMBER_PATTERN_KEYS) {
 236             List<String> patterns = (List<String>) myMap.remove(k);
 237             if (patterns != null) {
 238                 // Replace any null entry with empty strings.
 239                 String[] arrPatterns = patterns.stream()
 240                         .map(s -> s == null ? "" : s).toArray(String[]::new);
 241                 myMap.put(k, arrPatterns);
 242             }
 243         }
 244 
 245         // if myMap has any of NUMBER_ELEMENT_KEYS, create a complete NumberElements.
 246         String defaultScript = (String) myMap.get("DefaultNumberingSystem");


< prev index next >