< prev index next >

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

Print this page

        

@@ -31,10 +31,11 @@
 import java.util.Arrays;
 import java.util.Formatter;
 import java.util.HashSet;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Locale;
 import java.util.Objects;
 import java.util.Set;
 import java.util.SortedSet;

@@ -104,11 +105,11 @@
                 encoding = "us-ascii";
             }
         } else {
             encoding = "iso-8859-1";
         }
-
+        boolean containsList = false;
         Formatter fmt = null;
         if (type == BundleType.TIMEZONE) {
             fmt = new Formatter();
             Set<String> metaKeys = new HashSet<>();
             for (String key : map.keySet()) {

@@ -164,10 +165,18 @@
                                 fmt.format("        final String[] %s = new String[] {\n", metaVal);
                                 for (String s : (String[])val) {
                                     fmt.format("               \"%s\",\n", CLDRConverter.saveConvert(s, useJava));
                                 }
                                 fmt.format("            };\n");
+                            } else if (val instanceof List) {
+                                containsList = true;
+                                List<String> values = (List) val;
+                                fmt.format("        final List<String> %s = List.of (\n", metaVal);
+                                for (int index = 0; index < values.size() - 1; index++) {
+                                    fmt.format("               \"%s\",\n", CLDRConverter.saveConvert(values.get(index), useJava));
+                                }
+                                fmt.format("               \"%s\");\n", CLDRConverter.saveConvert(values.get(values.size() - 1), useJava));
                             } else {
                                 fmt.format("        final String %s = \"%s\";\n", metaVal, CLDRConverter.saveConvert((String)val, useJava));
                             }
                         }
 

@@ -193,10 +202,16 @@
             out.println(CopyrightHeaders.getOpenJDKCopyright());
             out.println(CopyrightHeaders.getUnicodeCopyright());
 
             if (useJava) {
                 out.println("package sun." + packageName + ";\n");
+                // only in the FormatData resource bundles which contains
+                // list in map
+                if (baseName.equals("FormatData") && (containsList
+                        || map.values().stream().anyMatch(v -> v instanceof List))) {
+                    out.printf("import java.util.List;\n\n");
+                }
                 out.printf("import %s;\n\n", type.getPathName());
                 out.printf("public class %s%s extends %s {\n", baseName, "root".equals(localeID) ? "" : "_" + localeID, type.getClassName());
 
                 out.println("    @Override\n" +
                             "    protected final Object[][] getContents() {");

@@ -224,10 +239,18 @@
                         out.println("            { \"" + key + "\",\n                new String[] {");
                         for (String s : values) {
                             out.println("                    \"" + CLDRConverter.saveConvert(s, useJava) + "\",");
                         }
                         out.println("                }\n            },");
+                    } else if (value instanceof List) {
+                        List<String> values = (List) value;
+                        out.println("            { \"" + key + "\",\n                List.of(");
+                        for (int index = 0; index < values.size() - 1; index++) {
+                            out.println("                    \"" + CLDRConverter.saveConvert(values.get(index), useJava) + "\",");
+                        }
+                        out.println("                    \"" + CLDRConverter.saveConvert(values.get(values.size() - 1), useJava) + "\"");
+                        out.println("                )\n            },");
                     } else {
                         throw new RuntimeException("unknown value type: " + value.getClass().getName());
                     }
                 } else {
                     out.println(key + "=" + CLDRConverter.saveConvert((String) map.get(key), useJava));
< prev index next >