1 package org.unicode.cldr.unittest; 2 3 import java.util.Collection; 4 import java.util.Collections; 5 import java.util.HashMap; 6 import java.util.LinkedHashSet; 7 import java.util.Map.Entry; 8 import java.util.Set; 9 10 import org.unicode.cldr.util.CLDRConfig; 11 import org.unicode.cldr.util.CLDRFile; 12 import org.unicode.cldr.util.Factory; 13 import org.unicode.cldr.util.PathStarrer; 14 import org.unicode.cldr.util.XPathParts; 15 16 import com.google.common.collect.Multimap; 17 import com.google.common.collect.TreeMultimap; 18 import com.ibm.icu.dev.test.TestFmwk; 19 import com.ibm.icu.dev.util.CollectionUtilities; 20 import com.ibm.icu.impl.Row; 21 import com.ibm.icu.impl.Row.R4; 22 23 public class TestAlt extends TestFmwk { 24 private static final Set<String> SINGLETON_ALT = Collections.singleton("alt"); 25 static CLDRConfig testInfo = CLDRConfig.getInstance(); 26 main(String[] args)27 public static void main(String[] args) { 28 new TestAlt().run(args); 29 } 30 testValues()31 public void testValues() { 32 Factory cldrFactory = testInfo.getCldrFactory(); 33 HashMap<String, String> altPaths = new HashMap<>(); 34 Multimap<String, R4<String, String, String, String>> altStarred = TreeMultimap.create(); 35 PathStarrer pathStarrer = new PathStarrer().setSubstitutionPattern("*"); 36 final Set<String> available = new LinkedHashSet<>(); 37 available.add("root"); 38 available.add("en"); 39 for (String locale : cldrFactory.getAvailable()) { 40 if (locale.startsWith("en_")) { 41 available.add(locale); 42 } 43 } 44 available.addAll(cldrFactory.getAvailable()); 45 46 for (String locale : available) { 47 CLDRFile cldrFile = cldrFactory.make(locale, false); 48 for (String xpath : cldrFile) { 49 if (altPaths.containsKey(xpath)) { 50 continue; 51 } 52 if (!xpath.contains("alt")) { 53 continue; 54 } 55 XPathParts parts = XPathParts.getFrozenInstance(xpath); 56 for (int i = 0; i < parts.size(); ++i) { 57 String altValue = parts.getAttributeValue(i, "alt"); 58 if (altValue != null) { 59 altPaths.put(xpath, locale); 60 logln(locale + "\t" + xpath); 61 String starredPath = pathStarrer.set(parts.cloneAsThawed(), SINGLETON_ALT); 62 String attrs = pathStarrer.getAttributesString("|"); 63 final XPathParts noAlt = parts.cloneAsThawed().removeAttribute(i, "alt"); 64 String plainPath = noAlt.toString(); 65 altStarred.put(starredPath, Row.of(locale, cldrFile.getStringValue(plainPath), cldrFile.getStringValue(xpath), attrs)); 66 } 67 } 68 } 69 } 70 for (Entry<String, Collection<R4<String, String, String, String>>> entry : altStarred.asMap().entrySet()) { 71 System.out.println(entry.getKey() + "\t" + CollectionUtilities.join(entry.getValue(), "\t")); 72 } 73 } 74 } 75