1 package org.unicode.cldr.tool;
2 
3 import java.util.Arrays;
4 import java.util.Collections;
5 import java.util.EnumSet;
6 import java.util.Map.Entry;
7 import java.util.Set;
8 import java.util.TreeMap;
9 import java.util.TreeSet;
10 
11 import org.unicode.cldr.util.CLDRConfig;
12 import org.unicode.cldr.util.CLDRFile;
13 import org.unicode.cldr.util.CLDRPaths;
14 import org.unicode.cldr.util.ChainedMap;
15 import org.unicode.cldr.util.ChainedMap.M3;
16 import org.unicode.cldr.util.ChainedMap.M4;
17 import org.unicode.cldr.util.CldrUtility;
18 import org.unicode.cldr.util.Factory;
19 import org.unicode.cldr.util.Level;
20 import org.unicode.cldr.util.Organization;
21 import org.unicode.cldr.util.StandardCodes;
22 import org.unicode.cldr.util.XPathParts;
23 
24 import com.google.common.base.Objects;
25 
26 public class FindAttributeValueDifferences {
27     private static final String LAST_ARCHIVE_DIRECTORY = CLDRPaths.ARCHIVE_DIRECTORY;
28 
getActuals( CLDRFile english, M4<String, String, String, Boolean> result)29     static public M4<String, String, String, Boolean> getActuals(
30         CLDRFile english,
31         M4<String, String, String, Boolean> result) {
32 
33         for (String path : english.fullIterable()) {
34             XPathParts parts = XPathParts.getFrozenInstance(path);
35             for (int i = 0; i < parts.size(); ++i) {
36                 String element = parts.getElement(i);
37                 for (Entry<String, String> av : parts.getAttributes(i).entrySet()) {
38                     result.put(element, av.getKey(), av.getValue(), Boolean.TRUE);
39                 }
40             }
41         }
42         return result;
43     }
44 
main(String[] args)45     public static void main(String[] args) {
46 
47         CLDRConfig config = CLDRConfig.getInstance();
48         Factory current = config.getCldrFactory();
49         Factory last = Factory.make(LAST_ARCHIVE_DIRECTORY + "cldr-" + ToolConstants.LAST_RELEASE_VERSION + "/common/main/", ".*");
50 
51         @SuppressWarnings({ "rawtypes", "unchecked" })
52         M4<String, String, String, Boolean> newValues = ChainedMap.of(new TreeMap(), new TreeMap(), new TreeMap(), Boolean.class);
53         @SuppressWarnings({ "rawtypes", "unchecked" })
54         M4<String, String, String, Boolean> oldValues = ChainedMap.of(new TreeMap(), new TreeMap(), new TreeMap(), Boolean.class);
55 
56         @SuppressWarnings({ "rawtypes", "unchecked" })
57         M3<String, String, Boolean> emptyM3 = ChainedMap.of(new TreeMap(), new TreeMap(), Boolean.class);
58 
59         Set<String> modernCldr = StandardCodes.make().getLocaleCoverageLocales(Organization.cldr, EnumSet.of(Level.MODERN));
60 
61         for (String locale : Arrays.asList("de")) {
62             getActuals(current.make(locale, false), newValues);
63             getActuals(last.make(locale, false), oldValues);
64         }
65 
66         Set<String> elements = new TreeSet<>(newValues.keySet());
67         elements.addAll(oldValues.keySet());
68 
69         for (String element : elements) {
70             M3<String, String, Boolean> newSubmap = CldrUtility.ifNull(newValues.get(element), emptyM3);
71             M3<String, String, Boolean> oldSubmap = CldrUtility.ifNull(oldValues.get(element), emptyM3);
72             Set<String> attributes = new TreeSet<>(newSubmap.keySet());
73             attributes.addAll(oldSubmap.keySet());
74 
75             for (String attribute : attributes) {
76                 @SuppressWarnings({ "unchecked" })
77                 Set<String> newAttValues = CldrUtility.ifNull(newSubmap.get(attribute), Collections.EMPTY_MAP).keySet();
78                 @SuppressWarnings({ "unchecked" })
79                 Set<String> oldAttValues = CldrUtility.ifNull(oldSubmap.get(attribute), Collections.EMPTY_MAP).keySet();
80                 if (Objects.equal(newAttValues, oldAttValues)) {
81                     continue;
82                 }
83                 showDiff(element, attribute, newAttValues, oldAttValues, "new");
84                 showDiff(element, attribute, oldAttValues, newAttValues, "old");
85             }
86         }
87     }
88 
showDiff(String element, String attribute, Set<String> newAttValues, Set<String> oldAttValues, String title)89     private static TreeSet<String> showDiff(String element, String attribute, Set<String> newAttValues, Set<String> oldAttValues, String title) {
90         TreeSet<String> currentAttributeValues = new TreeSet<>(newAttValues);
91         currentAttributeValues.removeAll(oldAttValues);
92         for (String attributeValue : currentAttributeValues) {
93             System.out.println(title + "\t" + element + "\t" + attribute + "\t" + attributeValue);
94         }
95         return currentAttributeValues;
96     }
97 }
98