16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package build.tools.cldrconverter; 27 28 import java.util.ArrayList; 29 import java.util.Arrays; 30 import java.util.EnumSet; 31 import java.util.HashMap; 32 import java.util.Iterator; 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[] 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); | 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package build.tools.cldrconverter; 27 28 import java.util.ArrayList; 29 import java.util.Arrays; 30 import java.util.EnumSet; 31 import java.util.HashMap; 32 import java.util.Iterator; 33 import java.util.List; 34 import java.util.Map; 35 import java.util.Objects; 36 import java.util.stream.Collectors; 37 38 class Bundle { 39 static enum Type { 40 LOCALENAMES, CURRENCYNAMES, TIMEZONENAMES, CALENDARDATA, FORMATDATA; 41 42 static EnumSet<Type> ALL_TYPES = EnumSet.of(LOCALENAMES, 43 CURRENCYNAMES, 44 TIMEZONENAMES, 45 CALENDARDATA, 46 FORMATDATA); 47 } 48 49 private final static Map<String, Bundle> bundles = new HashMap<>(); 50 51 private final static String[] NUMBER_PATTERN_KEYS = { 52 "NumberPatterns/decimal", 53 "NumberPatterns/currency", 54 "NumberPatterns/percent" 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 75 private final static String[] TIME_PATTERN_KEYS = { 76 "DateTimePatterns/full-time", 77 "DateTimePatterns/long-time", 78 "DateTimePatterns/medium-time", 79 "DateTimePatterns/short-time", 80 }; 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.length() == 0) { 227 CLDRConverter.warning("empty pattern for " + key); 228 } 229 numberPatterns[i] = value; 230 } 231 myMap.put("NumberPatterns", numberPatterns); 232 break; 233 } 234 } 235 236 for (String k : COMPACT_NUMBER_PATTERN_KEYS) { 237 List<String> patterns = (List<String>) myMap.remove(k); 238 if (patterns != null) { 239 // Replace any null entry with empty strings. 240 patterns = patterns.stream() 241 .map(s -> s == null ? "" : s).collect(Collectors.toList()); 242 myMap.put(k, patterns); 243 } 244 } 245 246 // if myMap has any of NUMBER_ELEMENT_KEYS, create a complete NumberElements. 247 String defaultScript = (String) myMap.get("DefaultNumberingSystem"); 248 @SuppressWarnings("unchecked") 249 List<String> scripts = (List<String>) myMap.get("numberingScripts"); 250 if (defaultScript == null && scripts != null) { 251 // Some locale data has no default script for numbering even with mutiple scripts. 252 // Take the first one as default in that case. 253 defaultScript = scripts.get(0); 254 myMap.put("DefaultNumberingSystem", defaultScript); 255 } 256 if (scripts != null) { 257 for (String script : scripts) { 258 for (String k : NUMBER_ELEMENT_KEYS) { 259 String[] numberElements = new String[NUMBER_ELEMENT_KEYS.length]; 260 for (int i = 0; i < NUMBER_ELEMENT_KEYS.length; i++) { 261 String key = script + "." + NUMBER_ELEMENT_KEYS[i]; 262 String value = (String) myMap.remove(key); |