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