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