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[] NUMBER_ELEMENT_KEYS = { 57 "NumberElements/decimal", 58 "NumberElements/group", 59 "NumberElements/list", 60 "NumberElements/percent", 61 "NumberElements/zero", 62 "NumberElements/pattern", 63 "NumberElements/minus", 64 "NumberElements/exponential", 65 "NumberElements/permille", 66 "NumberElements/infinity", 67 "NumberElements/nan" 68 }; 69 70 private final static String[] TIME_PATTERN_KEYS = { 71 "DateTimePatterns/full-time", 72 "DateTimePatterns/long-time", 73 "DateTimePatterns/medium-time", 74 "DateTimePatterns/short-time", 75 }; 208 209 // merge individual strings into arrays 210 211 // if myMap has any of the NumberPatterns members 212 for (String k : NUMBER_PATTERN_KEYS) { 213 if (myMap.containsKey(k)) { 214 String[] numberPatterns = new String[NUMBER_PATTERN_KEYS.length]; 215 for (int i = 0; i < NUMBER_PATTERN_KEYS.length; i++) { 216 String key = NUMBER_PATTERN_KEYS[i]; 217 String value = (String) myMap.remove(key); 218 if (value == null) { 219 value = (String) parentsMap.remove(key); 220 } 221 if (value.length() == 0) { 222 CLDRConverter.warning("empty pattern for " + key); 223 } 224 numberPatterns[i] = value; 225 } 226 myMap.put("NumberPatterns", numberPatterns); 227 break; 228 } 229 } 230 231 // if myMap has any of NUMBER_ELEMENT_KEYS, create a complete NumberElements. 232 String defaultScript = (String) myMap.get("DefaultNumberingSystem"); 233 @SuppressWarnings("unchecked") 234 List<String> scripts = (List<String>) myMap.get("numberingScripts"); 235 if (defaultScript == null && scripts != null) { 236 // Some locale data has no default script for numbering even with mutiple scripts. 237 // Take the first one as default in that case. 238 defaultScript = scripts.get(0); 239 myMap.put("DefaultNumberingSystem", defaultScript); 240 } 241 if (scripts != null) { 242 for (String script : scripts) { 243 for (String k : NUMBER_ELEMENT_KEYS) { 244 String[] numberElements = new String[NUMBER_ELEMENT_KEYS.length]; 245 for (int i = 0; i < NUMBER_ELEMENT_KEYS.length; i++) { 246 String key = script + "." + NUMBER_ELEMENT_KEYS[i]; 247 String value = (String) myMap.remove(key); | 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 74 private final static String[] TIME_PATTERN_KEYS = { 75 "DateTimePatterns/full-time", 76 "DateTimePatterns/long-time", 77 "DateTimePatterns/medium-time", 78 "DateTimePatterns/short-time", 79 }; 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"); 247 @SuppressWarnings("unchecked") 248 List<String> scripts = (List<String>) myMap.get("numberingScripts"); 249 if (defaultScript == null && scripts != null) { 250 // Some locale data has no default script for numbering even with mutiple scripts. 251 // Take the first one as default in that case. 252 defaultScript = scripts.get(0); 253 myMap.put("DefaultNumberingSystem", defaultScript); 254 } 255 if (scripts != null) { 256 for (String script : scripts) { 257 for (String k : NUMBER_ELEMENT_KEYS) { 258 String[] numberElements = new String[NUMBER_ELEMENT_KEYS.length]; 259 for (int i = 0; i < NUMBER_ELEMENT_KEYS.length; i++) { 260 String key = script + "." + NUMBER_ELEMENT_KEYS[i]; 261 String value = (String) myMap.remove(key); |