xref: /aosp_15_r20/external/cldr/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateBcp47Tests.java (revision 912701f9769bb47905792267661f0baf2b85bed5)
1 package org.unicode.cldr.tool;
2 
3 import com.ibm.icu.impl.Relation;
4 import com.ibm.icu.impl.Row;
5 import com.ibm.icu.impl.Row.R2;
6 import java.util.LinkedHashSet;
7 import java.util.Map;
8 import java.util.Map.Entry;
9 import java.util.Set;
10 import org.unicode.cldr.util.SupplementalDataInfo;
11 
12 public class GenerateBcp47Tests {
main(String[] args)13     public static void main(String[] args) {
14         //        UnicodeSet s = new
15         // UnicodeSet("[[:di:][:whitespace:]-[:cn:][:cc:]]").complement().complement();
16         //        System.out.println(s);
17         SupplementalDataInfo info = SupplementalDataInfo.getInstance();
18         Map<R2<String, String>, String> deprecatedMap = info.getBcp47Deprecated();
19         Map<R2<String, String>, String> descriptionsMap = info.getBcp47Descriptions();
20         System.out.println("#Deprecated");
21         for (Entry<R2<String, String>, String> entry : deprecatedMap.entrySet()) {
22             if (!"true".equals(entry.getValue())) {
23                 continue;
24             }
25             R2<String, String> key = entry.getKey();
26             System.out.println("{\"" + key.get0() + "\", \"" + key.get1() + "\"},");
27         }
28         System.out.println("#Tests");
29         Relation<String, String> extension2Keys = info.getBcp47Extension2Keys();
30         Relation<String, String> keys2subtypes = info.getBcp47Keys();
31         Set<String> deprecatedSet = new LinkedHashSet<>();
32         for (Entry<String, Set<String>> extensionKeys : extension2Keys.keyValuesSet()) {
33             String extension = extensionKeys.getKey();
34             Set<String> keys = extensionKeys.getValue();
35             for (String key : keys) {
36                 final Set<String> subtypes = keys2subtypes.get(key);
37                 final R2<String, String> keyBlank = Row.of(key, "");
38                 boolean deprecatedKey = "true".equals(deprecatedMap.get(keyBlank));
39                 String keyDescription = descriptionsMap.get(keyBlank);
40                 String non_deprecated = null;
41                 String deprecated = null;
42                 if (subtypes != null) {
43                     for (String subtype : subtypes) {
44                         final R2<String, String> keySubtype = Row.of(key, subtype);
45                         boolean deprecatedSubtype =
46                                 deprecatedKey || "true".equals(deprecatedMap.get(keySubtype));
47                         String subtypeDescription = descriptionsMap.get(keySubtype);
48 
49                         if (deprecatedSubtype) {
50                             if (deprecated == null) {
51                                 deprecatedSet.add(
52                                         "{\"OK\", \"en-"
53                                                 + extension
54                                                 + "-"
55                                                 + key
56                                                 + "-"
57                                                 + subtype
58                                                 + "\"}, // deprecated "
59                                                 + keyDescription
60                                                 + "; "
61                                                 + subtypeDescription);
62                                 deprecated = subtype;
63                             }
64                         } else {
65                             if (non_deprecated == null) {
66                                 System.out.println(
67                                         "{\"OK\", \"en-"
68                                                 + extension
69                                                 + "-"
70                                                 + key
71                                                 + "-"
72                                                 + subtype
73                                                 + "\"}, // "
74                                                 + keyDescription
75                                                 + "; "
76                                                 + subtypeDescription);
77                                 non_deprecated = subtype;
78                             }
79                         }
80                     }
81                 } else {
82                     System.out.println(
83                             "{\"OK\", \"en-"
84                                     + extension
85                                     + "-"
86                                     + key
87                                     + "-"
88                                     + "SPECIAL"
89                                     + "\"}, // "
90                                     + keyDescription);
91                 }
92             }
93         }
94         for (String dep : deprecatedSet) {
95             System.out.println(dep);
96         }
97     }
98 }
99