From 478e37e835f3e4d97418ffcf2813a0fa9fa9691f Mon Sep 17 00:00:00 2001 From: macchiati Date: Wed, 15 Nov 2023 13:11:34 -0800 Subject: [PATCH] CLDR-16232 reformatted --- .../org/unicode/cldr/tool/Inheritance.java | 160 +- .../unicode/cldr/tool/InheritanceStats.java | 284 ++- .../java/org/unicode/cldr/util/CLDRFile.java | 2149 ++++++++++------- .../java/org/unicode/cldr/util/XMLSource.java | 908 +++---- 4 files changed, 1977 insertions(+), 1524 deletions(-) diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/Inheritance.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/Inheritance.java index a5d07475493..077ebd7ee49 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/Inheritance.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/Inheritance.java @@ -1,5 +1,9 @@ package org.unicode.cldr.tool; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSortedMap; +import com.ibm.icu.util.Output; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -10,7 +14,6 @@ import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; - import org.unicode.cldr.util.CLDRFile; import org.unicode.cldr.util.CldrUtility; import org.unicode.cldr.util.DtdData.Attribute; @@ -20,24 +23,26 @@ import org.unicode.cldr.util.XMLSource.Alias; import org.unicode.cldr.util.XPathParts; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSortedMap; -import com.ibm.icu.util.Output; - public class Inheritance { private Inheritance.AliasMapper aliasMapper; private Factory factory; - public enum LateralAliasType {remove, removeWhenOptional, count} - public static final Map LATERAL_ATTRIBUTES = ImmutableMap.of( - "alt", LateralAliasType.remove, - "case", LateralAliasType.removeWhenOptional, - "gender", LateralAliasType.removeWhenOptional, - "count", LateralAliasType.count - ); + + public enum LateralAliasType { + remove, + removeWhenOptional, + count + } + + public static final Map LATERAL_ATTRIBUTES = + ImmutableMap.of( + "alt", LateralAliasType.remove, + "case", LateralAliasType.removeWhenOptional, + "gender", LateralAliasType.removeWhenOptional, + "count", LateralAliasType.count); /** * Is this a hard (explicit) value? (convenience method) + * * @param value * @return */ @@ -45,19 +50,19 @@ public static boolean isHardValue(String value) { return value != null && !value.equals(CldrUtility.INHERITANCE_MARKER); } - /** - * Creat an Inheritance class from a factory. - */ + /** Creat an Inheritance class from a factory. */ public Inheritance(Factory factory) { CLDRFile root = factory.make("root", false); aliasMapper = new AliasMapper(root); this.factory = factory; } - /** - * Get a String value with Bailey, as in current CLDRFile. - */ - public String getStringValueWithBailey(String locale, String path, Output pathWhereFound, Output localeWhereFound) { + /** Get a String value with Bailey, as in current CLDRFile. */ + public String getStringValueWithBailey( + String locale, + String path, + Output pathWhereFound, + Output localeWhereFound) { List verticalChain = getVerticalLocaleChain(locale); String result = searchVertical(path, pathWhereFound, localeWhereFound, verticalChain); if (result != null) { @@ -66,14 +71,16 @@ public String getStringValueWithBailey(String locale, String path, Output pathWhereFound, Output localeWhereFound) { - return getBaileyValue(path, pathWhereFound, localeWhereFound, getVerticalLocaleChain(locale)); + /** Get a Bailey value, as in current CLDRFile. */ + public String getBaileyValue( + String locale, + String path, + Output pathWhereFound, + Output localeWhereFound) { + return getBaileyValue( + path, pathWhereFound, localeWhereFound, getVerticalLocaleChain(locale)); } - private List getVerticalLocaleChain(String locale) { List result = new ArrayList<>(); while (locale != null) { @@ -83,9 +90,14 @@ private List getVerticalLocaleChain(String locale) { return ImmutableList.copyOf(result); } - private String getBaileyValue(String path, Output pathWhereFound, Output localeWhereFound, List verticalChain) { + private String getBaileyValue( + String path, + Output pathWhereFound, + Output localeWhereFound, + List verticalChain) { String result; - Set inheritanceChain = getInheritanceChain(verticalChain.get(0).getLocaleID(), path); + Set inheritanceChain = + getInheritanceChain(verticalChain.get(0).getLocaleID(), path); for (String path2 : inheritanceChain) { result = searchVertical(path2, pathWhereFound, localeWhereFound, verticalChain); if (result != null) { @@ -98,7 +110,11 @@ private String getBaileyValue(String path, Output pathWhereFound, Output return null; } - private String searchVertical(String path, Output pathWhereFound, Output localeWhereFound, List verticalChain) { + private String searchVertical( + String path, + Output pathWhereFound, + Output localeWhereFound, + List verticalChain) { for (CLDRFile file : verticalChain) { String value = file.getStringValue(path); if (isHardValue(value)) { @@ -110,9 +126,7 @@ private String searchVertical(String path, Output pathWhereFound, Output return null; } - /** - * Find out if there is vertical inheritance - */ + /** Find out if there is vertical inheritance */ public Set getInheritanceChain(String locale, String path) { Set result = new LinkedHashSet<>(); // prevent dups addVerticals(path, result); @@ -125,33 +139,41 @@ public Set getInheritanceChain(String locale, String path) { } parts = parts.cloneAsThawed(); switch (entry.getValue()) { - case removeWhenOptional: - Attribute a = InheritanceStats.dtdData.getAttribute(parts.getElement(elementNumber), attribute); - if (a.getMode() == Mode.OPTIONAL) { + case removeWhenOptional: + Attribute a = + InheritanceStats.dtdData.getAttribute( + parts.getElement(elementNumber), attribute); + if (a.getMode() == Mode.OPTIONAL) { + addPathReplacingAttribute(parts, elementNumber, attribute, null, result); + } + break; + case remove: addPathReplacingAttribute(parts, elementNumber, attribute, null, result); - } - break; - case remove: - addPathReplacingAttribute(parts, elementNumber, attribute, null, result); - break; - case count: - // TBD if count is decimal, use locale to get category - String attValue = parts.getAttributeValue(elementNumber, attribute); - if (!"other".equals(attValue)) { - addPathReplacingAttribute(parts, elementNumber, attribute, "other", result); - } - addPathReplacingAttribute(parts, elementNumber, attribute, null, result); - break; + break; + case count: + // TBD if count is decimal, use locale to get category + String attValue = parts.getAttributeValue(elementNumber, attribute); + if (!"other".equals(attValue)) { + addPathReplacingAttribute(parts, elementNumber, attribute, "other", result); + } + addPathReplacingAttribute(parts, elementNumber, attribute, null, result); + break; } int elementNumber2 = getFirstElementForAttribute(parts, attribute); if (elementNumber2 > 0) { - throw new IllegalArgumentException("Multiple instances of " + attribute + " in " + parts); + throw new IllegalArgumentException( + "Multiple instances of " + attribute + " in " + parts); } } return result; } - private void addPathReplacingAttribute(XPathParts parts, int elementNumber, String attribute, String attValue, Set result) { + private void addPathReplacingAttribute( + XPathParts parts, + int elementNumber, + String attribute, + String attValue, + Set result) { if (attValue == null) { parts.removeAttribute(elementNumber, attribute); } else { @@ -177,8 +199,8 @@ public int getFirstElementForAttribute(XPathParts parts, String key) { } /** - * Class to gather all the aliases in root into a form useful for - * processing lateral alias inheritance. + * Class to gather all the aliases in root into a form useful for processing lateral alias + * inheritance. */ public static class AliasMapper { // this map is sorted in reverse, so that longer substrings always come before shorter @@ -187,15 +209,14 @@ public static class AliasMapper { /** * Get all the prefixes + * * @return */ public Set getInheritingPathPrefixes() { return sorted.keySet(); } - /** - * Get all the inherited paths for a given path - */ + /** Get all the inherited paths for a given path */ public > T getInheritedPaths(String path, T result) { while (true) { String trial = getInheritedPath(path); @@ -211,32 +232,32 @@ public > T getInheritedPaths(String path, T result) } /** - * Given a path in a resolving CLDRFile that inherits laterally with aliases, - * return the path it inherits from. - *
If the CLDRFile is not resolving, an exception is thrown. + * Given a path in a resolving CLDRFile that inherits laterally with aliases, return the + * path it inherits from.
+ * If the CLDRFile is not resolving, an exception is thrown. + * * @param path - * @return the path that the input path inherits from laterally, - * or null if there is no such path. - *
If the file is not resolving, an exception is thrown. + * @return the path that the input path inherits from laterally, or null if there is no such + * path.
+ * If the file is not resolving, an exception is thrown. */ - public String getInheritedPath(String path) { SortedMap less = sorted.tailMap(path); String firstLess = less.firstKey(); if (!path.startsWith(firstLess)) { return null; } - String result = sorted.get(firstLess) - + path.substring(firstLess.length()); + String result = sorted.get(firstLess) + path.substring(firstLess.length()); // System.out.println(path + " ==> " + result); return result; } /** - * Given a path in a resolving CLDRFile, find all of the paths that inherit from it laterally. - * That is, the result is the set of all paths P such that getInheritedPath(P) == path - * If there are no such paths, the empty set is returned. - *
If the CLDRFile is not resolving, an exception is thrown. + * Given a path in a resolving CLDRFile, find all of the paths that inherit from it + * laterally. That is, the result is the set of all paths P such that getInheritedPath(P) == + * path If there are no such paths, the empty set is returned.
+ * If the CLDRFile is not resolving, an exception is thrown. + * * @param path * @return immutable set of laterally inheriting paths */ @@ -246,6 +267,7 @@ public Set getInheritingPaths(String path) { /** * Put together all the alias paths into the format: prefix => result. + * * @param root */ public AliasMapper(CLDRFile root) { @@ -270,4 +292,4 @@ public AliasMapper(CLDRFile root) { this.sorted = ImmutableSortedMap.copyOf(sorted); } } -} \ No newline at end of file +} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/InheritanceStats.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/InheritanceStats.java index f713fd51b04..0e2d9aa90f2 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/InheritanceStats.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/InheritanceStats.java @@ -1,5 +1,14 @@ package org.unicode.cldr.tool; +import com.google.common.base.Joiner; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSortedSet; +import com.google.common.collect.Lists; +import com.google.common.collect.Multimap; +import com.google.common.collect.TreeMultimap; +import com.ibm.icu.util.Output; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -10,7 +19,6 @@ import java.util.Objects; import java.util.Set; import java.util.TreeSet; - import org.unicode.cldr.test.SubmissionLocales; import org.unicode.cldr.util.CLDRConfig; import org.unicode.cldr.util.CLDRFile; @@ -29,16 +37,6 @@ import org.unicode.cldr.util.SupplementalDataInfo; import org.unicode.cldr.util.XPathParts; -import com.google.common.base.Joiner; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSortedSet; -import com.google.common.collect.Lists; -import com.google.common.collect.Multimap; -import com.google.common.collect.TreeMultimap; -import com.ibm.icu.util.Output; - public class InheritanceStats { private static final CLDRConfig CLDR_CONFIG = CLDRConfig.getInstance(); private static final Factory CLDR_FACTORY = CLDR_CONFIG.getCldrFactory(); @@ -51,20 +49,29 @@ public class InheritanceStats { static final char ZWSP = '\u200B'; static final char TSP = '\u2009'; - - public static void main(String[] args) { if (args.length == 0) { - args = new String[]{"dtd"}; + args = new String[] {"dtd"}; } for (String arg : args) { - switch(arg) { - case "stats": showLocaleStats(); break; - case "inherit": testInheritance(); break; - case "dtd": checkDtdData(); break; - case "attr": showAttributeValues(); break; - case "vxml": compareVxml(); break; - default: throw new IllegalArgumentException("bad argument"); + switch (arg) { + case "stats": + showLocaleStats(); + break; + case "inherit": + testInheritance(); + break; + case "dtd": + checkDtdData(); + break; + case "attr": + showAttributeValues(); + break; + case "vxml": + compareVxml(); + break; + default: + throw new IllegalArgumentException("bad argument"); } } } @@ -77,7 +84,8 @@ enum Status { diffPath, diffLocale; - static Set getSet(boolean isNullb, boolean isMarkerb, boolean bailey, boolean path, boolean locale) { + static Set getSet( + boolean isNullb, boolean isMarkerb, boolean bailey, boolean path, boolean locale) { Set s = EnumSet.noneOf(Status.class); if (isNullb) s.add(isNull); if (isMarkerb) s.add(isMarker); @@ -93,7 +101,9 @@ static Set getSet(boolean isNullb, boolean isMarkerb, boolean bailey, bo } return result; } + static final Map, Set> intern; + static { Map, Set> _intern = new LinkedHashMap<>(); add(_intern, Status.diffBailey); @@ -109,6 +119,7 @@ static Set getSet(boolean isNullb, boolean isMarkerb, boolean bailey, bo add(_intern, Status.isNull, Status.diffPath); intern = ImmutableMap.copyOf(_intern); } + static void add(Map, Set> _intern, Status... set) { ImmutableSortedSet s = ImmutableSortedSet.copyOf(set); _intern.put(s, s); @@ -162,14 +173,24 @@ public static void testInheritance() { // individual test cases String[][] tests = { - {"en", "path", "//ldml/units/unitLength[@type=\"long\"]/compoundUnit[@type=\"power3\"]/compoundUnitPattern1[@count=\"other\"][@gender=\"feminine\"]", + { + "en", + "path", + "//ldml/units/unitLength[@type=\"long\"]/compoundUnit[@type=\"power3\"]/compoundUnitPattern1[@count=\"other\"][@gender=\"feminine\"]", "//ldml/units/unitLength[@type=\"long\"]/compoundUnit[@type=\"power3\"]/compoundUnitPattern1[@count=\"other\"]" }, - {"en", "path", "//ldml/units/unitLength[@type=\"long\"]/unit[@type=\"graphics-dot\"]/unitPattern[@count=\"one\"][@alt=\"variant\"]", + { + "en", + "path", + "//ldml/units/unitLength[@type=\"long\"]/unit[@type=\"graphics-dot\"]/unitPattern[@count=\"one\"][@alt=\"variant\"]", "//ldml/units/unitLength[@type=\"long\"]/unit[@type=\"graphics-dot\"]/unitPattern[@count=\"one\"]" }, - {"de", "path", "//ldml/units/unitLength[@type=\"long\"]/compoundUnit[@type=\"power2\"]/compoundUnitPattern1[@count=\"one\"][@gender=\"feminine\"][@case=\"accusative\"][@alt=\"variant\"]", - "//ldml/units/unitLength[@type=\"long\"]/compoundUnit[@type=\"power2\"]/compoundUnitPattern1"}, + { + "de", + "path", + "//ldml/units/unitLength[@type=\"long\"]/compoundUnit[@type=\"power2\"]/compoundUnitPattern1[@count=\"one\"][@gender=\"feminine\"][@case=\"accusative\"][@alt=\"variant\"]", + "//ldml/units/unitLength[@type=\"long\"]/compoundUnit[@type=\"power2\"]/compoundUnitPattern1" + }, }; boolean allOk = true; for (String[] row : tests) { @@ -177,11 +198,17 @@ public static void testInheritance() { String type = row[1]; String path = row[2]; String expected = row[3]; - String testValue = inheritance.getBaileyValue(locale, path, testPathWhereFound, testLocaleWhereFound); + String testValue = + inheritance.getBaileyValue( + locale, path, testPathWhereFound, testLocaleWhereFound); String actual = null; - switch(type) { - case "path": actual = testPathWhereFound.value; break; - case "locale": actual = testLocaleWhereFound.value; break; + switch (type) { + case "path": + actual = testPathWhereFound.value; + break; + case "locale": + actual = testLocaleWhereFound.value; + break; } boolean success = assertEquals(path, expected, actual); @@ -189,10 +216,8 @@ public static void testInheritance() { inheritance.getBaileyValue(locale, path, testPathWhereFound, testLocaleWhereFound); allOk = false; } else { - System.out.println("\n" + locale - + "\t" + path - + "\nOK: \t" + actual - + "\t" + testValue); + System.out.println( + "\n" + locale + "\t" + path + "\nOK: \t" + actual + "\t" + testValue); } } @@ -206,37 +231,47 @@ public static void testInheritance() { if (resolvedCldrFile.getStringValue(path) == null) { continue; } -// String unresolvedValue = verticalChain.get(0).getStringValue(path); -// if (isHardValue(unresolvedValue)) { -// continue; // we have a value in the unresolved case, don't worry about it now -// } - String value = resolvedCldrFile.getStringValueWithBailey(path, pathWhereFound, localeWhereFound); - if ("code-fallback".equals(localeWhereFound.value) || "constructed".equals(pathWhereFound.value)) { + // String unresolvedValue = + // verticalChain.get(0).getStringValue(path); + // if (isHardValue(unresolvedValue)) { + // continue; // we have a value in the unresolved case, don't + // worry about it now + // } + String value = + resolvedCldrFile.getStringValueWithBailey( + path, pathWhereFound, localeWhereFound); + if ("code-fallback".equals(localeWhereFound.value) + || "constructed".equals(pathWhereFound.value)) { continue; } if (path.equals(pathWhereFound.value)) { continue; // ignore locale differences for now. } - String testValue = inheritance.getBaileyValue(locale, path, testPathWhereFound, testLocaleWhereFound); + String testValue = + inheritance.getBaileyValue( + locale, path, testPathWhereFound, testLocaleWhereFound); boolean success = true; success &= assertEquals(path, pathWhereFound.value, testPathWhereFound.value); - // success &= assertEquals(path, localeWhereFound.value, testLocaleWhereFound.value); + // success &= assertEquals(path, localeWhereFound.value, + // testLocaleWhereFound.value); if (!success) { // for debugging inheritance.getBaileyValue(locale, path, pathWhereFound, localeWhereFound); } else { - //System.out.println("\nSource: \t" + path + "\nOK: \t" + pathWhereFound.value); + // System.out.println("\nSource: \t" + path + "\nOK: \t" + + // pathWhereFound.value); } } } } -// AliasMapper aliasMapper = inheritance.aliasMapper; -// System.out.println("nonInitials: " + aliasMapper.nonInitials.size()); -// -// Set chain = inheritance.getInheritanceChain("en", "//ldml/units/unitLength[@type=\"long\"]/unit[@type=\"graphics-dot\"]/unitPattern[@count=\"one\"][@alt=\"variant\"]"); -// for (String s : chain) { -// System.out.println(s); -// } + // AliasMapper aliasMapper = inheritance.aliasMapper; + // System.out.println("nonInitials: " + aliasMapper.nonInitials.size()); + // + // Set chain = inheritance.getInheritanceChain("en", + // "//ldml/units/unitLength[@type=\"long\"]/unit[@type=\"graphics-dot\"]/unitPattern[@count=\"one\"][@alt=\"variant\"]"); + // for (String s : chain) { + // System.out.println(s); + // } } public static boolean assertEquals(String message, String expected, String actual) { @@ -265,36 +300,52 @@ static void checkDtdData() { } String aName = a.name; if (Inheritance.LATERAL_ATTRIBUTES.containsKey(aName)) { - System.out.println(aName - + "\t" + e - + "\t" + a.getMatchString() - + "\t" + a.getMode() - + "\t" + children); + System.out.println( + aName + + "\t" + + e + + "\t" + + a.getMatchString() + + "\t" + + a.getMode() + + "\t" + + children); } } } System.out.println("\nAttribute\tElement\tPossible Values"); lines.forEach(x -> System.out.println(x)); System.out.println("\nParents\tChild"); - childToParents.asMap().entrySet().forEach(x -> { - Element child = x.getKey(); - Collection parents = x.getValue(); - final Set fromElement = new HashSet<>(); - child.getParents().forEach( - y -> {if (!y.isDeprecated()) fromElement.add(y);} - ); - if (!fromElement.equals(parents)) { - throw new IllegalArgumentException("Bad parents in element"); - } - if (x.getValue().size() > 1) { - System.out.println(COMMA_JOINER.join(x.getValue()) + "\t" + x.getKey()); - } - }); + childToParents + .asMap() + .entrySet() + .forEach( + x -> { + Element child = x.getKey(); + Collection parents = x.getValue(); + final Set fromElement = new HashSet<>(); + child.getParents() + .forEach( + y -> { + if (!y.isDeprecated()) fromElement.add(y); + }); + if (!fromElement.equals(parents)) { + throw new IllegalArgumentException("Bad parents in element"); + } + if (x.getValue().size() > 1) { + System.out.println( + COMMA_JOINER.join(x.getValue()) + "\t" + x.getKey()); + } + }); } public static void showAttributeValues() { - final Set locales = StandardCodes.make().getLocaleCoverageLocales(Organization.cldr, ImmutableSortedSet.of(Level.MODERN, Level.MODERATE)); + final Set locales = + StandardCodes.make() + .getLocaleCoverageLocales( + Organization.cldr, + ImmutableSortedSet.of(Level.MODERN, Level.MODERATE)); AttributeData attributeData = new AttributeData(); Set attributes = Inheritance.LATERAL_ATTRIBUTES.keySet(); @@ -323,7 +374,11 @@ public static void showAttributeValues() { } } - public static void processLocales(final Set locales, AttributeData attributeData, Set attributes, Factory factory) { + public static void processLocales( + final Set locales, + AttributeData attributeData, + Set attributes, + Factory factory) { char lastChar = 0; for (String locale : locales) { CLDRFile cldrFile; @@ -346,10 +401,15 @@ private static final class AttributeData { public void showAlts() { System.out.println("\nP. Element\tElement\tAlt value\tStarred Path"); - dataToAlts.asMap().entrySet().forEach(x -> { - String element = x.getKey(); - System.out.println(element + "\t" + COMMA_JOINER.join(x.getValue())); - }); + dataToAlts + .asMap() + .entrySet() + .forEach( + x -> { + String element = x.getKey(); + System.out.println( + element + "\t" + COMMA_JOINER.join(x.getValue())); + }); } public void getAttributePaths(CLDRFile file, Set attributes) { @@ -375,11 +435,12 @@ public void getAttributePaths(CLDRFile file, Set attributes) { } if (altValue != null) { final String eName = parts.getElement(elementNumber); - String eName0 = parts.getElement(elementNumber-1); + String eName0 = parts.getElement(elementNumber - 1); dataToAlts.put( - eName0 + "\t" + eName + "\t" + attribute, -// pathStarrer.set(path) + "\t" + COMMA_JOINER.join(elementNameMap.get(eName).getChildren().keySet())), - altValue); + eName0 + "\t" + eName + "\t" + attribute, + // pathStarrer.set(path) + "\t" + + // COMMA_JOINER.join(elementNameMap.get(eName).getChildren().keySet())), + altValue); } } } @@ -394,26 +455,26 @@ public static void compareVxml() { for (String ldmlDirectory : DtdType.ldml.directories) { System.out.println("\n––––––––––\n" + ldmlDirectory + "\n––––––––––"); - final Factory mainFactory = SimpleFactory.make(CLDRPaths.COMMON_DIRECTORY + ldmlDirectory, ".*"); - final Factory dropFalse = SimpleFactory.make("/Users/markdavis/github/btangmu/common/" + ldmlDirectory, ".*"); - final Factory dropTrue = SimpleFactory.make("/Users/markdavis/github/common_true/common/" + ldmlDirectory, ".*"); - - System.out.println("locale" - + "\t" + "path" - + "\t" + "valueT" - + "\t" + "valueF" - + "\t" + "valueM" - + "\t" + "rawVT" - + "\t" + "rawVF" - + "\t" + "rawVM" - ); + final Factory mainFactory = + SimpleFactory.make(CLDRPaths.COMMON_DIRECTORY + ldmlDirectory, ".*"); + final Factory dropFalse = + SimpleFactory.make( + "/Users/markdavis/github/btangmu/common/" + ldmlDirectory, ".*"); + final Factory dropTrue = + SimpleFactory.make( + "/Users/markdavis/github/common_true/common/" + ldmlDirectory, ".*"); + + System.out.println( + "locale" + "\t" + "path" + "\t" + "valueT" + "\t" + "valueF" + "\t" + "valueM" + + "\t" + "rawVT" + "\t" + "rawVF" + "\t" + "rawVM"); Set seen = new HashSet<>(); for (String locale : mainFactory.getAvailable()) { if (SubmissionLocales.ALLOW_ALL_PATHS_BASIC.contains(locale)) { continue; } - Level targetCoverageLevel = StandardCodes.make().getLocaleCoverageLevel(Organization.cldr, locale); + Level targetCoverageLevel = + StandardCodes.make().getLocaleCoverageLevel(Organization.cldr, locale); CLDRFile cldrFileMain = mainFactory.make(locale, true); CLDRFile cldrFileFalse = dropFalse.make(locale, true); @@ -424,11 +485,12 @@ public static void compareVxml() { final CLDRFile unresolvedFalse = cldrFileFalse.getUnresolved(); // just in case there are differences in the paths, include all - Set sortedPaths = ImmutableSortedSet.naturalOrder() - .addAll(cldrFileMain) - .addAll(cldrFileFalse) - .addAll(cldrFileTrue) - .build(); + Set sortedPaths = + ImmutableSortedSet.naturalOrder() + .addAll(cldrFileMain) + .addAll(cldrFileFalse) + .addAll(cldrFileTrue) + .build(); for (String path : sortedPaths) { Level coverageLevel = SDI.getCoverageLevel(path, locale); @@ -436,7 +498,7 @@ public static void compareVxml() { continue; // skip levels higher than the target } if (skipAllowedChanges - && SubmissionLocales.allowEvenIfLimited(locale, path, false, false)) { + && SubmissionLocales.allowEvenIfLimited(locale, path, false, false)) { continue; } // we care about resolved differences. @@ -455,14 +517,21 @@ public static void compareVxml() { } } - String details = "\t" + path - + "\t" + valueTrue - + "\t" + valueFalse - + "\t" + valueMain - - + "\t" + unresolvedTrue.getStringValue(path) - + "\t" + unresolvedFalse.getStringValue(path) - + "\t" + unresolvedMain.getStringValue(path); + String details = + "\t" + + path + + "\t" + + valueTrue + + "\t" + + valueFalse + + "\t" + + valueMain + + "\t" + + unresolvedTrue.getStringValue(path) + + "\t" + + unresolvedFalse.getStringValue(path) + + "\t" + + unresolvedMain.getStringValue(path); // skip details that we have already seen @@ -474,6 +543,5 @@ public static void compareVxml() { } } } - } } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRFile.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRFile.java index ca50849cde1..1819fa2bfa7 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRFile.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRFile.java @@ -8,6 +8,27 @@ */ package org.unicode.cldr.util; +import com.google.common.base.Joiner; +import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap.Builder; +import com.google.common.collect.ImmutableSet; +import com.google.common.util.concurrent.UncheckedExecutionException; +import com.ibm.icu.impl.Relation; +import com.ibm.icu.impl.Row; +import com.ibm.icu.impl.Row.R2; +import com.ibm.icu.impl.Utility; +import com.ibm.icu.text.MessageFormat; +import com.ibm.icu.text.PluralRules; +import com.ibm.icu.text.SimpleDateFormat; +import com.ibm.icu.text.Transform; +import com.ibm.icu.text.UnicodeSet; +import com.ibm.icu.util.Calendar; +import com.ibm.icu.util.Freezable; +import com.ibm.icu.util.ICUUncheckedIOException; +import com.ibm.icu.util.Output; +import com.ibm.icu.util.ULocale; +import com.ibm.icu.util.VersionInfo; import java.io.File; import java.io.FileInputStream; import java.io.FilenameFilter; @@ -33,7 +54,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; - import org.unicode.cldr.test.CheckMetazones; import org.unicode.cldr.util.DayPeriodInfo.DayPeriod; import org.unicode.cldr.util.GrammarInfo.GrammaticalFeature; @@ -53,38 +73,17 @@ import org.xml.sax.XMLReader; import org.xml.sax.helpers.XMLReaderFactory; -import com.google.common.base.Joiner; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMap.Builder; -import com.google.common.collect.ImmutableSet; -import com.google.common.util.concurrent.UncheckedExecutionException; -import com.ibm.icu.impl.Relation; -import com.ibm.icu.impl.Row; -import com.ibm.icu.impl.Row.R2; -import com.ibm.icu.impl.Utility; -import com.ibm.icu.text.MessageFormat; -import com.ibm.icu.text.PluralRules; -import com.ibm.icu.text.SimpleDateFormat; -import com.ibm.icu.text.Transform; -import com.ibm.icu.text.UnicodeSet; -import com.ibm.icu.util.Calendar; -import com.ibm.icu.util.Freezable; -import com.ibm.icu.util.ICUUncheckedIOException; -import com.ibm.icu.util.Output; -import com.ibm.icu.util.ULocale; -import com.ibm.icu.util.VersionInfo; - /** - * This is a class that represents the contents of a CLDR file, as pairs, - * where the key is a "cleaned" xpath (with non-distinguishing attributes removed), - * and the value is an object that contains the full - * xpath plus a value, which is a string, or a node (the latter for atomic elements). - *

- * WARNING: The API on this class is likely to change. Having the full xpath on the value is clumsy; I need to - * change it to having the key be an object that contains the full xpath, but then sorts as if it were clean. - *

- * Each instance also contains a set of associated comments for each xpath. + * This is a class that represents the contents of a CLDR file, as pairs, where the key + * is a "cleaned" xpath (with non-distinguishing attributes removed), and the value is an object + * that contains the full xpath plus a value, which is a string, or a node (the latter for atomic + * elements). + * + *

WARNING: The API on this class is likely to change. Having the full xpath on the value + * is clumsy; I need to change it to having the key be an object that contains the full xpath, but + * then sorts as if it were clean. + * + *

Each instance also contains a set of associated comments for each xpath. * * @author medavis */ @@ -99,21 +98,23 @@ public class CLDRFile implements Freezable, Iterable, LocaleStringProvider { - private static final ImmutableSet casesNominativeOnly = ImmutableSet.of(GrammaticalFeature.grammaticalCase.getDefault(null)); + private static final ImmutableSet casesNominativeOnly = + ImmutableSet.of(GrammaticalFeature.grammaticalCase.getDefault(null)); /** * Variable to control whether File reads are buffered; this will about halve the time spent in - * loadFromFile() and Factory.make() from about 20 % to about 10 %. It will also noticeably improve the different - * unit tests take in the TestAll fixture. - * TRUE - use buffering (default) - * FALSE - do not use buffering + * loadFromFile() and Factory.make() from about 20 % to about 10 %. It will also noticeably + * improve the different unit tests take in the TestAll fixture. TRUE - use buffering (default) + * FALSE - do not use buffering */ private static final boolean USE_LOADING_BUFFER = true; private static final boolean DEBUG = false; - public static final Pattern ALT_PROPOSED_PATTERN = PatternCache.get(".*\\[@alt=\"[^\"]*proposed[^\"]*\"].*"); + public static final Pattern ALT_PROPOSED_PATTERN = + PatternCache.get(".*\\[@alt=\"[^\"]*proposed[^\"]*\"].*"); public static final Pattern DRAFT_PATTERN = PatternCache.get("\\[@draft=\"([^\"]*)\"\\]"); - public static final Pattern XML_SPACE_PATTERN = PatternCache.get("\\[@xml:space=\"([^\"]*)\"\\]"); + public static final Pattern XML_SPACE_PATTERN = + PatternCache.get("\\[@xml:space=\"([^\"]*)\"\\]"); private static boolean LOG_PROGRESS = false; @@ -124,10 +125,28 @@ public class CLDRFile implements Freezable, Iterable, LocaleSt public static final String SUPPLEMENTAL_METADATA = "supplementalMetadata"; public static final String SUPPLEMENTAL_PREFIX = "supplemental"; public static final String GEN_VERSION = "43"; - public static final List SUPPLEMENTAL_NAMES = Arrays.asList("characters", "coverageLevels", "dayPeriods", "genderList", "grammaticalFeatures", - "languageInfo", - "languageGroup", "likelySubtags", "metaZones", "numberingSystems", "ordinals", "pluralRanges", "plurals", "postalCodeData", "rgScope", - "supplementalData", "supplementalMetadata", "telephoneCodeData", "units", "windowsZones"); + public static final List SUPPLEMENTAL_NAMES = + Arrays.asList( + "characters", + "coverageLevels", + "dayPeriods", + "genderList", + "grammaticalFeatures", + "languageInfo", + "languageGroup", + "likelySubtags", + "metaZones", + "numberingSystems", + "ordinals", + "pluralRanges", + "plurals", + "postalCodeData", + "rgScope", + "supplementalData", + "supplementalMetadata", + "telephoneCodeData", + "units", + "windowsZones"); private Set extraPaths = null; @@ -140,27 +159,30 @@ public class CLDRFile implements Freezable, Iterable, LocaleSt private File supplementalDirectory; public enum DraftStatus { - unconfirmed, provisional, contributed, approved; + unconfirmed, + provisional, + contributed, + approved; public static DraftStatus forString(String string) { - return string == null ? DraftStatus.approved - : DraftStatus.valueOf(string.toLowerCase(Locale.ENGLISH)); + return string == null + ? DraftStatus.approved + : DraftStatus.valueOf(string.toLowerCase(Locale.ENGLISH)); } /** * Get the draft status from a full xpath + * * @param xpath * @return */ public static DraftStatus forXpath(String xpath) { - final String status = XPathParts.getFrozenInstance(xpath).getAttributeValue(-1, "draft"); + final String status = + XPathParts.getFrozenInstance(xpath).getAttributeValue(-1, "draft"); return forString(status); } - /** - * Return the XPath suffix for this draft status - * or "" for approved. - */ + /** Return the XPath suffix for this draft status or "" for approved. */ public String asXpath() { if (this == approved) { return ""; @@ -173,19 +195,26 @@ public String asXpath() { @Override public String toString() { return "{" - + "locked=" + locked - + " locale=" + dataSource.getLocaleID() - + " dataSource=" + dataSource.toString() - + "}"; + + "locked=" + + locked + + " locale=" + + dataSource.getLocaleID() + + " dataSource=" + + dataSource.toString() + + "}"; } public String toString(String regex) { return "{" - + "locked=" + locked - + " locale=" + dataSource.getLocaleID() - + " regex=" + regex - + " dataSource=" + dataSource.toString(regex) - + "}"; + + "locked=" + + locked + + " locale=" + + dataSource.getLocaleID() + + " regex=" + + regex + + " dataSource=" + + dataSource.toString(regex) + + "}"; } // for refactoring @@ -208,20 +237,22 @@ public boolean isNonInheriting() { /** * Construct a new CLDRFile. * - * @param dataSource - * must not be null + * @param dataSource must not be null */ public CLDRFile(XMLSource dataSource) { this.dataSource = dataSource; if (DEBUG_CLDR_FILE) { - creationTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(Calendar.getInstance().getTime()); + creationTime = + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") + .format(Calendar.getInstance().getTime()); System.out.println("📂 Created new CLDRFile(dataSource) at " + creationTime); } } /** * get Unresolved CLDRFile + * * @param localeId * @param dirs * @param minimalDraftStatus @@ -240,12 +271,17 @@ public CLDRFile(XMLSource dataSource, XMLSource... resolvingParents) { this.dataSource = new ResolvingSource(sourceList); if (DEBUG_CLDR_FILE) { - creationTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(Calendar.getInstance().getTime()); - System.out.println("📂 Created new CLDRFile(dataSource, XMLSource... resolvingParents) at " + creationTime); + creationTime = + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") + .format(Calendar.getInstance().getTime()); + System.out.println( + "📂 Created new CLDRFile(dataSource, XMLSource... resolvingParents) at " + + creationTime); } } - public static CLDRFile loadFromFile(File f, String localeName, DraftStatus minimalDraftStatus, XMLSource source) { + public static CLDRFile loadFromFile( + File f, String localeName, DraftStatus minimalDraftStatus, XMLSource source) { String fullFileName = f.getAbsolutePath(); try { fullFileName = PathUtilities.getNormalizedPathString(f); @@ -263,7 +299,7 @@ public static CLDRFile loadFromFile(File f, String localeName, DraftStatus minim } } else { // previous version - do not use buffering - try (InputStream fis = new FileInputStream(f);) { + try (InputStream fis = new FileInputStream(f); ) { cldrFile = load(fullFileName, localeName, fis, minimalDraftStatus, source); return cldrFile; } @@ -279,7 +315,8 @@ public static CLDRFile loadFromFile(File f, String localeName, DraftStatus minim } } - public static CLDRFile loadFromFiles(List dirs, String localeName, DraftStatus minimalDraftStatus, XMLSource source) { + public static CLDRFile loadFromFiles( + List dirs, String localeName, DraftStatus minimalDraftStatus, XMLSource source) { try { if (DEBUG_LOGGING) { System.out.println("Parsing: " + dirs); @@ -292,7 +329,11 @@ public static CLDRFile loadFromFiles(List dirs, String localeName, DraftSt for (File dir : dirs) { File f = new File(dir, localeName + ".xml"); try (InputStream fis = InputStreamFactory.createInputStream(f)) { - cldrFile.loadFromInputStream(PathUtilities.getNormalizedPathString(f), localeName, fis, minimalDraftStatus); + cldrFile.loadFromInputStream( + PathUtilities.getNormalizedPathString(f), + localeName, + fis, + minimalDraftStatus); } } return cldrFile; @@ -310,7 +351,8 @@ public static CLDRFile loadFromFiles(List dirs, String localeName, DraftSt } /** - * Produce a CLDRFile from a localeName, given a directory. (Normally a Factory is used to create CLDRFiles.) + * Produce a CLDRFile from a localeName, given a directory. (Normally a Factory is used to + * create CLDRFiles.) * * @param f * @param localeName @@ -320,11 +362,13 @@ public static CLDRFile loadFromFile(File f, String localeName, DraftStatus minim return loadFromFile(f, localeName, minimalDraftStatus, new SimpleXMLSource(localeName)); } - public static CLDRFile loadFromFiles(List dirs, String localeName, DraftStatus minimalDraftStatus) { + public static CLDRFile loadFromFiles( + List dirs, String localeName, DraftStatus minimalDraftStatus) { return loadFromFiles(dirs, localeName, minimalDraftStatus, new SimpleXMLSource(localeName)); } - static CLDRFile load(String fileName, String localeName, InputStream fis, DraftStatus minimalDraftStatus) { + static CLDRFile load( + String fileName, String localeName, InputStream fis, DraftStatus minimalDraftStatus) { return load(fileName, localeName, fis, minimalDraftStatus, new SimpleXMLSource(localeName)); } @@ -334,34 +378,41 @@ static CLDRFile load(String fileName, String localeName, InputStream fis, DraftS * @param localeName * @param fis */ - private static CLDRFile load(String fileName, String localeName, InputStream fis, - DraftStatus minimalDraftStatus, - XMLSource source) { + private static CLDRFile load( + String fileName, + String localeName, + InputStream fis, + DraftStatus minimalDraftStatus, + XMLSource source) { CLDRFile cldrFile = new CLDRFile(source); return cldrFile.loadFromInputStream(fileName, localeName, fis, minimalDraftStatus); } /** * Low-level function, only normally used for testing. + * * @param fileName * @param localeName * @param fis * @param minimalDraftStatus * @return */ - public CLDRFile loadFromInputStream(String fileName, String localeName, InputStream fis, DraftStatus minimalDraftStatus) { + public CLDRFile loadFromInputStream( + String fileName, String localeName, InputStream fis, DraftStatus minimalDraftStatus) { CLDRFile cldrFile = this; MyDeclHandler DEFAULT_DECLHANDLER = new MyDeclHandler(cldrFile, minimalDraftStatus); XMLFileReader.read(fileName, fis, -1, true, DEFAULT_DECLHANDLER); if (DEFAULT_DECLHANDLER.isSupplemental < 0) { - throw new IllegalArgumentException("root of file must be either ldml or supplementalData"); + throw new IllegalArgumentException( + "root of file must be either ldml or supplementalData"); } cldrFile.setNonInheriting(DEFAULT_DECLHANDLER.isSupplemental > 0); if (DEFAULT_DECLHANDLER.overrideCount > 0) { - throw new IllegalArgumentException("Internal problems: either data file has duplicate path, or" + - " CLDRFile.isDistinguishing() or CLDRFile.isOrdered() need updating: " - + DEFAULT_DECLHANDLER.overrideCount - + "; The exact problems are printed on the console above."); + throw new IllegalArgumentException( + "Internal problems: either data file has duplicate path, or" + + " CLDRFile.isDistinguishing() or CLDRFile.isOrdered() need updating: " + + DEFAULT_DECLHANDLER.overrideCount + + "; The exact problems are printed on the console above."); } if (localeName == null) { cldrFile.dataSource.setLocaleID(cldrFile.getLocaleIDFromIdentity()); @@ -386,38 +437,34 @@ public CLDRFile cloneAsThawed() { } } - /** - * Prints the contents of the file (the xpaths/values) to the console. - * - */ + /** Prints the contents of the file (the xpaths/values) to the console. */ public CLDRFile show() { - for (Iterator it2 = iterator(); it2.hasNext();) { + for (Iterator it2 = iterator(); it2.hasNext(); ) { String xpath = it2.next(); System.out.println(getFullXPath(xpath) + " =>\t" + getStringValue(xpath)); } return this; } - private final static Map nullOptions = Collections.unmodifiableMap(new TreeMap()); + private static final Map nullOptions = + Collections.unmodifiableMap(new TreeMap()); /** - * Write the corresponding XML file out, with the normal formatting and indentation. - * Will update the identity element, including version, and other items. - * If the CLDRFile is empty, the DTD type will be //ldml. + * Write the corresponding XML file out, with the normal formatting and indentation. Will update + * the identity element, including version, and other items. If the CLDRFile is empty, the DTD + * type will be //ldml. */ public void write(PrintWriter pw) { write(pw, nullOptions); } /** - * Write the corresponding XML file out, with the normal formatting and indentation. - * Will update the identity element, including version, and other items. - * If the CLDRFile is empty, the DTD type will be //ldml. + * Write the corresponding XML file out, with the normal formatting and indentation. Will update + * the identity element, including version, and other items. If the CLDRFile is empty, the DTD + * type will be //ldml. * - * @param pw - * writer to print to - * @param options - * map of options for writing + * @param pw writer to print to + * @param options map of options for writing * @return true if we write the file, false if we cancel due to skipping all paths */ public boolean write(PrintWriter pw, Map options) { @@ -426,23 +473,22 @@ public boolean write(PrintWriter pw, Map options) { return true; } - /** - * Get a string value from an xpath. - */ + /** Get a string value from an xpath. */ @Override public String getStringValue(String xpath) { try { String result = dataSource.getValueAtPath(xpath); if (result == null && dataSource.isResolving()) { final String fallbackPath = getFallbackPath(xpath, false, true); - // often fallbackPath equals xpath -- in such cases, isn't it a waste of time to call getValueAtPath again? + // often fallbackPath equals xpath -- in such cases, isn't it a waste of time to + // call getValueAtPath again? if (fallbackPath != null) { result = dataSource.getValueAtPath(fallbackPath); } } if (isResolved() - && GlossonymConstructor.valueIsBogus(result) - && GlossonymConstructor.pathIsEligible(xpath)) { + && GlossonymConstructor.valueIsBogus(result) + && GlossonymConstructor.pathIsEligible(xpath)) { final String constructedValue = new GlossonymConstructor(this).getValue(xpath); if (constructedValue != null) { result = constructedValue; @@ -455,14 +501,19 @@ public String getStringValue(String xpath) { } /** - * Get GeorgeBailey value: that is, what the value would be if it were not directly contained in the file at that path. - * If the value is null or INHERITANCE_MARKER (with resolving), then baileyValue = resolved value. - * A non-resolving CLDRFile will always return null. + * Get GeorgeBailey value: that is, what the value would be if it were not directly contained in + * the file at that path. If the value is null or INHERITANCE_MARKER (with resolving), then + * baileyValue = resolved value. A non-resolving CLDRFile will always return null. */ - public String getBaileyValue(String xpath, Output pathWhereFound, Output localeWhereFound) { + public String getBaileyValue( + String xpath, Output pathWhereFound, Output localeWhereFound) { String result = dataSource.getBaileyValue(xpath, pathWhereFound, localeWhereFound); - if ((result == null || result.equals(CldrUtility.INHERITANCE_MARKER)) && dataSource.isResolving()) { - final String fallbackPath = getFallbackPath(xpath, false, false); // return null if there is no different sideways path + if ((result == null || result.equals(CldrUtility.INHERITANCE_MARKER)) + && dataSource.isResolving()) { + final String fallbackPath = + getFallbackPath( + xpath, false, + false); // return null if there is no different sideways path if (xpath.equals(fallbackPath)) { getFallbackPath(xpath, false, true); throw new IllegalArgumentException(); // should never happen @@ -480,9 +531,12 @@ public String getBaileyValue(String xpath, Output pathWhereFound, Output } } } - if (isResolved() && GlossonymConstructor.valueIsBogus(result) && GlossonymConstructor.pathIsEligible(xpath)) { + if (isResolved() + && GlossonymConstructor.valueIsBogus(result) + && GlossonymConstructor.pathIsEligible(xpath)) { final GlossonymConstructor gc = new GlossonymConstructor(this); - final String constructedValue = gc.getValueAndTrack(xpath, pathWhereFound, localeWhereFound); + final String constructedValue = + gc.getValueAndTrack(xpath, pathWhereFound, localeWhereFound); if (constructedValue != null) { result = constructedValue; } @@ -505,12 +559,11 @@ public String transform(@SuppressWarnings("unused") String source) { /** * Only call if xpath doesn't exist in the current file. - *

- * For now, just handle counts and cases: see getCountPath Also handle extraPaths + * + *

For now, just handle counts and cases: see getCountPath Also handle extraPaths * * @param xpath - * @param winning - * TODO + * @param winning TODO * @param checkExtraPaths TODO * @return */ @@ -529,33 +582,35 @@ private String getFallbackPath(String xpath, boolean winning, boolean checkExtra * * @param xpath the distinguished path * @return the full path - * - * Examples: - * - * xpath = //ldml/localeDisplayNames/scripts/script[@type="Adlm"] - * result = //ldml/localeDisplayNames/scripts/script[@type="Adlm"][@draft="unconfirmed"] - * - * xpath = //ldml/dates/calendars/calendar[@type="hebrew"]/dateFormats/dateFormatLength[@type="full"]/dateFormat[@type="standard"]/pattern[@type="standard"] - * result = //ldml/dates/calendars/calendar[@type="hebrew"]/dateFormats/dateFormatLength[@type="full"]/dateFormat[@type="standard"]/pattern[@type="standard"][@numbers="hebr"] + *

Examples: + *

xpath = //ldml/localeDisplayNames/scripts/script[@type="Adlm"] result = + * //ldml/localeDisplayNames/scripts/script[@type="Adlm"][@draft="unconfirmed"] + *

xpath = + * //ldml/dates/calendars/calendar[@type="hebrew"]/dateFormats/dateFormatLength[@type="full"]/dateFormat[@type="standard"]/pattern[@type="standard"] + * result = + * //ldml/dates/calendars/calendar[@type="hebrew"]/dateFormats/dateFormatLength[@type="full"]/dateFormat[@type="standard"]/pattern[@type="standard"][@numbers="hebr"] */ public String getFullXPath(String xpath) { if (xpath == null) { throw new NullPointerException("Null distinguishing xpath"); } String result = dataSource.getFullPath(xpath); - return result != null ? result : xpath; // we can't add any non-distinguishing values if there is nothing there. -// if (result == null && dataSource.isResolving()) { -// String fallback = getFallbackPath(xpath, true); -// if (fallback != null) { -// // TODO, add attributes from fallback into main -// result = xpath; -// } -// } -// return result; + return result != null + ? result + : xpath; // we can't add any non-distinguishing values if there is nothing there. + // if (result == null && dataSource.isResolving()) { + // String fallback = getFallbackPath(xpath, true); + // if (fallback != null) { + // // TODO, add attributes from fallback into main + // result = xpath; + // } + // } + // return result; } /** * Get the last modified date (if available) from a distinguished path. + * * @return date or null if not available. */ public Date getLastModifiedDate(String xpath) { @@ -563,38 +618,43 @@ public Date getLastModifiedDate(String xpath) { } /** - * Find out where the value was found (for resolving locales). Returns code-fallback as the location if nothing is - * found + * Find out where the value was found (for resolving locales). Returns code-fallback as the + * location if nothing is found * - * @param distinguishedXPath - * path (must be distinguished!) - * @param status - * the distinguished path where the item was found. Pass in null if you don't care. + * @param distinguishedXPath path (must be distinguished!) + * @param status the distinguished path where the item was found. Pass in null if you don't + * care. */ @Override public String getSourceLocaleID(String distinguishedXPath, CLDRFile.Status status) { - return getSourceLocaleIdExtended(distinguishedXPath, status, true /* skipInheritanceMarker */); + return getSourceLocaleIdExtended( + distinguishedXPath, status, true /* skipInheritanceMarker */); } /** - * Find out where the value was found (for resolving locales). Returns code-fallback as the location if nothing is - * found + * Find out where the value was found (for resolving locales). Returns code-fallback as the + * location if nothing is found * - * @param distinguishedXPath - * path (must be distinguished!) - * @param status - * the distinguished path where the item was found. Pass in null if you don't care. + * @param distinguishedXPath path (must be distinguished!) + * @param status the distinguished path where the item was found. Pass in null if you don't + * care. * @param skipInheritanceMarker if true, skip sources in which value is INHERITANCE_MARKER * @return the locale id as a string */ - public String getSourceLocaleIdExtended(String distinguishedXPath, CLDRFile.Status status, boolean skipInheritanceMarker) { - String result = dataSource.getSourceLocaleIdExtended(distinguishedXPath, status, skipInheritanceMarker); + public String getSourceLocaleIdExtended( + String distinguishedXPath, CLDRFile.Status status, boolean skipInheritanceMarker) { + String result = + dataSource.getSourceLocaleIdExtended( + distinguishedXPath, status, skipInheritanceMarker); if (result == XMLSource.CODE_FALLBACK_ID && dataSource.isResolving()) { final String fallbackPath = getFallbackPath(distinguishedXPath, false, true); if (fallbackPath != null && !fallbackPath.equals(distinguishedXPath)) { - result = dataSource.getSourceLocaleIdExtended(fallbackPath, status, skipInheritanceMarker); + result = + dataSource.getSourceLocaleIdExtended( + fallbackPath, status, skipInheritanceMarker); } - if (result == XMLSource.CODE_FALLBACK_ID && getConstructedValue(distinguishedXPath) != null) { + if (result == XMLSource.CODE_FALLBACK_ID + && getConstructedValue(distinguishedXPath) != null) { if (status != null) { status.pathWhereFound = GlossonymConstructor.PSEUDO_PATH; } @@ -623,20 +683,22 @@ public boolean isHere(String path) { public CLDRFile add(String currentFullXPath, String value) { if (locked) throw new UnsupportedOperationException("Attempt to modify locked object"); // StringValue v = new StringValue(value, currentFullXPath); - Log.logln(LOG_PROGRESS, "ADDING: \t" + currentFullXPath + " \t" + value + "\t" + currentFullXPath); + Log.logln( + LOG_PROGRESS, + "ADDING: \t" + currentFullXPath + " \t" + value + "\t" + currentFullXPath); // xpath = xpath.intern(); try { dataSource.putValueAtPath(currentFullXPath, value); } catch (RuntimeException e) { - throw (IllegalArgumentException) new IllegalArgumentException("failed adding " + currentFullXPath + ",\t" - + value).initCause(e); + throw (IllegalArgumentException) + new IllegalArgumentException( + "failed adding " + currentFullXPath + ",\t" + value) + .initCause(e); } return this; } - /** - * Note where this element was parsed. - */ + /** Note where this element was parsed. */ public CLDRFile addSourceLocation(String currentFullXPath, XMLSource.SourceLocation location) { dataSource.addSourceLocation(currentFullXPath, location); return this; @@ -644,6 +706,7 @@ public CLDRFile addSourceLocation(String currentFullXPath, XMLSource.SourceLocat /** * Get the line and column for a path + * * @param path xpath or fullpath */ public XMLSource.SourceLocation getSourceLocation(String path) { @@ -656,9 +719,13 @@ public CLDRFile addComment(String xpath, String comment, Comments.CommentType ty // System.out.println("Adding comment: <" + xpath + "> '" + comment + "'"); Log.logln(LOG_PROGRESS, "ADDING Comment: \t" + type + "\t" + xpath + " \t" + comment); if (xpath == null || xpath.length() == 0) { - dataSource.getXpathComments().setFinalComment( - CldrUtility.joinWithSeparation(dataSource.getXpathComments().getFinalComment(), XPathParts.NEWLINE, - comment)); + dataSource + .getXpathComments() + .setFinalComment( + CldrUtility.joinWithSeparation( + dataSource.getXpathComments().getFinalComment(), + XPathParts.NEWLINE, + comment)); } else { xpath = getDistinguishingXPath(xpath, null); dataSource.getXpathComments().addComment(type, xpath, comment); @@ -667,15 +734,14 @@ public CLDRFile addComment(String xpath, String comment, Comments.CommentType ty } // TODO Change into enum, update docs - static final public int MERGE_KEEP_MINE = 0, - MERGE_REPLACE_MINE = 1, - MERGE_ADD_ALTERNATE = 2, - MERGE_REPLACE_MY_DRAFT = 3; + public static final int MERGE_KEEP_MINE = 0, + MERGE_REPLACE_MINE = 1, + MERGE_ADD_ALTERNATE = 2, + MERGE_REPLACE_MY_DRAFT = 3; /** - * Merges elements from another CLDR file. Note: when both have the same xpath key, - * the keepMine determines whether "my" values are kept - * or the other files values are kept. + * Merges elements from another CLDR file. Note: when both have the same xpath key, the keepMine + * determines whether "my" values are kept or the other files values are kept. * * @param other * @param conflict_resolution @@ -692,17 +758,18 @@ public CLDRFile putAll(CLDRFile other, int conflict_resolution) { } else if (conflict_resolution == MERGE_REPLACE_MY_DRAFT) { // first find all my alt=..proposed items Set hasDraftVersion = new HashSet<>(); - for (Iterator it = dataSource.iterator(); it.hasNext();) { + for (Iterator it = dataSource.iterator(); it.hasNext(); ) { String cpath = it.next(); String fullpath = getFullXPath(cpath); if (fullpath.indexOf("[@draft") >= 0) { - hasDraftVersion.add(getNondraftNonaltXPath(cpath)); // strips the alt and the draft + hasDraftVersion.add( + getNondraftNonaltXPath(cpath)); // strips the alt and the draft } } // only replace draft items! // this is either an item with draft in the fullpath // or an item with draft and alt in the full path - for (Iterator it = other.iterator(); it.hasNext();) { + for (Iterator it = other.iterator(); it.hasNext(); ) { String cpath = it.next(); cpath = getNondraftNonaltXPath(cpath); String newValue = other.getStringValue(cpath); @@ -711,12 +778,23 @@ public CLDRFile putAll(CLDRFile other, int conflict_resolution) { newFullPath = addReferencesIfNeeded(newFullPath, getFullXPath(cpath)); if (!hasDraftVersion.contains(cpath)) { - if (cpath.startsWith("//ldml/identity/")) continue; // skip, since the error msg is not needed. + if (cpath.startsWith("//ldml/identity/")) + continue; // skip, since the error msg is not needed. String myVersion = getStringValue(cpath); if (myVersion == null || !newValue.equals(myVersion)) { - Log.logln(getLocaleID() + "\tDenied attempt to replace non-draft" + CldrUtility.LINE_SEPARATOR - + "\tcurr: [" + cpath + ",\t" - + myVersion + "]" + CldrUtility.LINE_SEPARATOR + "\twith: [" + newValue + "]"); + Log.logln( + getLocaleID() + + "\tDenied attempt to replace non-draft" + + CldrUtility.LINE_SEPARATOR + + "\tcurr: [" + + cpath + + ",\t" + + myVersion + + "]" + + CldrUtility.LINE_SEPARATOR + + "\twith: [" + + newValue + + "]"); continue; } } @@ -724,18 +802,20 @@ public CLDRFile putAll(CLDRFile other, int conflict_resolution) { dataSource.putValueAtPath(newFullPath, newValue); } } else if (conflict_resolution == MERGE_ADD_ALTERNATE) { - for (Iterator it = other.iterator(); it.hasNext();) { + for (Iterator it = other.iterator(); it.hasNext(); ) { String key = it.next(); String otherValue = other.getStringValue(key); String myValue = dataSource.getValueAtPath(key); if (myValue == null) { dataSource.putValueAtPath(other.getFullXPath(key), otherValue); } else if (!(myValue.equals(otherValue) - && equalsIgnoringDraft(getFullXPath(key), other.getFullXPath(key))) - && !key.startsWith("//ldml/identity")) { - for (int i = 0;; ++i) { + && equalsIgnoringDraft(getFullXPath(key), other.getFullXPath(key))) + && !key.startsWith("//ldml/identity")) { + for (int i = 0; ; ++i) { String prop = "proposed" + (i == 0 ? "" : String.valueOf(i)); - XPathParts parts = XPathParts.getFrozenInstance(other.getFullXPath(key)).cloneAsThawed(); // not frozen, for addAttribut + XPathParts parts = + XPathParts.getFrozenInstance(other.getFullXPath(key)) + .cloneAsThawed(); // not frozen, for addAttribut String fullPath = parts.addAttribute("alt", prop).toString(); String path = getDistinguishingXPath(fullPath, null); if (dataSource.getValueAtPath(path) != null) { @@ -750,21 +830,25 @@ && equalsIgnoringDraft(getFullXPath(key), other.getFullXPath(key))) throw new IllegalArgumentException("Illegal operand: " + conflict_resolution); } - dataSource.getXpathComments().setInitialComment( - CldrUtility.joinWithSeparation(dataSource.getXpathComments().getInitialComment(), - XPathParts.NEWLINE, - other.dataSource.getXpathComments().getInitialComment())); - dataSource.getXpathComments().setFinalComment( - CldrUtility.joinWithSeparation(dataSource.getXpathComments().getFinalComment(), - XPathParts.NEWLINE, - other.dataSource.getXpathComments().getFinalComment())); + dataSource + .getXpathComments() + .setInitialComment( + CldrUtility.joinWithSeparation( + dataSource.getXpathComments().getInitialComment(), + XPathParts.NEWLINE, + other.dataSource.getXpathComments().getInitialComment())); + dataSource + .getXpathComments() + .setFinalComment( + CldrUtility.joinWithSeparation( + dataSource.getXpathComments().getFinalComment(), + XPathParts.NEWLINE, + other.dataSource.getXpathComments().getFinalComment())); dataSource.getXpathComments().joinAll(other.dataSource.getXpathComments()); return this; } - /** - * - */ + /** */ private String addReferencesIfNeeded(String newFullPath, String fullXPath) { if (fullXPath == null || fullXPath.indexOf("[@references=") < 0) { return newFullPath; @@ -789,85 +873,83 @@ private String addReferencesIfNeeded(String newFullPath, String fullXPath) { XPathParts newParts = XPathParts.getFrozenInstance(newFullPath); Map attributes = newParts.getAttributes(newParts.size() - 1); String references = attributes.get("references"); - if (references == null) - references = accummulatedReferences; - else - references += ", " + accummulatedReferences; + if (references == null) references = accummulatedReferences; + else references += ", " + accummulatedReferences; attributes.put("references", references); - System.out.println("Changing " + newFullPath + " plus " + fullXPath + " to " + newParts.toString()); + System.out.println( + "Changing " + newFullPath + " plus " + fullXPath + " to " + newParts.toString()); return newParts.toString(); } - /** - * Removes an element from a CLDRFile. - */ + /** Removes an element from a CLDRFile. */ public CLDRFile remove(String xpath) { remove(xpath, false); return this; } - /** - * Removes an element from a CLDRFile. - */ + /** Removes an element from a CLDRFile. */ public CLDRFile remove(String xpath, boolean butComment) { if (locked) throw new UnsupportedOperationException("Attempt to modify locked object"); if (butComment) { - appendFinalComment(dataSource.getFullPath(xpath) + "::<" + dataSource.getValueAtPath(xpath) + ">"); + appendFinalComment( + dataSource.getFullPath(xpath) + "::<" + dataSource.getValueAtPath(xpath) + ">"); } dataSource.removeValueAtPath(xpath); return this; } - /** - * Removes all xpaths from a CLDRFile. - */ + /** Removes all xpaths from a CLDRFile. */ public CLDRFile removeAll(Set xpaths, boolean butComment) { if (butComment) appendFinalComment("Illegal attributes removed:"); - for (Iterator it = xpaths.iterator(); it.hasNext();) { + for (Iterator it = xpaths.iterator(); it.hasNext(); ) { remove(it.next(), butComment); } return this; } - /** - * Code should explicitly include CODE_FALLBACK - */ - public static final Pattern specialsToKeep = PatternCache.get( - "/(" + - "measurementSystemName" + - "|codePattern" + - "|calendar\\[\\@type\\=\"[^\"]*\"\\]/(?!dateTimeFormats/appendItems)" + // gregorian - "|numbers/symbols/(decimal/group)" + - "|timeZoneNames/(hourFormat|gmtFormat|regionFormat)" + - "|pattern" + - ")"); - - static public final Pattern specialsToPushFromRoot = PatternCache.get( - "/(" + - "calendar\\[\\@type\\=\"gregorian\"\\]/" + - "(?!fields)" + - "(?!dateTimeFormats/appendItems)" + - "(?!.*\\[@type=\"format\"].*\\[@type=\"narrow\"])" + - "(?!.*\\[@type=\"stand-alone\"].*\\[@type=\"(abbreviated|wide)\"])" + - "|numbers/symbols/(decimal/group)" + - "|timeZoneNames/(hourFormat|gmtFormat|regionFormat)" + - ")"); + /** Code should explicitly include CODE_FALLBACK */ + public static final Pattern specialsToKeep = + PatternCache.get( + "/(" + + "measurementSystemName" + + "|codePattern" + + "|calendar\\[\\@type\\=\"[^\"]*\"\\]/(?!dateTimeFormats/appendItems)" + + // gregorian + "|numbers/symbols/(decimal/group)" + + "|timeZoneNames/(hourFormat|gmtFormat|regionFormat)" + + "|pattern" + + ")"); + + public static final Pattern specialsToPushFromRoot = + PatternCache.get( + "/(" + + "calendar\\[\\@type\\=\"gregorian\"\\]/" + + "(?!fields)" + + "(?!dateTimeFormats/appendItems)" + + "(?!.*\\[@type=\"format\"].*\\[@type=\"narrow\"])" + + "(?!.*\\[@type=\"stand-alone\"].*\\[@type=\"(abbreviated|wide)\"])" + + "|numbers/symbols/(decimal/group)" + + "|timeZoneNames/(hourFormat|gmtFormat|regionFormat)" + + ")"); private static final boolean MINIMIZE_ALT_PROPOSED = false; public interface RetentionTest { public enum Retention { - RETAIN, REMOVE, RETAIN_IF_DIFFERENT + RETAIN, + REMOVE, + RETAIN_IF_DIFFERENT } public Retention getRetention(String path); } - /** - * Removes all items with same value - */ - public CLDRFile removeDuplicates(CLDRFile other, boolean butComment, RetentionTest keepIfMatches, - Collection removedItems) { + /** Removes all items with same value */ + public CLDRFile removeDuplicates( + CLDRFile other, + boolean butComment, + RetentionTest keepIfMatches, + Collection removedItems) { if (locked) throw new UnsupportedOperationException("Attempt to modify locked object"); // Matcher specialPathMatcher = dontRemoveSpecials ? specialsToKeep.matcher("") : null; boolean first = true; @@ -877,7 +959,8 @@ public CLDRFile removeDuplicates(CLDRFile other, boolean butComment, RetentionTe removedItems.clear(); } Set checked = new HashSet<>(); - for (Iterator it = iterator(); it.hasNext();) { // see what items we have that the other also has + for (Iterator it = iterator(); + it.hasNext(); ) { // see what items we have that the other also has String curXpath = it.next(); boolean logicDuplicate = true; @@ -889,57 +972,57 @@ public CLDRFile removeDuplicates(CLDRFile other, boolean butComment, RetentionTe while (iter.hasNext() && logicDuplicate) { String xpath = iter.next(); switch (keepIfMatches.getRetention(xpath)) { - case RETAIN: - logicDuplicate = false; - continue; - case RETAIN_IF_DIFFERENT: - String currentValue = dataSource.getValueAtPath(xpath); - if (currentValue == null) { + case RETAIN: logicDuplicate = false; continue; - } - String otherXpath = xpath; - String otherValue = other.dataSource.getValueAtPath(otherXpath); - if (!currentValue.equals(otherValue)) { - if (MINIMIZE_ALT_PROPOSED) { - otherXpath = CLDRFile.getNondraftNonaltXPath(xpath); - if (otherXpath.equals(xpath)) { - logicDuplicate = false; - continue; - } - otherValue = other.dataSource.getValueAtPath(otherXpath); - if (!currentValue.equals(otherValue)) { + case RETAIN_IF_DIFFERENT: + String currentValue = dataSource.getValueAtPath(xpath); + if (currentValue == null) { + logicDuplicate = false; + continue; + } + String otherXpath = xpath; + String otherValue = other.dataSource.getValueAtPath(otherXpath); + if (!currentValue.equals(otherValue)) { + if (MINIMIZE_ALT_PROPOSED) { + otherXpath = CLDRFile.getNondraftNonaltXPath(xpath); + if (otherXpath.equals(xpath)) { + logicDuplicate = false; + continue; + } + otherValue = other.dataSource.getValueAtPath(otherXpath); + if (!currentValue.equals(otherValue)) { + logicDuplicate = false; + continue; + } + } else { logicDuplicate = false; continue; } - } else { + } + String keepValue = + XMLSource.getPathsAllowingDuplicates().get(xpath); + if (keepValue != null && keepValue.equals(currentValue)) { logicDuplicate = false; continue; } - } - String keepValue = XMLSource.getPathsAllowingDuplicates().get(xpath); - if (keepValue != null && keepValue.equals(currentValue)) { - logicDuplicate = false; - continue; - } - // we've now established that the values are the same - String currentFullXPath = dataSource.getFullPath(xpath); - String otherFullXPath = other.dataSource.getFullPath(otherXpath); - if (!equalsIgnoringDraft(currentFullXPath, otherFullXPath)) { - logicDuplicate = false; - continue; - } - if (DEBUG) { - keepIfMatches.getRetention(xpath); - } - break; - case REMOVE: - if (DEBUG) { - keepIfMatches.getRetention(xpath); - } - break; + // we've now established that the values are the same + String currentFullXPath = dataSource.getFullPath(xpath); + String otherFullXPath = other.dataSource.getFullPath(otherXpath); + if (!equalsIgnoringDraft(currentFullXPath, otherFullXPath)) { + logicDuplicate = false; + continue; + } + if (DEBUG) { + keepIfMatches.getRetention(xpath); + } + break; + case REMOVE: + if (DEBUG) { + keepIfMatches.getRetention(xpath); + } + break; } - } if (first) { @@ -984,7 +1067,8 @@ public XPathParts.Comments getXpath_comments() { } /** - * @return Returns the locale ID. In the case of a supplemental data file, it is SUPPLEMENTAL_NAME. + * @return Returns the locale ID. In the case of a supplemental data file, it is + * SUPPLEMENTAL_NAME. */ @Override public String getLocaleID() { @@ -996,7 +1080,7 @@ public String getLocaleID() { */ public String getLocaleIDFromIdentity() { ULocale.Builder lb = new ULocale.Builder(); - for (Iterator i = iterator("//ldml/identity/"); i.hasNext();) { + for (Iterator i = iterator("//ldml/identity/"); i.hasNext(); ) { XPathParts xpp = XPathParts.getFrozenInstance(i.next()); String k = xpp.getElement(-1); String v = xpp.getAttributeValue(-1, "type"); @@ -1037,29 +1121,27 @@ public CLDRFile clearComments() { return this; } - /** - * Sets a final comment, replacing everything that was there. - */ + /** Sets a final comment, replacing everything that was there. */ public CLDRFile setFinalComment(String comment) { if (locked) throw new UnsupportedOperationException("Attempt to modify locked object"); dataSource.getXpathComments().setFinalComment(comment); return this; } - /** - * Adds a comment to the final list of comments. - */ + /** Adds a comment to the final list of comments. */ public CLDRFile appendFinalComment(String comment) { if (locked) throw new UnsupportedOperationException("Attempt to modify locked object"); - dataSource.getXpathComments().setFinalComment( - CldrUtility - .joinWithSeparation(dataSource.getXpathComments().getFinalComment(), XPathParts.NEWLINE, comment)); + dataSource + .getXpathComments() + .setFinalComment( + CldrUtility.joinWithSeparation( + dataSource.getXpathComments().getFinalComment(), + XPathParts.NEWLINE, + comment)); return this; } - /** - * Sets the initial comment, replacing everything that was there. - */ + /** Sets the initial comment, replacing everything that was there. */ public CLDRFile setInitialComment(String comment) { if (locked) throw new UnsupportedOperationException("Attempt to modify locked object"); dataSource.getXpathComments().setInitialComment(comment); @@ -1069,8 +1151,8 @@ public CLDRFile setInitialComment(String comment) { // ========== STATIC UTILITIES ========== /** - * Utility to restrict to files matching a given regular expression. The expression does not contain ".xml". - * Note that supplementalData is always skipped, and root is always included. + * Utility to restrict to files matching a given regular expression. The expression does not + * contain ".xml". Note that supplementalData is always skipped, and root is always included. */ public static Set getMatchingXMLFiles(File sourceDirs[], Matcher m) { Set s = new TreeSet<>(); @@ -1080,7 +1162,8 @@ public static Set getMatchingXMLFiles(File sourceDirs[], Matcher m) { throw new IllegalArgumentException("Directory doesn't exist:\t" + dir.getPath()); } if (!dir.isDirectory()) { - throw new IllegalArgumentException("Input isn't a file directory:\t" + dir.getPath()); + throw new IllegalArgumentException( + "Input isn't a file directory:\t" + dir.getPath()); } File[] files = dir.listFiles(); for (int i = 0; i < files.length; ++i) { @@ -1109,9 +1192,10 @@ public Iterator iterator(Matcher pathFilter) { } public Iterator iterator(String prefix, Comparator comparator) { - Iterator it = (prefix == null || prefix.length() == 0) - ? dataSource.iterator() - : dataSource.iterator(prefix); + Iterator it = + (prefix == null || prefix.length() == 0) + ? dataSource.iterator() + : dataSource.iterator(prefix); if (comparator == null) return it; Set orderedSet = new TreeSet<>(comparator); it.forEachRemaining(orderedSet::add); @@ -1183,7 +1267,9 @@ public static String getNondraftNonaltXPath(String xpath) { return xpath; } synchronized (syncObject) { - XPathParts parts = XPathParts.getFrozenInstance(xpath).cloneAsThawed(); // can't be frozen since we call removeAttributes + XPathParts parts = + XPathParts.getFrozenInstance(xpath) + .cloneAsThawed(); // can't be frozen since we call removeAttributes String restore; HashSet toRemove = new HashSet<>(); for (int i = 0; i < parts.size(); ++i) { @@ -1193,7 +1279,7 @@ public static String getNondraftNonaltXPath(String xpath) { Map attributes = parts.getAttributes(i); toRemove.clear(); restore = null; - for (Iterator it = attributes.keySet().iterator(); it.hasNext();) { + for (Iterator it = attributes.keySet().iterator(); it.hasNext(); ) { String attribute = it.next(); if (attribute.equals("draft")) { toRemove.add(attribute); @@ -1203,7 +1289,9 @@ public static String getNondraftNonaltXPath(String xpath) { if (proposedPos >= 0) { toRemove.add(attribute); if (proposedPos > 0) { - restore = value.substring(0, proposedPos - 1); // is of form xxx-proposedyyy + restore = + value.substring( + 0, proposedPos - 1); // is of form xxx-proposedyyy } } } @@ -1228,9 +1316,7 @@ public static boolean isDistinguishing(DtdType type, String elementName, String return DtdData.getInstance(type).isDistinguishing(elementName, attribute); } - /** - * Utility to create a validating XML reader. - */ + /** Utility to create a validating XML reader. */ public static XMLReader createXMLReader(boolean validating) { String[] testList = { "org.apache.xerces.parsers.SAXParser", @@ -1243,29 +1329,31 @@ public static XMLReader createXMLReader(boolean validating) { XMLReader result = null; for (int i = 0; i < testList.length; ++i) { try { - result = (testList[i].length() != 0) - ? XMLReaderFactory.createXMLReader(testList[i]) - : XMLReaderFactory.createXMLReader(); + result = + (testList[i].length() != 0) + ? XMLReaderFactory.createXMLReader(testList[i]) + : XMLReaderFactory.createXMLReader(); result.setFeature("http://xml.org/sax/features/validation", validating); break; } catch (SAXException e1) { } } if (result == null) - throw new NoClassDefFoundError("No SAX parser is available, or unable to set validation correctly"); + throw new NoClassDefFoundError( + "No SAX parser is available, or unable to set validation correctly"); return result; } /** - * Return a directory to supplemental data used by this CLDRFile. - * If the CLDRFile is not normally disk-based, the returned directory may be temporary - * and not guaranteed to exist past the lifetime of the CLDRFile. The directory - * should be considered read-only. + * Return a directory to supplemental data used by this CLDRFile. If the CLDRFile is not + * normally disk-based, the returned directory may be temporary and not guaranteed to exist past + * the lifetime of the CLDRFile. The directory should be considered read-only. */ public File getSupplementalDirectory() { if (supplementalDirectory == null) { // ask CLDRConfig. - supplementalDirectory = CLDRConfig.getInstance().getSupplementalDataInfo().getDirectory(); + supplementalDirectory = + CLDRConfig.getInstance().getSupplementalDataInfo().getDirectory(); } return supplementalDirectory; } @@ -1282,19 +1370,21 @@ public CLDRFile setSupplementalDirectory(File supplementalDirectory) { * @see #getSupplementalDirectory() */ public File[] getSupplementalXMLFiles() { - return getSupplementalDirectory().listFiles(new FilenameFilter() { - @Override - public boolean accept(@SuppressWarnings("unused") File dir, String name) { - return name.endsWith(".xml"); - } - }); + return getSupplementalDirectory() + .listFiles( + new FilenameFilter() { + @Override + public boolean accept( + @SuppressWarnings("unused") File dir, String name) { + return name.endsWith(".xml"); + } + }); } /** * Convenience function to return a specific supplemental file * - * @param filename - * the file to return + * @param filename the file to return * @return the file (may not exist) * @see #getSupplementalDirectory() */ @@ -1308,19 +1398,23 @@ public static boolean isSupplementalName(String localeName) { // static String[] keys = {"calendar", "collation", "currency"}; // - // static String[] calendar_keys = {"buddhist", "chinese", "gregorian", "hebrew", "islamic", "islamic-civil", + // static String[] calendar_keys = {"buddhist", "chinese", "gregorian", "hebrew", "islamic", + // "islamic-civil", // "japanese"}; - // static String[] collation_keys = {"phonebook", "traditional", "direct", "pinyin", "stroke", "posix", "big5han", + // static String[] collation_keys = {"phonebook", "traditional", "direct", "pinyin", "stroke", + // "posix", "big5han", // "gb2312han"}; - /* *//** - * Value that contains a node. WARNING: this is not done yet, and may change. - * In particular, we don't want to return a Node, since that is mutable, and makes caching unsafe!! + /* */ + /** + * Value that contains a node. WARNING: this is not done yet, and may change. In particular, we + * don't want to return a Node, since that is mutable, and makes caching unsafe!! */ /* * static public class NodeValue extends Value { * private Node nodeValue; - *//** + */ + /** * Creation. WARNING, may change. * * @param value @@ -1331,18 +1425,16 @@ public static boolean isSupplementalName(String localeName) { * super(currentFullXPath); * this.nodeValue = value; * } - *//** - * boilerplate */ + /** boilerplate */ /* * public boolean hasSameValue(Object other) { * if (super.hasSameValue(other)) return false; * return nodeValue.equals(((NodeValue)other).nodeValue); * } - *//** - * boilerplate */ + /** boilerplate */ /* * public String getStringValue() { * return nodeValue.toString(); @@ -1373,8 +1465,10 @@ private static class MyDeclHandler implements AllHandler { private String lastActiveLeafNode; private String lastLeafNode; private int isSupplemental = -1; - private int[] orderedCounter = new int[30]; // just make deep enough to handle any CLDR file. - private String[] orderedString = new String[30]; // just make deep enough to handle any CLDR file. + private int[] orderedCounter = + new int[30]; // just make deep enough to handle any CLDR file. + private String[] orderedString = + new String[30]; // just make deep enough to handle any CLDR file. private int level = 0; private int overrideCount = 0; private Locator documentLocator = null; @@ -1404,11 +1498,15 @@ private void push(String qName, Attributes attributes) { orderedString[level] = qName; } if (lastChars.length() != 0) { - if (whitespace.containsAll(lastChars)) - lastChars = ""; + if (whitespace.containsAll(lastChars)) lastChars = ""; else - throw new IllegalArgumentException("Must not have mixed content: " + qName + ", " - + show(attributes) + ", Content: " + lastChars); + throw new IllegalArgumentException( + "Must not have mixed content: " + + qName + + ", " + + show(attributes) + + ", Content: " + + lastChars); } // currentXPath += "/" + qName; currentFullXPath += "/" + qName; @@ -1422,24 +1520,27 @@ private void push(String qName, Attributes attributes) { String attribute = attributes.getQName(i); String value = attributes.getValue(i); - // if (!isSupplemental) ldmlComparator.addAttribute(attribute); // must do BEFORE put + // if (!isSupplemental) ldmlComparator.addAttribute(attribute); // must do + // BEFORE put // ldmlComparator.addValue(value); // special fix to remove version // // - if (attribute.equals("cldrVersion") - && (qName.equals("version"))) { - ((SimpleXMLSource) target.dataSource).setDtdVersionInfo(VersionInfo.getInstance(value)); + if (attribute.equals("cldrVersion") && (qName.equals("version"))) { + ((SimpleXMLSource) target.dataSource) + .setDtdVersionInfo(VersionInfo.getInstance(value)); } else { putAndFixDeprecatedAttribute(qName, attribute, value); } } - for (Iterator it = attributeOrder.keySet().iterator(); it.hasNext();) { + for (Iterator it = attributeOrder.keySet().iterator(); it.hasNext(); ) { String attribute = it.next(); String value = attributeOrder.get(attribute); - String both = "[@" + attribute + "=\"" + value + "\"]"; // TODO quote the value?? + String both = + "[@" + attribute + "=\"" + value + "\"]"; // TODO quote the value?? currentFullXPath += both; - // distinguishing = key, registry, alt, and type (except for the type attribute on the elements + // distinguishing = key, registry, alt, and type (except for the type attribute + // on the elements // default and mapping). // if (isDistinguishing(qName, attribute)) { // currentXPath += both; @@ -1447,10 +1548,12 @@ private void push(String qName, Attributes attributes) { } } if (comment != null) { - if (currentFullXPath.equals("//ldml") || currentFullXPath.equals("//supplementalData")) { + if (currentFullXPath.equals("//ldml") + || currentFullXPath.equals("//supplementalData")) { target.setInitialComment(comment); } else { - target.addComment(currentFullXPath, comment, XPathParts.Comments.CommentType.PREBLOCK); + target.addComment( + currentFullXPath, comment, XPathParts.Comments.CommentType.PREBLOCK); } comment = null; } @@ -1465,11 +1568,11 @@ private String orderingAttribute() { private void putAndFixDeprecatedAttribute(String element, String attribute, String value) { if (attribute.equals("draft")) { - if (value.equals("true")) - value = "approved"; + if (value.equals("true")) value = "approved"; else if (value.equals("false")) value = "unconfirmed"; } else if (attribute.equals("type")) { - if (changedTypes.contains(element) && isSupplemental < 1) { // measurementSystem for example did not + if (changedTypes.contains(element) + && isSupplemental < 1) { // measurementSystem for example did not // change from 'type' to 'choice'. attribute = "choice"; } @@ -1489,16 +1592,22 @@ private void putAndFixDeprecatedAttribute(String element, String attribute, Stri attributeOrder.put(attribute, value); } - //private Set fixedSkeletons = new HashSet(); + // private Set fixedSkeletons = new HashSet(); - //private DateTimePatternGenerator dateGenerator = DateTimePatternGenerator.getEmptyInstance(); + // private DateTimePatternGenerator dateGenerator = + // DateTimePatternGenerator.getEmptyInstance(); - /** - * Types which changed from 'type' to 'choice', but not in supplemental data. - */ - private static Set changedTypes = new HashSet<>(Arrays.asList(new String[] { - "abbreviationFallback", - "default", "mapping", "measurementSystem", "preferenceOrdering" })); + /** Types which changed from 'type' to 'choice', but not in supplemental data. */ + private static Set changedTypes = + new HashSet<>( + Arrays.asList( + new String[] { + "abbreviationFallback", + "default", + "mapping", + "measurementSystem", + "preferenceOrdering" + })); Matcher draftMatcher = DRAFT_PATTERN.matcher(""); @@ -1513,14 +1622,15 @@ private void addPath(String fullXPath, String value) { if (former != null) { String formerPath = target.getFullXPath(fullXPath); if (!former.equals(value) || !fullXPath.equals(formerPath)) { - if (!fullXPath.startsWith("//ldml/identity/version") && !fullXPath.startsWith("//ldml/identity/generation")) { + if (!fullXPath.startsWith("//ldml/identity/version") + && !fullXPath.startsWith("//ldml/identity/generation")) { warnOnOverride(former, formerPath); } } } value = trimWhitespaceSpecial(value); target.add(fullXPath, value) - .addSourceLocation(fullXPath, new XMLSource.SourceLocation(documentLocator)); + .addSourceLocation(fullXPath, new XMLSource.SourceLocation(documentLocator)); } private void pop(String qName) { @@ -1537,7 +1647,9 @@ private void pop(String qName) { acceptItem = true; } } else { - acceptItem = true; // if not found, then the draft status is approved, so it is always ok + acceptItem = + true; // if not found, then the draft status is approved, so it is + // always ok } } if (acceptItem) { @@ -1564,11 +1676,13 @@ private void pop(String qName) { } lastChars = ""; } else { - Log.logln(LOG_PROGRESS && lastActiveLeafNode != null, "pop: zeroing last leafNode: " - + lastActiveLeafNode); + Log.logln( + LOG_PROGRESS && lastActiveLeafNode != null, + "pop: zeroing last leafNode: " + lastActiveLeafNode); lastActiveLeafNode = null; if (comment != null) { - target.addComment(lastLeafNode, comment, XPathParts.Comments.CommentType.POSTBLOCK); + target.addComment( + lastLeafNode, comment, XPathParts.Comments.CommentType.POSTBLOCK); comment = null; } } @@ -1600,11 +1714,22 @@ private String trimWhitespaceSpecial(String source) { private void warnOnOverride(String former, String formerPath) { String distinguishing = CLDRFile.getDistinguishingXPath(formerPath, null); - System.out.println("\tERROR in " + target.getLocaleID() - + ";\toverriding old value <" + former + "> at path " + distinguishing + - "\twith\t<" + lastChars + ">" + - CldrUtility.LINE_SEPARATOR + "\told fullpath: " + formerPath + - CldrUtility.LINE_SEPARATOR + "\tnew fullpath: " + currentFullXPath); + System.out.println( + "\tERROR in " + + target.getLocaleID() + + ";\toverriding old value <" + + former + + "> at path " + + distinguishing + + "\twith\t<" + + lastChars + + ">" + + CldrUtility.LINE_SEPARATOR + + "\told fullpath: " + + formerPath + + CldrUtility.LINE_SEPARATOR + + "\tnew fullpath: " + + currentFullXPath); overrideCount += 1; } @@ -1625,29 +1750,29 @@ private static int findLastSlash(String input) { for (int i = input.length() - 1; i >= 0; --i) { char ch = input.charAt(i); switch (ch) { - case '\'': - case '"': - if (inQuote == 0) { - inQuote = ch; - } else if (inQuote == ch) { - inQuote = 0; // come out of quote - } - break; - case '/': - if (inQuote == 0 && braceStack == 0) { - return i; - } - break; - case '[': - if (inQuote == 0) { - --braceStack; - } - break; - case ']': - if (inQuote == 0) { - ++braceStack; - } - break; + case '\'': + case '"': + if (inQuote == 0) { + inQuote = ch; + } else if (inQuote == ch) { + inQuote = 0; // come out of quote + } + break; + case '/': + if (inQuote == 0 && braceStack == 0) { + return i; + } + break; + case '[': + if (inQuote == 0) { + --braceStack; + } + break; + case ']': + if (inQuote == 0) { + ++braceStack; + } + break; } } return -1; @@ -1656,23 +1781,26 @@ private static int findLastSlash(String input) { // SAX items we need to catch @Override - public void startElement( - String uri, - String localName, - String qName, - Attributes attributes) + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { - Log.logln(LOG_PROGRESS || SHOW_START_END, "startElement uri\t" + uri - + "\tlocalName " + localName - + "\tqName " + qName - + "\tattributes " + show(attributes)); + Log.logln( + LOG_PROGRESS || SHOW_START_END, + "startElement uri\t" + + uri + + "\tlocalName " + + localName + + "\tqName " + + qName + + "\tattributes " + + show(attributes)); try { if (isSupplemental < 0) { // set by first element - attributeOrder = new TreeMap<>( - // HACK for ldmlIcu - dtdData.dtdType == DtdType.ldml - ? CLDRFile.getAttributeOrdering() - : dtdData.getAttributeComparator()); + attributeOrder = + new TreeMap<>( + // HACK for ldmlIcu + dtdData.dtdType == DtdType.ldml + ? CLDRFile.getAttributeOrdering() + : dtdData.getAttributeComparator()); isSupplemental = target.dtdType == DtdType.ldml ? 0 : 1; } push(qName, attributes); @@ -1683,10 +1811,10 @@ public void startElement( } @Override - public void endElement(String uri, String localName, String qName) - throws SAXException { - Log.logln(LOG_PROGRESS || SHOW_START_END, "endElement uri\t" + uri + "\tlocalName " + localName - + "\tqName " + qName); + public void endElement(String uri, String localName, String qName) throws SAXException { + Log.logln( + LOG_PROGRESS || SHOW_START_END, + "endElement uri\t" + uri + "\tlocalName " + localName + "\tqName " + qName); try { pop(qName); } catch (RuntimeException e) { @@ -1695,12 +1823,11 @@ public void endElement(String uri, String localName, String qName) } } - //static final char XML_LINESEPARATOR = (char) 0xA; - //static final String XML_LINESEPARATOR_STRING = String.valueOf(XML_LINESEPARATOR); + // static final char XML_LINESEPARATOR = (char) 0xA; + // static final String XML_LINESEPARATOR_STRING = String.valueOf(XML_LINESEPARATOR); @Override - public void characters(char[] ch, int start, int length) - throws SAXException { + public void characters(char[] ch, int start, int length) throws SAXException { try { String value = new String(ch, start, length); Log.logln(LOG_PROGRESS, "characters:\t" + value); @@ -1718,9 +1845,14 @@ public void characters(char[] ch, int start, int length) @Override public void startDTD(String name, String publicId, String systemId) throws SAXException { - Log.logln(LOG_PROGRESS, "startDTD name: " + name - + ", publicId: " + publicId - + ", systemId: " + systemId); + Log.logln( + LOG_PROGRESS, + "startDTD name: " + + name + + ", publicId: " + + publicId + + ", systemId: " + + systemId); commentStack++; target.dtdType = DtdType.valueOf(name); target.dtdData = dtdData = DtdData.getInstance(target.dtdType); @@ -1740,9 +1872,11 @@ public void comment(char[] ch, int start, int length) throws SAXException { if (commentStack != 0) return; String comment0 = trimWhitespaceSpecial(string).trim(); if (lastActiveLeafNode != null) { - target.addComment(lastActiveLeafNode, comment0, XPathParts.Comments.CommentType.LINE); + target.addComment( + lastActiveLeafNode, comment0, XPathParts.Comments.CommentType.LINE); } else { - comment = (comment == null ? comment0 : comment + XPathParts.NEWLINE + comment0); + comment = + (comment == null ? comment0 : comment + XPathParts.NEWLINE + comment0); } } catch (RuntimeException e) { e.printStackTrace(); @@ -1753,13 +1887,18 @@ public void comment(char[] ch, int start, int length) throws SAXException { @Override public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { if (LOG_PROGRESS) - Log.logln(LOG_PROGRESS, - "ignorableWhitespace length: " + length + ": " + Utility.hex(new String(ch, start, length))); + Log.logln( + LOG_PROGRESS, + "ignorableWhitespace length: " + + length + + ": " + + Utility.hex(new String(ch, start, length))); // if (lastActiveLeafNode != null) { for (int i = start; i < start + length; ++i) { if (ch[i] == '\n') { - Log.logln(LOG_PROGRESS && lastActiveLeafNode != null, "\\n: zeroing last leafNode: " - + lastActiveLeafNode); + Log.logln( + LOG_PROGRESS && lastActiveLeafNode != null, + "\\n: zeroing last leafNode: " + lastActiveLeafNode); lastActiveLeafNode = null; break; } @@ -1777,7 +1916,8 @@ public void startDocument() throws SAXException { public void endDocument() throws SAXException { Log.logln(LOG_PROGRESS, "endDocument"); try { - if (comment != null) target.addComment(null, comment, XPathParts.Comments.CommentType.LINE); + if (comment != null) + target.addComment(null, comment, XPathParts.Comments.CommentType.LINE); } catch (RuntimeException e) { e.printStackTrace(); throw e; @@ -1792,9 +1932,21 @@ public void elementDecl(String name, String model) throws SAXException { } @Override - public void attributeDecl(String eName, String aName, String type, String mode, String value) - throws SAXException { - Log.logln(LOG_PROGRESS, "Attribute\t" + eName + "\t" + aName + "\t" + type + "\t" + mode + "\t" + value); + public void attributeDecl( + String eName, String aName, String type, String mode, String value) + throws SAXException { + Log.logln( + LOG_PROGRESS, + "Attribute\t" + + eName + + "\t" + + aName + + "\t" + + type + + "\t" + + mode + + "\t" + + value); } @Override @@ -1803,19 +1955,18 @@ public void internalEntityDecl(String name, String value) throws SAXException { } @Override - public void externalEntityDecl(String name, String publicId, String systemId) throws SAXException { + public void externalEntityDecl(String name, String publicId, String systemId) + throws SAXException { Log.logln(LOG_PROGRESS, "Internal Entity\t" + name + "\t" + publicId + "\t" + systemId); } @Override - public void processingInstruction(String target, String data) - throws SAXException { + public void processingInstruction(String target, String data) throws SAXException { Log.logln(LOG_PROGRESS, "processingInstruction: " + target + ", " + data); } @Override - public void skippedEntity(String name) - throws SAXException { + public void skippedEntity(String name) throws SAXException { Log.logln(LOG_PROGRESS, "skippedEntity: " + name); } @@ -1827,8 +1978,7 @@ public void setDocumentLocator(Locator locator) { @Override public void startPrefixMapping(String prefix, String uri) throws SAXException { - Log.logln(LOG_PROGRESS, "startPrefixMapping prefix: " + prefix + - ", uri: " + uri); + Log.logln(LOG_PROGRESS, "startPrefixMapping prefix: " + prefix + ", uri: " + uri); } @Override @@ -1890,20 +2040,20 @@ public void warning(SAXParseException exception) throws SAXException { } } - /** - * Show a SAX exception in a readable form. - */ + /** Show a SAX exception in a readable form. */ public static String showSAX(SAXParseException exception) { return exception.getMessage() - + ";\t SystemID: " + exception.getSystemId() - + ";\t PublicID: " + exception.getPublicId() - + ";\t LineNumber: " + exception.getLineNumber() - + ";\t ColumnNumber: " + exception.getColumnNumber(); + + ";\t SystemID: " + + exception.getSystemId() + + ";\t PublicID: " + + exception.getPublicId() + + ";\t LineNumber: " + + exception.getLineNumber() + + ";\t ColumnNumber: " + + exception.getColumnNumber(); } - /** - * Says whether the whole file is draft - */ + /** Says whether the whole file is draft */ public boolean isDraft() { String item = iterator().next(); return item.startsWith("//ldml[@draft=\"unconfirmed\"]"); @@ -1925,8 +2075,7 @@ public boolean isDraft() { // } /** - * Gets the type of a given xpath, eg script, territory, ... - * TODO move to separate class + * Gets the type of a given xpath, eg script, territory, ... TODO move to separate class * * @param xpath * @return @@ -1939,9 +2088,7 @@ public static int getNameType(String xpath) { return -1; } - /** - * Gets the display name for a type - */ + /** Gets the display name for a type */ public static String getNameTypeName(int index) { try { return getNameName(index); @@ -1950,52 +2097,54 @@ public static String getNameTypeName(int index) { } } - public static final int NO_NAME = -1, LANGUAGE_NAME = 0, SCRIPT_NAME = 1, TERRITORY_NAME = 2, VARIANT_NAME = 3, - CURRENCY_NAME = 4, CURRENCY_SYMBOL = 5, - TZ_EXEMPLAR = 6, TZ_START = TZ_EXEMPLAR, - TZ_GENERIC_LONG = 7, TZ_GENERIC_SHORT = 8, - TZ_STANDARD_LONG = 9, TZ_STANDARD_SHORT = 10, - TZ_DAYLIGHT_LONG = 11, TZ_DAYLIGHT_SHORT = 12, - TZ_LIMIT = 13, - KEY_NAME = 13, - KEY_TYPE_NAME = 14, - SUBDIVISION_NAME = 15, - LIMIT_TYPES = 15; + public static final int NO_NAME = -1, + LANGUAGE_NAME = 0, + SCRIPT_NAME = 1, + TERRITORY_NAME = 2, + VARIANT_NAME = 3, + CURRENCY_NAME = 4, + CURRENCY_SYMBOL = 5, + TZ_EXEMPLAR = 6, + TZ_START = TZ_EXEMPLAR, + TZ_GENERIC_LONG = 7, + TZ_GENERIC_SHORT = 8, + TZ_STANDARD_LONG = 9, + TZ_STANDARD_SHORT = 10, + TZ_DAYLIGHT_LONG = 11, + TZ_DAYLIGHT_SHORT = 12, + TZ_LIMIT = 13, + KEY_NAME = 13, + KEY_TYPE_NAME = 14, + SUBDIVISION_NAME = 15, + LIMIT_TYPES = 15; private static final String[][] NameTable = { - { "//ldml/localeDisplayNames/languages/language[@type=\"", "\"]", "language" }, - { "//ldml/localeDisplayNames/scripts/script[@type=\"", "\"]", "script" }, - { "//ldml/localeDisplayNames/territories/territory[@type=\"", "\"]", "territory" }, - { "//ldml/localeDisplayNames/variants/variant[@type=\"", "\"]", "variant" }, - { "//ldml/numbers/currencies/currency[@type=\"", "\"]/displayName", "currency" }, - { "//ldml/numbers/currencies/currency[@type=\"", "\"]/symbol", "currency-symbol" }, - { "//ldml/dates/timeZoneNames/zone[@type=\"", "\"]/exemplarCity", "exemplar-city" }, - { "//ldml/dates/timeZoneNames/zone[@type=\"", "\"]/long/generic", "tz-generic-long" }, - { "//ldml/dates/timeZoneNames/zone[@type=\"", "\"]/short/generic", "tz-generic-short" }, - { "//ldml/dates/timeZoneNames/zone[@type=\"", "\"]/long/standard", "tz-standard-long" }, - { "//ldml/dates/timeZoneNames/zone[@type=\"", "\"]/short/standard", "tz-standard-short" }, - { "//ldml/dates/timeZoneNames/zone[@type=\"", "\"]/long/daylight", "tz-daylight-long" }, - { "//ldml/dates/timeZoneNames/zone[@type=\"", "\"]/short/daylight", "tz-daylight-short" }, - { "//ldml/localeDisplayNames/keys/key[@type=\"", "\"]", "key" }, - { "//ldml/localeDisplayNames/types/type[@key=\"", "\"][@type=\"", "\"]", "key|type" }, - { "//ldml/localeDisplayNames/subdivisions/subdivision[@type=\"", "\"]", "subdivision" }, + {"//ldml/localeDisplayNames/languages/language[@type=\"", "\"]", "language"}, + {"//ldml/localeDisplayNames/scripts/script[@type=\"", "\"]", "script"}, + {"//ldml/localeDisplayNames/territories/territory[@type=\"", "\"]", "territory"}, + {"//ldml/localeDisplayNames/variants/variant[@type=\"", "\"]", "variant"}, + {"//ldml/numbers/currencies/currency[@type=\"", "\"]/displayName", "currency"}, + {"//ldml/numbers/currencies/currency[@type=\"", "\"]/symbol", "currency-symbol"}, + {"//ldml/dates/timeZoneNames/zone[@type=\"", "\"]/exemplarCity", "exemplar-city"}, + {"//ldml/dates/timeZoneNames/zone[@type=\"", "\"]/long/generic", "tz-generic-long"}, + {"//ldml/dates/timeZoneNames/zone[@type=\"", "\"]/short/generic", "tz-generic-short"}, + {"//ldml/dates/timeZoneNames/zone[@type=\"", "\"]/long/standard", "tz-standard-long"}, + {"//ldml/dates/timeZoneNames/zone[@type=\"", "\"]/short/standard", "tz-standard-short"}, + {"//ldml/dates/timeZoneNames/zone[@type=\"", "\"]/long/daylight", "tz-daylight-long"}, + {"//ldml/dates/timeZoneNames/zone[@type=\"", "\"]/short/daylight", "tz-daylight-short"}, + {"//ldml/localeDisplayNames/keys/key[@type=\"", "\"]", "key"}, + {"//ldml/localeDisplayNames/types/type[@key=\"", "\"][@type=\"", "\"]", "key|type"}, + {"//ldml/localeDisplayNames/subdivisions/subdivision[@type=\"", "\"]", "subdivision"}, /** - * - * Newfoundland Time - * Newfoundland Standard Time - * Newfoundland Daylight Time - * - * - - * - * NT - * NST - * NDT - * + * Newfoundland Time Newfoundland Standard + * Time Newfoundland Daylight Time - + * NT NST NDT */ }; - // private static final String[] TYPE_NAME = {"language", "script", "territory", "variant", "currency", + // private static final String[] TYPE_NAME = {"language", "script", "territory", "variant", + // "currency", // "currency-symbol", // "tz-exemplar", // "tz-generic-long", "tz-generic-short"}; @@ -2009,32 +2158,37 @@ public Iterator getAvailableIterator(int type) { */ public static String getKey(int type, String code) { switch (type) { - case VARIANT_NAME: - code = code.toUpperCase(Locale.ROOT); - break; - case KEY_NAME: - code = fixKeyName(code); - break; - case TZ_DAYLIGHT_LONG: - case TZ_DAYLIGHT_SHORT: - case TZ_EXEMPLAR: - case TZ_GENERIC_LONG: - case TZ_GENERIC_SHORT: - case TZ_STANDARD_LONG: - case TZ_STANDARD_SHORT: - code = getLongTzid(code); - break; + case VARIANT_NAME: + code = code.toUpperCase(Locale.ROOT); + break; + case KEY_NAME: + code = fixKeyName(code); + break; + case TZ_DAYLIGHT_LONG: + case TZ_DAYLIGHT_SHORT: + case TZ_EXEMPLAR: + case TZ_GENERIC_LONG: + case TZ_GENERIC_SHORT: + case TZ_STANDARD_LONG: + case TZ_STANDARD_SHORT: + code = getLongTzid(code); + break; } String[] nameTableRow = NameTable[type]; if (code.contains("|")) { String[] codes = code.split("\\|"); - return nameTableRow[0] + fixKeyName(codes[0]) + nameTableRow[1] + codes[1] + nameTableRow[2]; + return nameTableRow[0] + + fixKeyName(codes[0]) + + nameTableRow[1] + + codes[1] + + nameTableRow[2]; } else { return nameTableRow[0] + code + nameTableRow[1]; } } - static final Relation, String> bcp47AliasMap = CLDRConfig.getInstance().getSupplementalDataInfo().getBcp47Aliases(); + static final Relation, String> bcp47AliasMap = + CLDRConfig.getInstance().getSupplementalDataInfo().getBcp47Aliases(); public static String getLongTzid(String code) { if (!code.contains("/")) { @@ -2047,10 +2201,19 @@ public static String getLongTzid(String code) { } static final ImmutableMap FIX_KEY_NAME; + static { Builder temp = ImmutableMap.builder(); - for (String s : Arrays.asList("colAlternate", "colBackwards", "colCaseFirst", "colCaseLevel", "colNormalization", "colNumeric", "colReorder", - "colStrength")) { + for (String s : + Arrays.asList( + "colAlternate", + "colBackwards", + "colCaseFirst", + "colCaseLevel", + "colNormalization", + "colNumeric", + "colReorder", + "colStrength")) { temp.put(s.toLowerCase(Locale.ROOT), s); } FIX_KEY_NAME = temp.build(); @@ -2091,19 +2254,16 @@ public static int typeNameToCode(String type) { return -1; } - /** - * For use in getting short names. - */ - public static final Transform SHORT_ALTS = new Transform<>() { - @Override - public String transform(@SuppressWarnings("unused") String source) { - return "short"; - } - }; + /** For use in getting short names. */ + public static final Transform SHORT_ALTS = + new Transform<>() { + @Override + public String transform(@SuppressWarnings("unused") String source) { + return "short"; + } + }; - /** - * Returns the name of a type. - */ + /** Returns the name of a type. */ public static String getNameName(int choice) { String[] nameTableRow = NameTable[choice]; return nameTableRow[nameTableRow.length - 1]; @@ -2133,27 +2293,29 @@ public static boolean isOrdered(String element, DtdType type) { return DtdData.getInstance(type).isOrdered(element); } - private static Comparator ldmlComparator = DtdData.getInstance(DtdType.ldmlICU).getDtdComparator(null); + private static Comparator ldmlComparator = + DtdData.getInstance(DtdType.ldmlICU).getDtdComparator(null); + + private static final Map> defaultSuppressionMap; - private final static Map> defaultSuppressionMap; static { String[][] data = { - { "ldml", "version", GEN_VERSION }, - { "version", "cldrVersion", "*" }, - { "orientation", "characters", "left-to-right" }, - { "orientation", "lines", "top-to-bottom" }, - { "weekendStart", "time", "00:00" }, - { "weekendEnd", "time", "24:00" }, - { "dateFormat", "type", "standard" }, - { "timeFormat", "type", "standard" }, - { "dateTimeFormat", "type", "standard" }, - { "decimalFormat", "type", "standard" }, - { "scientificFormat", "type", "standard" }, - { "percentFormat", "type", "standard" }, - { "pattern", "type", "standard" }, - { "currency", "type", "standard" }, - { "transform", "visibility", "external" }, - { "*", "_q", "*" }, + {"ldml", "version", GEN_VERSION}, + {"version", "cldrVersion", "*"}, + {"orientation", "characters", "left-to-right"}, + {"orientation", "lines", "top-to-bottom"}, + {"weekendStart", "time", "00:00"}, + {"weekendEnd", "time", "24:00"}, + {"dateFormat", "type", "standard"}, + {"timeFormat", "type", "standard"}, + {"dateTimeFormat", "type", "standard"}, + {"decimalFormat", "type", "standard"}, + {"scientificFormat", "type", "standard"}, + {"percentFormat", "type", "standard"}, + {"pattern", "type", "standard"}, + {"currency", "type", "standard"}, + {"transform", "visibility", "external"}, + {"*", "_q", "*"}, }; Map> tempmain = asMap(data, true); defaultSuppressionMap = Collections.unmodifiableMap(tempmain); @@ -2163,7 +2325,7 @@ public static Map> getDefaultSuppressionMap() { return defaultSuppressionMap; } - @SuppressWarnings({ "rawtypes", "unchecked" }) + @SuppressWarnings({"rawtypes", "unchecked"}) private static Map asMap(String[][] data, boolean tree) { Map tempmain = tree ? (Map) new TreeMap() : new HashMap(); int len = data[0].length; // must be same for all elements @@ -2184,9 +2346,7 @@ private static Map asMap(String[][] data, boolean tree) { return tempmain; } - /** - * Removes a comment. - */ + /** Removes a comment. */ public CLDRFile removeComment(String string) { if (locked) throw new UnsupportedOperationException("Attempt to modify locked object"); dataSource.getXpathComments().removeComment(string); @@ -2194,15 +2354,15 @@ public CLDRFile removeComment(String string) { } /** - * @param draftStatus - * TODO - * + * @param draftStatus TODO */ public CLDRFile makeDraft(DraftStatus draftStatus) { if (locked) throw new UnsupportedOperationException("Attempt to modify locked object"); - for (Iterator it = dataSource.iterator(); it.hasNext();) { + for (Iterator it = dataSource.iterator(); it.hasNext(); ) { String path = it.next(); - XPathParts parts = XPathParts.getFrozenInstance(dataSource.getFullPath(path)).cloneAsThawed(); // not frozen, for addAttribute + XPathParts parts = + XPathParts.getFrozenInstance(dataSource.getFullPath(path)) + .cloneAsThawed(); // not frozen, for addAttribute parts.addAttribute("draft", draftStatus.toString()); dataSource.putValueAtPath(parts.toString(), dataSource.getValueAtPath(path)); } @@ -2217,12 +2377,17 @@ public UnicodeSet getExemplarSet(ExemplarType type, WinningChoice winningChoice) return getExemplarSet(type, winningChoice, UnicodeSet.CASE); } - static final UnicodeSet HACK_CASE_CLOSURE_SET = new UnicodeSet( - "[ſẛffẞ{i̇}\u1F71\u1F73\u1F75\u1F77\u1F79\u1F7B\u1F7D\u1FBB\u1FBE\u1FC9\u1FCB\u1FD3\u1FDB\u1FE3\u1FEB\u1FF9\u1FFB\u2126\u212A\u212B]") - .freeze(); + static final UnicodeSet HACK_CASE_CLOSURE_SET = + new UnicodeSet( + "[ſẛffẞ{i̇}\u1F71\u1F73\u1F75\u1F77\u1F79\u1F7B\u1F7D\u1FBB\u1FBE\u1FC9\u1FCB\u1FD3\u1FDB\u1FE3\u1FEB\u1FF9\u1FFB\u2126\u212A\u212B]") + .freeze(); public enum ExemplarType { - main, auxiliary, index, punctuation, numbers; + main, + auxiliary, + index, + punctuation, + numbers; public static ExemplarType fromString(String type) { return type.isEmpty() ? main : valueOf(type); @@ -2251,12 +2416,16 @@ public UnicodeSet getExemplarSet(ExemplarType type, WinningChoice winningChoice, } public static String getExemplarPath(ExemplarType type) { - return "//ldml/characters/exemplarCharacters" + (type == ExemplarType.main ? "" : "[@type=\"" + type + "\"]"); + return "//ldml/characters/exemplarCharacters" + + (type == ExemplarType.main ? "" : "[@type=\"" + type + "\"]"); } public enum NumberingSystem { - latin(null), defaultSystem("//ldml/numbers/defaultNumberingSystem"), nativeSystem("//ldml/numbers/otherNumberingSystems/native"), traditional( - "//ldml/numbers/otherNumberingSystems/traditional"), finance("//ldml/numbers/otherNumberingSystems/finance"); + latin(null), + defaultSystem("//ldml/numbers/defaultNumberingSystem"), + nativeSystem("//ldml/numbers/otherNumberingSystems/native"), + traditional("//ldml/numbers/otherNumberingSystems/traditional"), + finance("//ldml/numbers/otherNumberingSystems/finance"); public final String path; private NumberingSystem(String path) { @@ -2276,13 +2445,8 @@ public UnicodeSet getExemplarsNumeric(String numberingSystem) { UnicodeSet result = new UnicodeSet(); SupplementalDataInfo sdi = CLDRConfig.getInstance().getSupplementalDataInfo(); String[] symbolPaths = { - "decimal", - "group", - "percentSign", - "perMille", - "plusSign", - "minusSign", - //"infinity" + "decimal", "group", "percentSign", "perMille", "plusSign", "minusSign", + // "infinity" }; String digits = sdi.getDigits(numberingSystem); @@ -2290,7 +2454,8 @@ public UnicodeSet getExemplarsNumeric(String numberingSystem) { result.addAll(digits); } for (String path : symbolPaths) { - String fullPath = "//ldml/numbers/symbols[@numberSystem=\"" + numberingSystem + "\"]/" + path; + String fullPath = + "//ldml/numbers/symbols[@numberSystem=\"" + numberingSystem + "\"]/" + path; String value = getStringValue(fullPath); if (value != null) { result.add(value); @@ -2301,9 +2466,10 @@ public UnicodeSet getExemplarsNumeric(String numberingSystem) { } public String getCurrentMetazone(String zone) { - for (Iterator it2 = iterator(); it2.hasNext();) { + for (Iterator it2 = iterator(); it2.hasNext(); ) { String xpath = it2.next(); - if (xpath.startsWith("//ldml/dates/timeZoneNames/zone[@type=\"" + zone + "\"]/usesMetazone")) { + if (xpath.startsWith( + "//ldml/dates/timeZoneNames/zone[@type=\"" + zone + "\"]/usesMetazone")) { XPathParts parts = XPathParts.getFrozenInstance(xpath); if (!parts.containsAttribute("to")) { return parts.getAttributeValue(4, "mzone"); @@ -2331,8 +2497,11 @@ public static final String distinguishedXPathStats() { private static class DistinguishedXPath { public static final String stats() { - return "distinguishingMap:" + distinguishingMap.size() + " " + - "normalizedPathMap:" + normalizedPathMap.size(); + return "distinguishingMap:" + + distinguishingMap.size() + + " " + + "normalizedPathMap:" + + normalizedPathMap.size(); } private static Map distinguishingMap = new ConcurrentHashMap<>(); @@ -2343,11 +2512,14 @@ public static final String stats() { } public static String getDistinguishingXPath(String xpath, String[] normalizedPath) { - // For example, this removes [@xml:space="preserve"] from a path with element foreignSpaceReplacement. + // For example, this removes [@xml:space="preserve"] from a path with element + // foreignSpaceReplacement. // synchronized (distinguishingMap) { String result = distinguishingMap.get(xpath); if (result == null) { - XPathParts distinguishingParts = XPathParts.getFrozenInstance(xpath).cloneAsThawed(); // not frozen, for removeAttributes + XPathParts distinguishingParts = + XPathParts.getFrozenInstance(xpath) + .cloneAsThawed(); // not frozen, for removeAttributes DtdType type = distinguishingParts.getDtdData().dtdType; Set toRemove = new HashSet<>(); @@ -2397,7 +2569,8 @@ public static String getDistinguishingXPath(String xpath, String[] normalizedPat distinguishingParts.putAttributeValue(placementIndex, "alt", alt); } if (references.length() != 0) { - distinguishingParts.putAttributeValue(placementIndex, "references", references); + distinguishingParts.putAttributeValue( + placementIndex, "references", references); } String newXPath = distinguishingParts.toString(); if (!newXPath.equals(xpath)) { @@ -2435,8 +2608,8 @@ public static String getDistinguishingXPath(String xpath, String[] normalizedPat return result; } - public Map getNonDistinguishingAttributes(String fullPath, Map result, - Set skipList) { + public Map getNonDistinguishingAttributes( + String fullPath, Map result, Set skipList) { if (result == null) { result = new LinkedHashMap<>(); } else { @@ -2447,9 +2620,10 @@ public Map getNonDistinguishingAttributes(String fullPath, Map attributes = distinguishingParts.getAttributes(i); - for (Iterator it = attributes.keySet().iterator(); it.hasNext();) { + for (Iterator it = attributes.keySet().iterator(); it.hasNext(); ) { String attribute = it.next(); - if (!isDistinguishing(type, element, attribute) && !skipList.contains(attribute)) { + if (!isDistinguishing(type, element, attribute) + && !skipList.contains(attribute)) { result.put(attribute, attributes.get(attribute)); } } @@ -2479,8 +2653,8 @@ public boolean isEmpty() { return !dataSource.iterator().hasNext(); } - public Map getNonDistinguishingAttributes(String fullPath, Map result, - Set skipList) { + public Map getNonDistinguishingAttributes( + String fullPath, Map result, Set skipList) { return distinguishedXPath.getNonDistinguishingAttributes(fullPath, result, skipList); } @@ -2498,13 +2672,11 @@ public VersionInfo getDtdVersionInfo() { String full = getFullXPath(path); XPathParts parts = XPathParts.getFrozenInstance(full); String versionString = parts.findFirstAttributeValue("version"); - return versionString == null - ? null - : VersionInfo.getInstance(versionString); + return versionString == null ? null : VersionInfo.getInstance(versionString); } private boolean contains(Map a, Map b) { - for (Iterator it = b.keySet().iterator(); it.hasNext();) { + for (Iterator it = b.keySet().iterator(); it.hasNext(); ) { String key = it.next(); String otherValue = a.get(key); if (otherValue == null) { @@ -2523,8 +2695,11 @@ public String getFullXPath(String path, boolean ignoreOtherLeafAttributes) { if (result != null) return result; XPathParts parts = XPathParts.getFrozenInstance(path); Map lastAttributes = parts.getAttributes(parts.size() - 1); - String base = parts.toString(parts.size() - 1) + "/" + parts.getElement(parts.size() - 1); // trim final element - for (Iterator it = iterator(base); it.hasNext();) { + String base = + parts.toString(parts.size() - 1) + + "/" + + parts.getElement(parts.size() - 1); // trim final element + for (Iterator it = iterator(base); it.hasNext(); ) { String otherPath = it.next(); XPathParts other = XPathParts.getFrozenInstance(otherPath); if (other.size() != parts.size()) { @@ -2554,13 +2729,12 @@ public boolean isWinningPath(String path) { } /** - * Returns the "winning" path, for use in the survey tool tests, out of all - * those paths that only differ by having "alt proposed". The exact meaning - * may be tweaked over time, but the user's choice (vote) has precedence, then - * any undisputed choice, then the "best" choice of the remainders. A value is - * always returned if there is a valid path, and the returned value is always - * a valid path in the resolved file; that is, it may be valid in the - * parent, or valid because of aliasing. + * Returns the "winning" path, for use in the survey tool tests, out of all those paths that + * only differ by having "alt proposed". The exact meaning may be tweaked over time, but the + * user's choice (vote) has precedence, then any undisputed choice, then the "best" choice of + * the remainders. A value is always returned if there is a valid path, and the returned value + * is always a valid path in the resolved file; that is, it may be valid in the parent, + * or valid because of aliasing. * * @param path * @return path, perhaps with an alt proposed added. @@ -2581,9 +2755,8 @@ public String getWinningValue(String path) { } /** - * Shortcut for getting the string value for the winning path. - * If the winning value is an INHERITANCE_MARKER (used in survey - * tool), then the Bailey value is returned. + * Shortcut for getting the string value for the winning path. If the winning value is an + * INHERITANCE_MARKER (used in survey tool), then the Bailey value is returned. * * @param path * @return the winning value @@ -2594,9 +2767,8 @@ public String getWinningValueWithBailey(String path) { } /** - * Shortcut for getting the string value for a path. - * If the string value is an INHERITANCE_MARKER (used in survey - * tool), then the Bailey value is returned. + * Shortcut for getting the string value for a path. If the string value is an + * INHERITANCE_MARKER (used in survey tool), then the Bailey value is returned. * * @param path * @return the string value @@ -2606,16 +2778,18 @@ public String getStringValueWithBailey(String path) { } /** - * Shortcut for getting the string value for a path. - * If the string value is an INHERITANCE_MARKER (used in survey - * tool), then the Bailey value is returned. + * Shortcut for getting the string value for a path. If the string value is an + * INHERITANCE_MARKER (used in survey tool), then the Bailey value is returned. * * @param path the given xpath - * @param pathWhereFound if not null, to be filled in with the path where the value is actually found - * @param localeWhereFound if not null, to be filled in with the locale where the value is actually found + * @param pathWhereFound if not null, to be filled in with the path where the value is actually + * found + * @param localeWhereFound if not null, to be filled in with the locale where the value is + * actually found * @return the string value */ - public String getStringValueWithBailey(String path, Output pathWhereFound, Output localeWhereFound) { + public String getStringValueWithBailey( + String path, Output pathWhereFound, Output localeWhereFound) { String value = getStringValue(path); if (CldrUtility.INHERITANCE_MARKER.equals(value)) { value = getBaileyValue(path, pathWhereFound, localeWhereFound); @@ -2634,14 +2808,15 @@ public String getStringValueWithBailey(String path, Output pathWhereFoun /** * Return the distinguished paths that have the specified value. The pathPrefix and pathMatcher - * can be used to restrict the returned paths to those matching. - * The pathMatcher can be null (equals .*). + * can be used to restrict the returned paths to those matching. The pathMatcher can be null + * (equals .*). * * @param valueToMatch * @param pathPrefix * @return */ - public Set getPathsWithValue(String valueToMatch, String pathPrefix, Matcher pathMatcher, Set result) { + public Set getPathsWithValue( + String valueToMatch, String pathPrefix, Matcher pathMatcher, Set result) { if (result == null) { result = new HashSet<>(); } @@ -2649,7 +2824,7 @@ public Set getPathsWithValue(String valueToMatch, String pathPrefix, Mat if (pathMatcher == null) { return result; } - for (Iterator it = result.iterator(); it.hasNext();) { + for (Iterator it = result.iterator(); it.hasNext(); ) { String path = it.next(); if (!pathMatcher.reset(path).matches()) { it.remove(); @@ -2659,14 +2834,14 @@ public Set getPathsWithValue(String valueToMatch, String pathPrefix, Mat } /** - * Return the distinguished paths that match the pathPrefix and pathMatcher - * The pathMatcher can be null (equals .*). + * Return the distinguished paths that match the pathPrefix and pathMatcher The pathMatcher can + * be null (equals .*). */ public Set getPaths(String pathPrefix, Matcher pathMatcher, Set result) { if (result == null) { result = new HashSet<>(); } - for (Iterator it = dataSource.iterator(pathPrefix); it.hasNext();) { + for (Iterator it = dataSource.iterator(pathPrefix); it.hasNext(); ) { String path = it.next(); if (pathMatcher != null && !pathMatcher.reset(path).matches()) { continue; @@ -2677,14 +2852,14 @@ public Set getPaths(String pathPrefix, Matcher pathMatcher, Set } public enum WinningChoice { - NORMAL, WINNING + NORMAL, + WINNING } /** * Used in TestUser to get the "winning" path. Simple implementation just for testing. * * @author markdavis - * */ static class WinningComparator implements Comparator { String user; @@ -2694,9 +2869,9 @@ public WinningComparator(String user) { } /** - * if it contains the user, sort first. Otherwise use normal string sorting. A better implementation would look - * at - * the number of votes next, and whither there was an approved or provisional path. + * if it contains the user, sort first. Otherwise use normal string sorting. A better + * implementation would look at the number of votes next, and whither there was an approved + * or provisional path. */ @Override public int compare(String o1, String o2) { @@ -2715,7 +2890,6 @@ public int compare(String o1, String o2) { * This is a test class used to simulate what the survey tool would do. * * @author markdavis - * */ public static class TestUser extends CLDRFile { @@ -2726,8 +2900,11 @@ public TestUser(CLDRFile baseFile, String user, boolean resolved) { if (!baseFile.isResolved()) { throw new IllegalArgumentException("baseFile must be resolved"); } - Relation pathMap = Relation.of(new HashMap>(), TreeSet.class, - new WinningComparator(user)); + Relation pathMap = + Relation.of( + new HashMap>(), + TreeSet.class, + new WinningComparator(user)); for (String path : baseFile) { String newPath = getNondraftNonaltXPath(path); pathMap.put(newPath, path); @@ -2777,7 +2954,8 @@ public Collection getExtraPaths() { */ public Collection getExtraPaths(String prefix, Collection toAddTo) { for (String item : getRawExtraPaths()) { - if (item.startsWith(prefix) && dataSource.getValueAtPath(item) == null) { // don't use getStringValue, since + if (item.startsWith(prefix) + && dataSource.getValueAtPath(item) == null) { // don't use getStringValue, since // it recurses. toAddTo.add(item); } @@ -2788,16 +2966,18 @@ public Collection getExtraPaths(String prefix, Collection toAddT // extraPaths contains the raw extra paths. // It requires filtering in those cases where we don't want duplicate paths. /** - * Returns the raw extra paths, irrespective of what paths are already represented in the locale. + * Returns the raw extra paths, irrespective of what paths are already represented in the + * locale. * * @return */ public Set getRawExtraPaths() { if (extraPaths == null) { - extraPaths = ImmutableSet.builder() - .addAll(getRawExtraPathsPrivate()) - .addAll(CONST_EXTRA_PATHS) - .build(); + extraPaths = + ImmutableSet.builder() + .addAll(getRawExtraPathsPrivate()) + .addAll(CONST_EXTRA_PATHS) + .build(); if (DEBUG) { System.out.println(getLocaleID() + "\textras: " + extraPaths.size()); } @@ -2806,30 +2986,24 @@ public Set getRawExtraPaths() { } /** - * Add (possibly over four thousand) extra paths to the given collection. - * These are paths that typically don't have a reasonable fallback value that - * could be added to root. Some of them are common to all locales, and some - * of them are specific to the given locale, based on features like the plural rules - * for the locale. + * Add (possibly over four thousand) extra paths to the given collection. These are paths that + * typically don't have a reasonable fallback value that could be added to root. Some of them + * are common to all locales, and some of them are specific to the given locale, based on + * features like the plural rules for the locale. * - * The ones that are constant for all locales should go into CONST_EXTRA_PATHS. + *

The ones that are constant for all locales should go into CONST_EXTRA_PATHS. * * @return toAddTo (the collection) - * - * Called only by getRawExtraPaths. - * - * "Raw" refers to the fact that some of the paths may duplicate paths that are - * already in this CLDRFile (in the xml and/or votes), in which case they will - * later get filtered by getExtraPaths (removed from toAddTo) rather than re-added. - * - * NOTE: values may be null for some "extra" paths in locales for which no explicit - * values have been submitted. Both unit tests and Survey Tool client code generate - * errors or warnings for null value, but allow null value for certain exceptional - * extra paths. See the functions named extraPathAllowsNullValue in TestPaths.java - * and in the JavaScript client code. Make sure that updates here are reflected there - * and vice versa. - * - * Reference: https://unicode-org.atlassian.net/browse/CLDR-11238 + *

Called only by getRawExtraPaths. + *

"Raw" refers to the fact that some of the paths may duplicate paths that are already + * in this CLDRFile (in the xml and/or votes), in which case they will later get filtered by + * getExtraPaths (removed from toAddTo) rather than re-added. + *

NOTE: values may be null for some "extra" paths in locales for which no explicit + * values have been submitted. Both unit tests and Survey Tool client code generate errors + * or warnings for null value, but allow null value for certain exceptional extra paths. See + * the functions named extraPathAllowsNullValue in TestPaths.java and in the JavaScript + * client code. Make sure that updates here are reflected there and vice versa. + *

Reference: https://unicode-org.atlassian.net/browse/CLDR-11238 */ private Set getRawExtraPathsPrivate() { Set toAddTo = new HashSet<>(); @@ -2837,7 +3011,13 @@ private Set getRawExtraPathsPrivate() { // units PluralInfo plurals = supplementalData.getPlurals(PluralType.cardinal, getLocaleID()); if (plurals == null && DEBUG) { - System.err.println("No " + PluralType.cardinal + " plurals for " + getLocaleID() + " in " + supplementalData.getDirectory().getAbsolutePath()); + System.err.println( + "No " + + PluralType.cardinal + + " plurals for " + + getLocaleID() + + " in " + + supplementalData.getDirectory().getAbsolutePath()); } Set pluralCounts = Collections.emptySet(); if (plurals != null) { @@ -2850,19 +3030,25 @@ private Set getRawExtraPathsPrivate() { } // dayPeriods String locale = getLocaleID(); - DayPeriodInfo dayPeriods = supplementalData.getDayPeriods(DayPeriodInfo.Type.format, locale); + DayPeriodInfo dayPeriods = + supplementalData.getDayPeriods(DayPeriodInfo.Type.format, locale); if (dayPeriods != null) { LinkedHashSet items = new LinkedHashSet<>(dayPeriods.getPeriods()); items.add(DayPeriod.am); items.add(DayPeriod.pm); - for (String context : new String[] { "format", "stand-alone" }) { - for (String width : new String[] { "narrow", "abbreviated", "wide" }) { + for (String context : new String[] {"format", "stand-alone"}) { + for (String width : new String[] {"narrow", "abbreviated", "wide"}) { for (DayPeriod dayPeriod : items) { // ldml/dates/calendars/calendar[@type="gregorian"]/dayPeriods/dayPeriodContext[@type="format"]/dayPeriodWidth[@type="wide"]/dayPeriod[@type="am"] - toAddTo.add("//ldml/dates/calendars/calendar[@type=\"gregorian\"]/dayPeriods/" + - "dayPeriodContext[@type=\"" + context - + "\"]/dayPeriodWidth[@type=\"" + width - + "\"]/dayPeriod[@type=\"" + dayPeriod + "\"]"); + toAddTo.add( + "//ldml/dates/calendars/calendar[@type=\"gregorian\"]/dayPeriods/" + + "dayPeriodContext[@type=\"" + + context + + "\"]/dayPeriodWidth[@type=\"" + + width + + "\"]/dayPeriod[@type=\"" + + dayPeriod + + "\"]"); } } } @@ -2873,40 +3059,55 @@ private Set getRawExtraPathsPrivate() { for (String zone : zones) { final boolean metazoneUsesDST = CheckMetazones.metazoneUsesDST(zone); - for (String width : new String[] { "long", "short" }) { - for (String type : new String[] { "generic", "standard", "daylight" }) { + for (String width : new String[] {"long", "short"}) { + for (String type : new String[] {"generic", "standard", "daylight"}) { if (metazoneUsesDST || type.equals("standard")) { // Only add /standard for non-DST metazones - final String path = "//ldml/dates/timeZoneNames/metazone[@type=\"" + zone + "\"]/" + width + "/" + type; + final String path = + "//ldml/dates/timeZoneNames/metazone[@type=\"" + + zone + + "\"]/" + + width + + "/" + + type; toAddTo.add(path); } } } } -// // Individual zone overrides -// final String[] overrides = { -// "Pacific/Honolulu\"]/short/generic", -// "Pacific/Honolulu\"]/short/standard", -// "Pacific/Honolulu\"]/short/daylight", -// "Europe/Dublin\"]/long/daylight", -// "Europe/London\"]/long/daylight", -// "Etc/UTC\"]/long/standard", -// "Etc/UTC\"]/short/standard" -// }; -// for (String override : overrides) { -// toAddTo.add("//ldml/dates/timeZoneNames/zone[@type=\"" + override); -// } + // // Individual zone overrides + // final String[] overrides = { + // "Pacific/Honolulu\"]/short/generic", + // "Pacific/Honolulu\"]/short/standard", + // "Pacific/Honolulu\"]/short/daylight", + // "Europe/Dublin\"]/long/daylight", + // "Europe/London\"]/long/daylight", + // "Etc/UTC\"]/long/standard", + // "Etc/UTC\"]/short/standard" + // }; + // for (String override : overrides) { + // toAddTo.add("//ldml/dates/timeZoneNames/zone[@type=\"" + override); + // } // Currencies Set codes = supplementalData.getBcp47Keys().getAll("cu"); for (String code : codes) { String currencyCode = code.toUpperCase(); - toAddTo.add("//ldml/numbers/currencies/currency[@type=\"" + currencyCode + "\"]/symbol"); - toAddTo.add("//ldml/numbers/currencies/currency[@type=\"" + currencyCode + "\"]/displayName"); + toAddTo.add( + "//ldml/numbers/currencies/currency[@type=\"" + currencyCode + "\"]/symbol"); + toAddTo.add( + "//ldml/numbers/currencies/currency[@type=\"" + + currencyCode + + "\"]/displayName"); if (!pluralCounts.isEmpty()) { for (Count count : pluralCounts) { - toAddTo.add("//ldml/numbers/currencies/currency[@type=\"" + currencyCode + "\"]/displayName[@count=\"" + count.toString() + "\"]"); + toAddTo.add( + "//ldml/numbers/currencies/currency[@type=\"" + + currencyCode + + "\"]/displayName[@count=\"" + + count.toString() + + "\"]"); } } } @@ -2916,44 +3117,79 @@ private Set getRawExtraPathsPrivate() { GrammarInfo grammarInfo = supplementalData.getGrammarInfo(getLocaleID(), true); if (grammarInfo != null) { if (grammarInfo.hasInfo(GrammaticalTarget.nominal)) { - Collection genders = grammarInfo.get(GrammaticalTarget.nominal, GrammaticalFeature.grammaticalGender, GrammaticalScope.units); - Collection rawCases = grammarInfo.get(GrammaticalTarget.nominal, GrammaticalFeature.grammaticalCase, GrammaticalScope.units); + Collection genders = + grammarInfo.get( + GrammaticalTarget.nominal, + GrammaticalFeature.grammaticalGender, + GrammaticalScope.units); + Collection rawCases = + grammarInfo.get( + GrammaticalTarget.nominal, + GrammaticalFeature.grammaticalCase, + GrammaticalScope.units); Collection nomCases = rawCases.isEmpty() ? casesNominativeOnly : rawCases; Collection adjustedPlurals = pluralCounts; - // There was code here allowing fewer plurals to be used, but is retracted for now (needs more thorough integration in logical groups, etc.) + // There was code here allowing fewer plurals to be used, but is retracted for now + // (needs more thorough integration in logical groups, etc.) // This note is left for 'blame' to find the old code in case we revive that. // TODO use UnitPathType to get paths if (!genders.isEmpty()) { for (String unit : GrammarInfo.getUnitsToAddGrammar()) { - toAddTo.add("//ldml/units/unitLength[@type=\"long\"]/unit[@type=\"" + unit + "\"]/gender"); + toAddTo.add( + "//ldml/units/unitLength[@type=\"long\"]/unit[@type=\"" + + unit + + "\"]/gender"); } for (Count plural : adjustedPlurals) { for (String gender : genders) { for (String case1 : nomCases) { - final String grammaticalAttributes = GrammarInfo.getGrammaticalInfoAttributes(grammarInfo, UnitPathType.power, plural.toString(), - gender, case1); - toAddTo - .add("//ldml/units/unitLength[@type=\"long\"]/compoundUnit[@type=\"power2\"]/compoundUnitPattern1" + grammaticalAttributes); - toAddTo - .add("//ldml/units/unitLength[@type=\"long\"]/compoundUnit[@type=\"power3\"]/compoundUnitPattern1" + grammaticalAttributes); + final String grammaticalAttributes = + GrammarInfo.getGrammaticalInfoAttributes( + grammarInfo, + UnitPathType.power, + plural.toString(), + gender, + case1); + toAddTo.add( + "//ldml/units/unitLength[@type=\"long\"]/compoundUnit[@type=\"power2\"]/compoundUnitPattern1" + + grammaticalAttributes); + toAddTo.add( + "//ldml/units/unitLength[@type=\"long\"]/compoundUnit[@type=\"power3\"]/compoundUnitPattern1" + + grammaticalAttributes); } } } - // Der {0} ist … + // Der {0} ist + // … for (String gender : genders) { - toAddTo.add("//ldml/numbers/minimalPairs/genderMinimalPairs[@gender=\"" + gender + "\"]"); + toAddTo.add( + "//ldml/numbers/minimalPairs/genderMinimalPairs[@gender=\"" + + gender + + "\"]"); } } if (!rawCases.isEmpty()) { for (String case1 : rawCases) { - // {0} kostet €3,50. - toAddTo.add("//ldml/numbers/minimalPairs/caseMinimalPairs[@case=\"" + case1 + "\"]"); + // {0} kostet + // €3,50. + toAddTo.add( + "//ldml/numbers/minimalPairs/caseMinimalPairs[@case=\"" + + case1 + + "\"]"); for (Count plural : adjustedPlurals) { for (String unit : GrammarInfo.getUnitsToAddGrammar()) { - toAddTo.add("//ldml/units/unitLength[@type=\"long\"]/unit[@type=\"" + unit + "\"]/unitPattern" - + GrammarInfo.getGrammaticalInfoAttributes(grammarInfo, UnitPathType.unit, plural.toString(), null, case1)); + toAddTo.add( + "//ldml/units/unitLength[@type=\"long\"]/unit[@type=\"" + + unit + + "\"]/unitPattern" + + GrammarInfo.getGrammaticalInfoAttributes( + grammarInfo, + UnitPathType.unit, + plural.toString(), + null, + case1)); } } } @@ -2963,17 +3199,19 @@ private Set getRawExtraPathsPrivate() { return toAddTo; } - private void addPluralCounts(Collection toAddTo, - final Set pluralCounts, - final Set pluralCountsRaw, - Iterable file) { + private void addPluralCounts( + Collection toAddTo, + final Set pluralCounts, + final Set pluralCountsRaw, + Iterable file) { for (String path : file) { String countAttr = "[@count=\"other\"]"; int countPos = path.indexOf(countAttr); if (countPos < 0) { continue; } - Set pluralCountsNeeded = path.startsWith("//ldml/numbers/minimalPairs") ? pluralCountsRaw : pluralCounts; + Set pluralCountsNeeded = + path.startsWith("//ldml/numbers/minimalPairs") ? pluralCountsRaw : pluralCounts; if (pluralCountsNeeded.size() > 1) { String start = path.substring(0, countPos) + "[@count=\""; String end = "\"]" + path.substring(countPos + countAttr.length()); @@ -2988,29 +3226,37 @@ private void addPluralCounts(Collection toAddTo, } /** - * Get the path with the given count, case, or gender, with fallback. The fallback acts like an alias in root. - *

Count:

- *

It acts like there is an alias in root from count=n to count=one, - * then for currency display names from count=one to no count
+ * Get the path with the given count, case, or gender, with fallback. The fallback acts like an + * alias in root. + * + *

Count: + * + *

It acts like there is an alias in root from count=n to count=one, then for currency + * display names from count=one to no count
* For unitPatterns, falls back to Count.one.
- * For others, falls back to Count.one, then no count.

- *

Case

- *

The fallback is to no case, which = nominative.

- *

Case

- *

The fallback is to no case, which = nominative.

+ * For others, falls back to Count.one, then no count. + * + *

Case + * + *

The fallback is to no case, which = nominative. + * + *

Case + * + *

The fallback is to no case, which = nominative. * * @param xpath - * @param count - * Count may be null. Returns null if nothing is found. - * @param winning - * TODO + * @param count Count may be null. Returns null if nothing is found. + * @param winning TODO * @return */ public String getCountPathWithFallback(String xpath, Count count, boolean winning) { String result; - XPathParts parts = XPathParts.getFrozenInstance(xpath).cloneAsThawed(); // not frozen, addAttribute in getCountPathWithFallback2 + XPathParts parts = + XPathParts.getFrozenInstance(xpath) + .cloneAsThawed(); // not frozen, addAttribute in getCountPathWithFallback2 - // In theory we should do all combinations of gender, case, count (and eventually definiteness), but for simplicity + // In theory we should do all combinations of gender, case, count (and eventually + // definiteness), but for simplicity // we just successively try "zeroing" each one in a set order. // tryDefault modifies the parts in question Output newPath = new Output<>(); @@ -3031,7 +3277,9 @@ public String getCountPathWithFallback(String xpath, Count count, boolean winnin int item = Integer.parseInt(actualCount); String locale = getLocaleID(); SupplementalDataInfo sdi = CLDRConfig.getInstance().getSupplementalDataInfo(); - PluralRules rules = sdi.getPluralRules(new ULocale(locale), PluralRules.PluralType.CARDINAL); + PluralRules rules = + sdi.getPluralRules( + new ULocale(locale), PluralRules.PluralType.CARDINAL); String keyword = rules.select(item); Count itemCount = Count.valueOf(keyword); result = getCountPathWithFallback2(parts, xpath, itemCount, winning); @@ -3064,9 +3312,11 @@ public String getCountPathWithFallback(String xpath, Count count, boolean winnin } /** - * Modify the parts by setting the attribute in question to the default value (typically null to clear). If there is a value for that path, use it. + * Modify the parts by setting the attribute in question to the default value (typically null to + * clear). If there is a value for that path, use it. */ - public boolean tryDefault(XPathParts parts, String attribute, String defaultValue, Output newPath) { + public boolean tryDefault( + XPathParts parts, String attribute, String defaultValue, Output newPath) { String oldValue = parts.getAttributeValue(-1, attribute); if (oldValue != null) { parts.setAttribute(-1, attribute, null); @@ -3078,8 +3328,8 @@ public boolean tryDefault(XPathParts parts, String attribute, String defaultValu return false; } - private String getCountPathWithFallback2(XPathParts parts, String xpathWithNoCount, - Count count, boolean winning) { + private String getCountPathWithFallback2( + XPathParts parts, String xpathWithNoCount, Count count, boolean winning) { parts.addAttribute("count", count == null ? null : count.toString()); String newPath = parts.toString(); if (!newPath.equals(xpathWithNoCount)) { @@ -3098,16 +3348,17 @@ private String getCountPathWithFallback2(XPathParts parts, String xpathWithNoCou } /** - * Returns a value to be used for "filling in" a "Change" value in the survey - * tool. Currently returns the following. + * Returns a value to be used for "filling in" a "Change" value in the survey tool. Currently + * returns the following. + * *

    - *
  • The "winning" value (if not inherited). Example: if "Donnerstag" has the most votes for 'thursday', then - * clicking on the empty field will fill in "Donnerstag" - *
  • The singular form. Example: if the value for 'hour' is "heure", then clicking on the entry field for 'hours' - * will insert "heure". - *
  • The parent's value. Example: if I'm in [de_CH] and there are no proposals for 'thursday', then clicking on - * the empty field will fill in "Donnerstag" from [de]. - *
  • Otherwise don't fill in anything, and return null. + *
  • The "winning" value (if not inherited). Example: if "Donnerstag" has the most votes for + * 'thursday', then clicking on the empty field will fill in "Donnerstag" + *
  • The singular form. Example: if the value for 'hour' is "heure", then clicking on the + * entry field for 'hours' will insert "heure". + *
  • The parent's value. Example: if I'm in [de_CH] and there are no proposals for + * 'thursday', then clicking on the empty field will fill in "Donnerstag" from [de]. + *
  • Otherwise don't fill in anything, and return null. *
* * @return @@ -3135,7 +3386,9 @@ public String getFillInValue(String distinguishedPath) { */ public boolean isNotRoot(String distinguishedPath) { String source = getSourceLocaleID(distinguishedPath, null); - return source != null && !source.equals("root") && !source.equals(XMLSource.CODE_FALLBACK_ID); + return source != null + && !source.equals("root") + && !source.equals(XMLSource.CODE_FALLBACK_ID); } public boolean isAliasedAtTopLevel() { @@ -3147,11 +3400,11 @@ public static Comparator getComparator(DtdType dtdType) { return ldmlComparator; } switch (dtdType) { - case ldml: - case ldmlICU: - return ldmlComparator; - default: - return DtdData.getInstance(dtdType).getDtdComparator(null); + case ldml: + case ldmlICU: + return ldmlComparator; + default: + return DtdData.getInstance(dtdType).getDtdComparator(null); } } @@ -3160,13 +3413,11 @@ public Comparator getComparator() { } public DtdType getDtdType() { - return dtdType != null ? dtdType - : dataSource.getDtdType(); + return dtdType != null ? dtdType : dataSource.getDtdType(); } public DtdData getDtdData() { - return dtdData != null ? dtdData - : DtdData.getInstance(getDtdType()); + return dtdData != null ? dtdData : DtdData.getInstance(getDtdType()); } public static Comparator getPathComparator(String path) { @@ -3195,9 +3446,7 @@ public void setDtdType(DtdType dtdType) { this.dtdType = dtdType; } - /** - * Used only for TestExampleGenerator. - */ + /** Used only for TestExampleGenerator. */ public void valueChanged(String xpath) { if (isResolved()) { ResolvingSource resSource = (ResolvingSource) dataSource; @@ -3205,17 +3454,17 @@ public void valueChanged(String xpath) { } } - /** - * Used only for TestExampleGenerator. - */ + /** Used only for TestExampleGenerator. */ public void disableCaching() { dataSource.disableCaching(); } /** - * Get a constructed value for the given path, if it is a path for which values can be constructed + * Get a constructed value for the given path, if it is a path for which values can be + * constructed * - * @param xpath the given path, such as //ldml/localeDisplayNames/languages/language[@type="zh_Hans"] + * @param xpath the given path, such as + * //ldml/localeDisplayNames/languages/language[@type="zh_Hans"] * @return the constructed value, or null if this path doesn't have a constructed value */ public String getConstructedValue(String xpath) { @@ -3226,8 +3475,8 @@ public String getConstructedValue(String xpath) { } /** - * Get the string value for the given path in this locale, - * without resolving to any other path or locale. + * Get the string value for the given path in this locale, without resolving to any other path + * or locale. * * @param xpath the given path * @return the string value, unresolved @@ -3239,10 +3488,12 @@ private String getStringValueUnresolved(String xpath) { /** * Create an overriding LocaleStringProvider for testing and example generation + * * @param pathAndValueOverrides * @return */ - public LocaleStringProvider makeOverridingStringProvider(Map pathAndValueOverrides) { + public LocaleStringProvider makeOverridingStringProvider( + Map pathAndValueOverrides) { return new OverridingStringProvider(pathAndValueOverrides); } @@ -3279,11 +3530,14 @@ public String getSourceLocaleID(String xpath, Status status) { public String getKeyName(String key) { String result = getStringValue("//ldml/localeDisplayNames/keys/key[@type=\"" + key + "\"]"); if (result == null) { - Relation, String> toAliases = SupplementalDataInfo.getInstance().getBcp47Aliases(); + Relation, String> toAliases = + SupplementalDataInfo.getInstance().getBcp47Aliases(); Set aliases = toAliases.get(Row.of(key, "")); if (aliases != null) { for (String alias : aliases) { - result = getStringValue("//ldml/localeDisplayNames/keys/key[@type=\"" + alias + "\"]"); + result = + getStringValue( + "//ldml/localeDisplayNames/keys/key[@type=\"" + alias + "\"]"); if (result != null) { break; } @@ -3294,9 +3548,16 @@ public String getKeyName(String key) { } public String getKeyValueName(String key, String value) { - String result = getStringValue("//ldml/localeDisplayNames/types/type[@key=\"" + key + "\"][@type=\"" + value + "\"]"); + String result = + getStringValue( + "//ldml/localeDisplayNames/types/type[@key=\"" + + key + + "\"][@type=\"" + + value + + "\"]"); if (result == null) { - Relation, String> toAliases = SupplementalDataInfo.getInstance().getBcp47Aliases(); + Relation, String> toAliases = + SupplementalDataInfo.getInstance().getBcp47Aliases(); Set keyAliases = toAliases.get(Row.of(key, "")); Set valueAliases = toAliases.get(Row.of(key, value)); if (keyAliases != null || valueAliases != null) { @@ -3308,7 +3569,13 @@ public String getKeyValueName(String key, String value) { } for (String keyAlias : keyAliases) { for (String valueAlias : valueAliases) { - result = getStringValue("//ldml/localeDisplayNames/types/type[@key=\"" + keyAlias + "\"][@type=\"" + valueAlias + "\"]"); + result = + getStringValue( + "//ldml/localeDisplayNames/types/type[@key=\"" + + keyAlias + + "\"][@type=\"" + + valueAlias + + "\"]"); if (result != null) { break; } @@ -3332,9 +3599,7 @@ public String getKeyValueName(String key, String value) { static final Joiner JOIN_HYPHEN = Joiner.on('-'); static final Joiner JOIN_UNDERBAR = Joiner.on('_'); - /** - * Utility for getting a name, given a type and code. - */ + /** Utility for getting a name, given a type and code. */ public String getName(String type, String code) { return getName(typeNameToCode(type), code); } @@ -3344,8 +3609,8 @@ public String getName(int type, String code) { } /** - * Returns the name of the given bcp47 identifier. Note that extensions must - * be specified using the old "\@key=type" syntax. + * Returns the name of the given bcp47 identifier. Note that extensions must be specified using + * the old "\@key=type" syntax. * * @param localeOrTZID * @return @@ -3355,33 +3620,40 @@ public synchronized String getName(String localeOrTZID) { } public String getName( - LanguageTagParser lparser, - boolean onlyConstructCompound, - Transform altPicker - ) { + LanguageTagParser lparser, + boolean onlyConstructCompound, + Transform altPicker) { return getName( - lparser, - onlyConstructCompound, - altPicker, - getWinningValueWithBailey("//ldml/localeDisplayNames/localeDisplayPattern/localeKeyTypePattern"), - getWinningValueWithBailey("//ldml/localeDisplayNames/localeDisplayPattern/localePattern"), - getWinningValueWithBailey("//ldml/localeDisplayNames/localeDisplayPattern/localeSeparator") - ); + lparser, + onlyConstructCompound, + altPicker, + getWinningValueWithBailey( + "//ldml/localeDisplayNames/localeDisplayPattern/localeKeyTypePattern"), + getWinningValueWithBailey( + "//ldml/localeDisplayNames/localeDisplayPattern/localePattern"), + getWinningValueWithBailey( + "//ldml/localeDisplayNames/localeDisplayPattern/localeSeparator")); } public synchronized String getName( - String localeOrTZID, - boolean onlyConstructCompound, - String localeKeyTypePattern, - String localePattern, - String localeSeparator - ) { - return getName(localeOrTZID, onlyConstructCompound, localeKeyTypePattern, localePattern, localeSeparator, null); + String localeOrTZID, + boolean onlyConstructCompound, + String localeKeyTypePattern, + String localePattern, + String localeSeparator) { + return getName( + localeOrTZID, + onlyConstructCompound, + localeKeyTypePattern, + localePattern, + localeSeparator, + null); } /** - * Returns the name of the given bcp47 identifier. Note that extensions must - * be specified using the old "\@key=type" syntax. + * Returns the name of the given bcp47 identifier. Note that extensions must be specified using + * the old "\@key=type" syntax. + * * @param localeOrTZID the locale or timezone ID * @param onlyConstructCompound * @return @@ -3391,33 +3663,36 @@ public synchronized String getName(String localeOrTZID, boolean onlyConstructCom } /** - * Returns the name of the given bcp47 identifier. Note that extensions must - * be specified using the old "\@key=type" syntax. + * Returns the name of the given bcp47 identifier. Note that extensions must be specified using + * the old "\@key=type" syntax. + * * @param localeOrTZID the locale or timezone ID - * @param onlyConstructCompound if true, returns "English (United Kingdom)" instead of "British English" - * @param altPicker Used to select particular alts. For example, SHORT_ALTS can be used to get "English (U.K.)" - * instead of "English (United Kingdom)" + * @param onlyConstructCompound if true, returns "English (United Kingdom)" instead of "British + * English" + * @param altPicker Used to select particular alts. For example, SHORT_ALTS can be used to get + * "English (U.K.)" instead of "English (United Kingdom)" * @return */ public synchronized String getName( - String localeOrTZID, - boolean onlyConstructCompound, - Transform altPicker - ) { + String localeOrTZID, + boolean onlyConstructCompound, + Transform altPicker) { return getName( - localeOrTZID, - onlyConstructCompound, - getWinningValueWithBailey("//ldml/localeDisplayNames/localeDisplayPattern/localeKeyTypePattern"), - getWinningValueWithBailey("//ldml/localeDisplayNames/localeDisplayPattern/localePattern"), - getWinningValueWithBailey("//ldml/localeDisplayNames/localeDisplayPattern/localeSeparator"), - altPicker - ); + localeOrTZID, + onlyConstructCompound, + getWinningValueWithBailey( + "//ldml/localeDisplayNames/localeDisplayPattern/localeKeyTypePattern"), + getWinningValueWithBailey( + "//ldml/localeDisplayNames/localeDisplayPattern/localePattern"), + getWinningValueWithBailey( + "//ldml/localeDisplayNames/localeDisplayPattern/localeSeparator"), + altPicker); } /** - * Returns the name of the given bcp47 identifier. Note that extensions must - * be specified using the old "\@key=type" syntax. - * Only used by ExampleGenerator. + * Returns the name of the given bcp47 identifier. Note that extensions must be specified using + * the old "\@key=type" syntax. Only used by ExampleGenerator. + * * @param localeOrTZID the locale or timezone ID * @param onlyConstructCompound * @param localeKeyTypePattern the pattern used to format key-type pairs @@ -3426,19 +3701,21 @@ public synchronized String getName( * @return */ public synchronized String getName( - String localeOrTZID, - boolean onlyConstructCompound, - String localeKeyTypePattern, - String localePattern, - String localeSeparator, - Transform altPicker - ) { + String localeOrTZID, + boolean onlyConstructCompound, + String localeKeyTypePattern, + String localePattern, + String localeSeparator, + Transform altPicker) { // Hack for seed if (localePattern == null) { localePattern = "{0} ({1})"; } boolean isCompound = localeOrTZID.contains("_"); - String name = isCompound && onlyConstructCompound ? null : getName(LANGUAGE_NAME, localeOrTZID, altPicker); + String name = + isCompound && onlyConstructCompound + ? null + : getName(LANGUAGE_NAME, localeOrTZID, altPicker); // TODO - handle arbitrary combinations if (name != null && !name.contains("_") && !name.contains("-")) { @@ -3446,17 +3723,22 @@ public synchronized String getName( return name; } LanguageTagParser lparser = new LanguageTagParser().set(localeOrTZID); - return getName(lparser, onlyConstructCompound, altPicker, localeKeyTypePattern, localePattern, localeSeparator); + return getName( + lparser, + onlyConstructCompound, + altPicker, + localeKeyTypePattern, + localePattern, + localeSeparator); } public String getName( - LanguageTagParser lparser, - boolean onlyConstructCompound, - Transform altPicker, - String localeKeyTypePattern, - String localePattern, - String localeSeparator - ) { + LanguageTagParser lparser, + boolean onlyConstructCompound, + Transform altPicker, + String localeKeyTypePattern, + String localePattern, + String localeSeparator) { String name; String original = null; @@ -3473,11 +3755,19 @@ public String getName( if (name != null) { haveScript = haveRegion = true; } else { - name = getName(LANGUAGE_NAME, lparser.toString(LanguageTagParser.LANGUAGE_SCRIPT), altPicker); + name = + getName( + LANGUAGE_NAME, + lparser.toString(LanguageTagParser.LANGUAGE_SCRIPT), + altPicker); if (name != null) { haveScript = true; } else { - name = getName(LANGUAGE_NAME, lparser.toString(LanguageTagParser.LANGUAGE_REGION), altPicker); + name = + getName( + LANGUAGE_NAME, + lparser.toString(LanguageTagParser.LANGUAGE_REGION), + altPicker); if (name != null) { haveRegion = true; } else { @@ -3492,10 +3782,18 @@ public String getName( name = name.replace('(', '[').replace(')', ']').replace('(', '[').replace(')', ']'); String extras = ""; if (!haveScript) { - extras = addDisplayName(lparser.getScript(), SCRIPT_NAME, localeSeparator, extras, altPicker); + extras = + addDisplayName( + lparser.getScript(), SCRIPT_NAME, localeSeparator, extras, altPicker); } if (!haveRegion) { - extras = addDisplayName(lparser.getRegion(), TERRITORY_NAME, localeSeparator, extras, altPicker); + extras = + addDisplayName( + lparser.getRegion(), + TERRITORY_NAME, + localeSeparator, + extras, + altPicker); } List variants = lparser.getVariants(); for (String orig : variants) { @@ -3503,17 +3801,25 @@ public String getName( } // Look for key-type pairs. - main:for (Map.Entry> extension : lparser.getLocaleExtensionsDetailed().entrySet()) { + main: + for (Map.Entry> extension : + lparser.getLocaleExtensionsDetailed().entrySet()) { String key = extension.getKey(); if (key.equals("h0")) { continue; } List keyValue = extension.getValue(); - String oldFormatType = (key.equals("ca") ? JOIN_HYPHEN : JOIN_UNDERBAR).join(keyValue); // default value + String oldFormatType = + (key.equals("ca") ? JOIN_HYPHEN : JOIN_UNDERBAR) + .join(keyValue); // default value // Check if key/type pairs exist in the CLDRFile first. String value = getKeyValueName(key, oldFormatType); if (value != null) { - value = value.replace('(', '[').replace(')', ']').replace('(', '[').replace(')', ']'); + value = + value.replace('(', '[') + .replace(')', ']') + .replace('(', '[') + .replace(')', ']'); } else { // if we fail, then we construct from the key name and the value String kname = getKeyName(key); @@ -3521,49 +3827,65 @@ public String getName( kname = key; // should not happen, but just in case } switch (key) { - case "t": - List hybrid = lparser.getLocaleExtensionsDetailed().get("h0"); - if (hybrid != null) { - kname = getKeyValueName("h0", JOIN_UNDERBAR.join(hybrid)); - } - oldFormatType = getName(oldFormatType); - break; - case "h0": - continue main; - case "cu": - oldFormatType = getName(CURRENCY_SYMBOL, oldFormatType.toUpperCase(Locale.ROOT)); - break; - case "tz": - oldFormatType = getTZName(oldFormatType, "VVVV"); - break; - case "kr": - oldFormatType = getReorderName(localeSeparator, keyValue); - break; - case "rg": - case "sd": - oldFormatType = getName(SUBDIVISION_NAME, oldFormatType); - break; - default: - oldFormatType = JOIN_HYPHEN.join(keyValue); + case "t": + List hybrid = lparser.getLocaleExtensionsDetailed().get("h0"); + if (hybrid != null) { + kname = getKeyValueName("h0", JOIN_UNDERBAR.join(hybrid)); + } + oldFormatType = getName(oldFormatType); + break; + case "h0": + continue main; + case "cu": + oldFormatType = + getName(CURRENCY_SYMBOL, oldFormatType.toUpperCase(Locale.ROOT)); + break; + case "tz": + oldFormatType = getTZName(oldFormatType, "VVVV"); + break; + case "kr": + oldFormatType = getReorderName(localeSeparator, keyValue); + break; + case "rg": + case "sd": + oldFormatType = getName(SUBDIVISION_NAME, oldFormatType); + break; + default: + oldFormatType = JOIN_HYPHEN.join(keyValue); } - value = MessageFormat.format(localeKeyTypePattern, new Object[] { kname, oldFormatType }); - value = value.replace('(', '[').replace(')', ']').replace('(', '[').replace(')', ']'); + value = + MessageFormat.format( + localeKeyTypePattern, new Object[] {kname, oldFormatType}); + value = + value.replace('(', '[') + .replace(')', ']') + .replace('(', '[') + .replace(')', ']'); } - extras = extras.isEmpty() ? value : MessageFormat.format(localeSeparator, new Object[] { extras, value }); + extras = + extras.isEmpty() + ? value + : MessageFormat.format(localeSeparator, new Object[] {extras, value}); } // now handle stray extensions - for (Map.Entry> extension : lparser.getExtensionsDetailed().entrySet()) { - String value = MessageFormat.format( - localeKeyTypePattern, - new Object[] { extension.getKey(), JOIN_HYPHEN.join(extension.getValue()) } - ); - extras = extras.isEmpty() ? value : MessageFormat.format(localeSeparator, new Object[] { extras, value }); + for (Map.Entry> extension : + lparser.getExtensionsDetailed().entrySet()) { + String value = + MessageFormat.format( + localeKeyTypePattern, + new Object[] { + extension.getKey(), JOIN_HYPHEN.join(extension.getValue()) + }); + extras = + extras.isEmpty() + ? value + : MessageFormat.format(localeSeparator, new Object[] {extras, value}); } // fix this -- shouldn't be hardcoded! if (extras.length() == 0) { return name; } - return MessageFormat.format(localePattern, new Object[] { name, extras }); + return MessageFormat.format(localePattern, new Object[] {name, extras}); } /** @@ -3571,9 +3893,10 @@ public String getName( * * @param type * @param code - * @param codeToAlt - if not null, is called on the code. If the result is not null, then that is used for an alt value. - * If the alt path has a value it is used, otherwise the normal one is used. For example, the transform could return "short" for - * PS or HK or MO, but not US or GB. + * @param codeToAlt - if not null, is called on the code. If the result is not null, then that + * is used for an alt value. If the alt path has a value it is used, otherwise the normal + * one is used. For example, the transform could return "short" for PS or HK or MO, but not + * US or GB. * @return */ public String getName(int type, String code, Transform codeToAlt) { @@ -3598,7 +3921,8 @@ public String getName(int type, String code, Transform codeToAlt if (set != null) { return set.iterator().next(); } - Map> map = StandardCodes.getLStreg().get("language"); + Map> map = + StandardCodes.getLStreg().get("language"); Map info = map.get(code); if (info != null) { result = info.get("Description"); @@ -3635,6 +3959,7 @@ private String getLstrFallback(String codeType, String code) { /** * Gets timezone name. Not optimized. + * * @param tzcode * @return */ @@ -3650,34 +3975,40 @@ private String getTZName(String tzcode, String format) { private String getReorderName(String localeSeparator, List keyValues) { String result = null; for (String value : keyValues) { - String name = getName(SCRIPT_NAME, Character.toUpperCase(value.charAt(0)) + value.substring(1)); + String name = + getName( + SCRIPT_NAME, + Character.toUpperCase(value.charAt(0)) + value.substring(1)); if (name == null) { name = getKeyValueName("kr", value); if (name == null) { name = value; } } - result = result == null ? name : MessageFormat.format(localeSeparator, new Object[] { result, name }); + result = + result == null + ? name + : MessageFormat.format(localeSeparator, new Object[] {result, name}); } return result; } /** * Adds the display name for a subtag to a string. + * * @param subtag the subtag * @param type the type of the subtag - * @param separatorPattern the pattern to be used for separating display - * names in the resultant string + * @param separatorPattern the pattern to be used for separating display names in the resultant + * string * @param extras the string to be added to * @return the modified display name string */ private String addDisplayName( - String subtag, - int type, - String separatorPattern, - String extras, - Transform altPicker - ) { + String subtag, + int type, + String separatorPattern, + String extras, + Transform altPicker) { if (subtag.length() == 0) { return extras; } @@ -3690,20 +4021,20 @@ private String addDisplayName( if (extras.length() == 0) { extras += sname; } else { - extras = MessageFormat.format(separatorPattern, new Object[] { extras, sname }); + extras = MessageFormat.format(separatorPattern, new Object[] {extras, sname}); } return extras; } /** - * Like getStringValueWithBailey, but reject constructed values, to prevent - * circularity problems with getName + * Like getStringValueWithBailey, but reject constructed values, to prevent circularity problems + * with getName * - * Since GlossonymConstructor uses getName to CREATE constructed values, circularity - * problems would occur if getName in turn used GlossonymConstructor to get constructed - * Bailey values. Note that getStringValueWithBailey only returns a constructed value if - * the value would otherwise be "bogus", and getName has no use for bogus values, so there - * is no harm in returning null rather than code-fallback or other bogus values. + *

Since GlossonymConstructor uses getName to CREATE constructed values, circularity problems + * would occur if getName in turn used GlossonymConstructor to get constructed Bailey values. + * Note that getStringValueWithBailey only returns a constructed value if the value would + * otherwise be "bogus", and getName has no use for bogus values, so there is no harm in + * returning null rather than code-fallback or other bogus values. * * @param path the given xpath * @return the string value, or null @@ -3718,49 +4049,49 @@ private String getStringValueWithBaileyNotConstructed(String path) { } /** - * A set of paths to be added to getRawExtraPaths(). - * These are constant across locales, and don't have good fallback values in root. - * NOTE: if this is changed, you'll need to modify TestPaths.extraPathAllowsNullValue - */ - static final Set CONST_EXTRA_PATHS = ImmutableSet.of( - // Individual zone overrides — were in getRawExtraPaths - "//ldml/dates/timeZoneNames/zone[@type=\"Pacific/Honolulu\"]/short/generic", - "//ldml/dates/timeZoneNames/zone[@type=\"Pacific/Honolulu\"]/short/standard", - "//ldml/dates/timeZoneNames/zone[@type=\"Pacific/Honolulu\"]/short/daylight", - "//ldml/dates/timeZoneNames/zone[@type=\"Europe/Dublin\"]/long/daylight", - "//ldml/dates/timeZoneNames/zone[@type=\"Europe/London\"]/long/daylight", - "//ldml/dates/timeZoneNames/zone[@type=\"Etc/UTC\"]/long/standard", - "//ldml/dates/timeZoneNames/zone[@type=\"Etc/UTC\"]/short/standard", - // Person name paths - "//ldml/personNames/sampleName[@item=\"nativeG\"]/nameField[@type=\"given\"]", - "//ldml/personNames/sampleName[@item=\"nativeGS\"]/nameField[@type=\"given\"]", - "//ldml/personNames/sampleName[@item=\"nativeGS\"]/nameField[@type=\"surname\"]", - "//ldml/personNames/sampleName[@item=\"nativeGGS\"]/nameField[@type=\"given\"]", - "//ldml/personNames/sampleName[@item=\"nativeGGS\"]/nameField[@type=\"given2\"]", - "//ldml/personNames/sampleName[@item=\"nativeGGS\"]/nameField[@type=\"surname\"]", - "//ldml/personNames/sampleName[@item=\"nativeFull\"]/nameField[@type=\"title\"]", - "//ldml/personNames/sampleName[@item=\"nativeFull\"]/nameField[@type=\"given\"]", - "//ldml/personNames/sampleName[@item=\"nativeFull\"]/nameField[@type=\"given-informal\"]", - "//ldml/personNames/sampleName[@item=\"nativeFull\"]/nameField[@type=\"given2\"]", - "//ldml/personNames/sampleName[@item=\"nativeFull\"]/nameField[@type=\"surname-prefix\"]", - "//ldml/personNames/sampleName[@item=\"nativeFull\"]/nameField[@type=\"surname-core\"]", - "//ldml/personNames/sampleName[@item=\"nativeFull\"]/nameField[@type=\"surname2\"]", - "//ldml/personNames/sampleName[@item=\"nativeFull\"]/nameField[@type=\"generation\"]", - "//ldml/personNames/sampleName[@item=\"nativeFull\"]/nameField[@type=\"credentials\"]", - "//ldml/personNames/sampleName[@item=\"foreignG\"]/nameField[@type=\"given\"]", - "//ldml/personNames/sampleName[@item=\"foreignGS\"]/nameField[@type=\"given\"]", - "//ldml/personNames/sampleName[@item=\"foreignGS\"]/nameField[@type=\"surname\"]", - "//ldml/personNames/sampleName[@item=\"foreignGGS\"]/nameField[@type=\"given\"]", - "//ldml/personNames/sampleName[@item=\"foreignGGS\"]/nameField[@type=\"given2\"]", - "//ldml/personNames/sampleName[@item=\"foreignGGS\"]/nameField[@type=\"surname\"]", - "//ldml/personNames/sampleName[@item=\"foreignFull\"]/nameField[@type=\"title\"]", - "//ldml/personNames/sampleName[@item=\"foreignFull\"]/nameField[@type=\"given\"]", - "//ldml/personNames/sampleName[@item=\"foreignFull\"]/nameField[@type=\"given-informal\"]", - "//ldml/personNames/sampleName[@item=\"foreignFull\"]/nameField[@type=\"given2\"]", - "//ldml/personNames/sampleName[@item=\"foreignFull\"]/nameField[@type=\"surname-prefix\"]", - "//ldml/personNames/sampleName[@item=\"foreignFull\"]/nameField[@type=\"surname-core\"]", - "//ldml/personNames/sampleName[@item=\"foreignFull\"]/nameField[@type=\"surname2\"]", - "//ldml/personNames/sampleName[@item=\"foreignFull\"]/nameField[@type=\"generation\"]", - "//ldml/personNames/sampleName[@item=\"foreignFull\"]/nameField[@type=\"credentials\"]" - ); + * A set of paths to be added to getRawExtraPaths(). These are constant across locales, and + * don't have good fallback values in root. NOTE: if this is changed, you'll need to modify + * TestPaths.extraPathAllowsNullValue + */ + static final Set CONST_EXTRA_PATHS = + ImmutableSet.of( + // Individual zone overrides — were in getRawExtraPaths + "//ldml/dates/timeZoneNames/zone[@type=\"Pacific/Honolulu\"]/short/generic", + "//ldml/dates/timeZoneNames/zone[@type=\"Pacific/Honolulu\"]/short/standard", + "//ldml/dates/timeZoneNames/zone[@type=\"Pacific/Honolulu\"]/short/daylight", + "//ldml/dates/timeZoneNames/zone[@type=\"Europe/Dublin\"]/long/daylight", + "//ldml/dates/timeZoneNames/zone[@type=\"Europe/London\"]/long/daylight", + "//ldml/dates/timeZoneNames/zone[@type=\"Etc/UTC\"]/long/standard", + "//ldml/dates/timeZoneNames/zone[@type=\"Etc/UTC\"]/short/standard", + // Person name paths + "//ldml/personNames/sampleName[@item=\"nativeG\"]/nameField[@type=\"given\"]", + "//ldml/personNames/sampleName[@item=\"nativeGS\"]/nameField[@type=\"given\"]", + "//ldml/personNames/sampleName[@item=\"nativeGS\"]/nameField[@type=\"surname\"]", + "//ldml/personNames/sampleName[@item=\"nativeGGS\"]/nameField[@type=\"given\"]", + "//ldml/personNames/sampleName[@item=\"nativeGGS\"]/nameField[@type=\"given2\"]", + "//ldml/personNames/sampleName[@item=\"nativeGGS\"]/nameField[@type=\"surname\"]", + "//ldml/personNames/sampleName[@item=\"nativeFull\"]/nameField[@type=\"title\"]", + "//ldml/personNames/sampleName[@item=\"nativeFull\"]/nameField[@type=\"given\"]", + "//ldml/personNames/sampleName[@item=\"nativeFull\"]/nameField[@type=\"given-informal\"]", + "//ldml/personNames/sampleName[@item=\"nativeFull\"]/nameField[@type=\"given2\"]", + "//ldml/personNames/sampleName[@item=\"nativeFull\"]/nameField[@type=\"surname-prefix\"]", + "//ldml/personNames/sampleName[@item=\"nativeFull\"]/nameField[@type=\"surname-core\"]", + "//ldml/personNames/sampleName[@item=\"nativeFull\"]/nameField[@type=\"surname2\"]", + "//ldml/personNames/sampleName[@item=\"nativeFull\"]/nameField[@type=\"generation\"]", + "//ldml/personNames/sampleName[@item=\"nativeFull\"]/nameField[@type=\"credentials\"]", + "//ldml/personNames/sampleName[@item=\"foreignG\"]/nameField[@type=\"given\"]", + "//ldml/personNames/sampleName[@item=\"foreignGS\"]/nameField[@type=\"given\"]", + "//ldml/personNames/sampleName[@item=\"foreignGS\"]/nameField[@type=\"surname\"]", + "//ldml/personNames/sampleName[@item=\"foreignGGS\"]/nameField[@type=\"given\"]", + "//ldml/personNames/sampleName[@item=\"foreignGGS\"]/nameField[@type=\"given2\"]", + "//ldml/personNames/sampleName[@item=\"foreignGGS\"]/nameField[@type=\"surname\"]", + "//ldml/personNames/sampleName[@item=\"foreignFull\"]/nameField[@type=\"title\"]", + "//ldml/personNames/sampleName[@item=\"foreignFull\"]/nameField[@type=\"given\"]", + "//ldml/personNames/sampleName[@item=\"foreignFull\"]/nameField[@type=\"given-informal\"]", + "//ldml/personNames/sampleName[@item=\"foreignFull\"]/nameField[@type=\"given2\"]", + "//ldml/personNames/sampleName[@item=\"foreignFull\"]/nameField[@type=\"surname-prefix\"]", + "//ldml/personNames/sampleName[@item=\"foreignFull\"]/nameField[@type=\"surname-core\"]", + "//ldml/personNames/sampleName[@item=\"foreignFull\"]/nameField[@type=\"surname2\"]", + "//ldml/personNames/sampleName[@item=\"foreignFull\"]/nameField[@type=\"generation\"]", + "//ldml/personNames/sampleName[@item=\"foreignFull\"]/nameField[@type=\"credentials\"]"); } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/XMLSource.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/XMLSource.java index 5e070e7fe83..e8542fa4614 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/XMLSource.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/XMLSource.java @@ -7,6 +7,11 @@ package org.unicode.cldr.util; +import com.google.common.collect.Iterators; +import com.ibm.icu.impl.Utility; +import com.ibm.icu.util.Freezable; +import com.ibm.icu.util.Output; +import com.ibm.icu.util.VersionInfo; import java.io.File; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -25,17 +30,10 @@ import java.util.WeakHashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; - import org.unicode.cldr.util.CLDRFile.DraftStatus; import org.unicode.cldr.util.XPathParts.Comments; import org.xml.sax.Locator; -import com.google.common.collect.Iterators; -import com.ibm.icu.impl.Utility; -import com.ibm.icu.util.Freezable; -import com.ibm.icu.util.Output; -import com.ibm.icu.util.VersionInfo; - /** * Overall process is described in * http://cldr.unicode.org/development/development-process/design-proposals/resolution-of-cldr-files @@ -57,22 +55,22 @@ public abstract class XMLSource implements Freezable, IterableMaybe we could clean up #2 and #3 when reading in a CLDRFile the first time? * * @param oldPath * @param relativePath @@ -414,17 +403,19 @@ public static String stripLastElement(String oldPath) { @Override public String toString() { - return - "newLocaleID: " + newLocaleID + ",\t" - + - "oldPath: " + oldPath + ",\n\t" - + - "newPath: " + newPath; + return "newLocaleID: " + + newLocaleID + + ",\t" + + "oldPath: " + + oldPath + + ",\n\t" + + "newPath: " + + newPath; } /** - * This function is called on the full path, when we know the distinguishing path matches the oldPath. - * So we just want to modify the base of the path + * This function is called on the full path, when we know the distinguishing path matches + * the oldPath. So we just want to modify the base of the path * * @param oldPath * @param newPath @@ -445,7 +436,7 @@ public String changeNewToOld(String fullPath, String newPath, String oldPath) { Map attributesFull = partsFull.getAttributes(-1); Map attributesNew = partsNew.getAttributes(-1); Map attributesOld = partsOld.getAttributes(-1); - for (Iterator it = attributesFull.keySet().iterator(); it.hasNext();) { + for (Iterator it = attributesFull.keySet().iterator(); it.hasNext(); ) { String attribute = it.next(); if (attributesNew.containsKey(attribute)) continue; attributesOld.put(attribute, attributesFull.get(attribute)); @@ -486,8 +477,8 @@ public static boolean isAliasPath(String path) { /** * This method should be overridden. * - * @return a mapping of paths to their aliases. Note that since root is the - * only locale to have aliases, all other locales will have no mappings. + * @return a mapping of paths to their aliases. Note that since root is the only locale to have + * aliases, all other locales will have no mappings. */ protected synchronized TreeMap getAliases() { if (!cachingIsEnabled) { @@ -508,10 +499,9 @@ protected synchronized TreeMap getAliases() { } /** - * Look for aliases and create mappings for them. - * Aliases are only ever found in root. + * Look for aliases and create mappings for them. Aliases are only ever found in root. * - * return aliasMap the new map + *

return aliasMap the new map */ private TreeMap loadAliases() { TreeMap aliasMap = new TreeMap<>(); @@ -548,7 +538,8 @@ private LinkedHashMap> getReverseAliases() { list.add(entry.getKey()); } // Sort map. - LinkedHashMap> reverseAliasMap = new LinkedHashMap<>(new TreeMap<>(reverse)); + LinkedHashMap> reverseAliasMap = + new LinkedHashMap<>(new TreeMap<>(reverse)); if (cachingIsEnabled) { reverseAliasCache = reverseAliasMap; } @@ -558,17 +549,18 @@ private LinkedHashMap> getReverseAliases() { /** * Clear "any internal caches" (or only aliasCache?) for this XMLSource. * - * Called only by XMLSource.putValueAtPath and XMLSource.removeValueAtPath + *

Called only by XMLSource.putValueAtPath and XMLSource.removeValueAtPath * - * Note: this method does not affect other caches: reverseAliasCache, getFullPathAtDPathCache, getSourceLocaleIDCache + *

Note: this method does not affect other caches: reverseAliasCache, + * getFullPathAtDPathCache, getSourceLocaleIDCache */ private void clearCache() { aliasCache = null; } /** - * Return the localeID of the XMLSource where the path was found - * SUBCLASSING: must be overridden in a resolving locale + * Return the localeID of the XMLSource where the path was found SUBCLASSING: must be overridden + * in a resolving locale * * @param path the given path * @param status if not null, to have status.pathWhereFound filled in @@ -582,23 +574,24 @@ public String getSourceLocaleID(String path, CLDRFile.Status status) { } /** - * Same as getSourceLocaleID, with unused parameter skipInheritanceMarker. - * This is defined so that the version for ResolvingSource can be defined and called - * for a ResolvingSource that is declared as an XMLSource. + * Same as getSourceLocaleID, with unused parameter skipInheritanceMarker. This is defined so + * that the version for ResolvingSource can be defined and called for a ResolvingSource that is + * declared as an XMLSource. * * @param path the given path * @param status if not null, to have status.pathWhereFound filled in * @param skipInheritanceMarker ignored * @return the localeID */ - public String getSourceLocaleIdExtended(String path, CLDRFile.Status status, - @SuppressWarnings("unused") boolean skipInheritanceMarker) { + public String getSourceLocaleIdExtended( + String path, + CLDRFile.Status status, + @SuppressWarnings("unused") boolean skipInheritanceMarker) { return getSourceLocaleID(path, status); } /** - * Remove the value. - * SUBCLASSING: must be overridden in a resolving locale + * Remove the value. SUBCLASSING: must be overridden in a resolving locale * * @param xpath */ @@ -609,8 +602,7 @@ public void removeValueAtPath(String xpath) { } /** - * Get the value. - * SUBCLASSING: must be overridden in a resolving locale + * Get the value. SUBCLASSING: must be overridden in a resolving locale * * @param xpath * @return @@ -620,8 +612,8 @@ public String getValueAtPath(String xpath) { } /** - * Get the full path for a distinguishing path - * SUBCLASSING: must be overridden in a resolving locale + * Get the full path for a distinguishing path SUBCLASSING: must be overridden in a resolving + * locale * * @param xpath * @return @@ -631,40 +623,38 @@ public String getFullPath(String xpath) { } /** - * Put the full path for this distinguishing path - * The caller will have processed the path, and only call this with the distinguishing path - * SUBCLASSING: must be overridden + * Put the full path for this distinguishing path The caller will have processed the path, and + * only call this with the distinguishing path SUBCLASSING: must be overridden */ - abstract public void putFullPathAtDPath(String distinguishingXPath, String fullxpath); + public abstract void putFullPathAtDPath(String distinguishingXPath, String fullxpath); /** - * Put the distinguishing path, value. - * The caller will have processed the path, and only call this with the distinguishing path - * SUBCLASSING: must be overridden + * Put the distinguishing path, value. The caller will have processed the path, and only call + * this with the distinguishing path SUBCLASSING: must be overridden */ - abstract public void putValueAtDPath(String distinguishingXPath, String value); + public abstract void putValueAtDPath(String distinguishingXPath, String value); /** - * Remove the path, and the full path, and value corresponding to the path. - * The caller will have processed the path, and only call this with the distinguishing path - * SUBCLASSING: must be overridden + * Remove the path, and the full path, and value corresponding to the path. The caller will have + * processed the path, and only call this with the distinguishing path SUBCLASSING: must be + * overridden */ - abstract public void removeValueAtDPath(String distinguishingXPath); + public abstract void removeValueAtDPath(String distinguishingXPath); /** - * Get the value at the given distinguishing path - * The caller will have processed the path, and only call this with the distinguishing path - * SUBCLASSING: must be overridden + * Get the value at the given distinguishing path The caller will have processed the path, and + * only call this with the distinguishing path SUBCLASSING: must be overridden */ - abstract public String getValueAtDPath(String path); + public abstract String getValueAtDPath(String path); public boolean hasValueAtDPath(String path) { return (getValueAtDPath(path) != null); } /** - * Get the Last-Change Date (if known) when the value was changed. - * SUBCLASSING: may be overridden. defaults to NULL. + * Get the Last-Change Date (if known) when the value was changed. SUBCLASSING: may be + * overridden. defaults to NULL. + * * @return last change date (if known), else null */ public Date getChangeDateAtDPath(String path) { @@ -672,35 +662,32 @@ public Date getChangeDateAtDPath(String path) { } /** - * Get the full path at the given distinguishing path - * The caller will have processed the path, and only call this with the distinguishing path - * SUBCLASSING: must be overridden + * Get the full path at the given distinguishing path The caller will have processed the path, + * and only call this with the distinguishing path SUBCLASSING: must be overridden */ - abstract public String getFullPathAtDPath(String path); + public abstract String getFullPathAtDPath(String path); /** - * Get the comments for the source. - * TODO: integrate the Comments class directly into this class + * Get the comments for the source. TODO: integrate the Comments class directly into this class * SUBCLASSING: must be overridden */ - abstract public Comments getXpathComments(); + public abstract Comments getXpathComments(); /** - * Set the comments for the source. - * TODO: integrate the Comments class directly into this class + * Set the comments for the source. TODO: integrate the Comments class directly into this class * SUBCLASSING: must be overridden */ - abstract public void setXpathComments(Comments comments); + public abstract void setXpathComments(Comments comments); /** * @return an iterator over the distinguished paths */ @Override - abstract public Iterator iterator(); + public abstract Iterator iterator(); /** - * @return an iterator over the distinguished paths that start with the prefix. - * SUBCLASSING: Normally overridden for efficiency + * @return an iterator over the distinguished paths that start with the prefix. SUBCLASSING: + * Normally overridden for efficiency */ public Iterator iterator(String prefix) { if (prefix == null || prefix.length() == 0) return iterator(); @@ -713,24 +700,20 @@ public Iterator iterator(Matcher pathFilter) { } /** - * @return returns whether resolving or not - * SUBCLASSING: Only changed for resolving subclasses + * @return returns whether resolving or not SUBCLASSING: Only changed for resolving subclasses */ public boolean isResolving() { return false; } /** - * Returns the unresolved version of this XMLSource. - * SUBCLASSING: Override in resolving sources. + * Returns the unresolved version of this XMLSource. SUBCLASSING: Override in resolving sources. */ public XMLSource getUnresolving() { return this; } - /** - * SUBCLASSING: must be overridden - */ + /** SUBCLASSING: must be overridden */ @Override public XMLSource cloneAsThawed() { try { @@ -742,32 +725,34 @@ public XMLSource cloneAsThawed() { } } - /** - * for debugging only - */ + /** for debugging only */ @Override public String toString() { StringBuffer result = new StringBuffer(); - for (Iterator it = iterator(); it.hasNext();) { + for (Iterator it = iterator(); it.hasNext(); ) { String path = it.next(); String value = getValueAtDPath(path); String fullpath = getFullPathAtDPath(path); - result.append(fullpath).append(" =\t ").append(value).append(CldrUtility.LINE_SEPARATOR); + result.append(fullpath) + .append(" =\t ") + .append(value) + .append(CldrUtility.LINE_SEPARATOR); } return result.toString(); } - /** - * for debugging only - */ + /** for debugging only */ public String toString(String regex) { Matcher matcher = PatternCache.get(regex).matcher(""); StringBuffer result = new StringBuffer(); - for (Iterator it = iterator(matcher); it.hasNext();) { + for (Iterator it = iterator(matcher); it.hasNext(); ) { String path = it.next(); String value = getValueAtDPath(path); String fullpath = getFullPathAtDPath(path); - result.append(fullpath).append(" =\t ").append(value).append(CldrUtility.LINE_SEPARATOR); + result.append(fullpath) + .append(" =\t ") + .append(value) + .append(CldrUtility.LINE_SEPARATOR); } return result.toString(); } @@ -791,7 +776,6 @@ public void setNonInheriting(boolean nonInheriting) { * Internal class for doing resolution * * @author davis - * */ public static class ResolvingSource extends XMLSource implements Listener { private XMLSource currentSource; @@ -822,9 +806,16 @@ public String getValueAtDPath(String xpath) { if (DEBUG_PATH != null && DEBUG_PATH.matcher(xpath).find()) { System.out.println("Getting value for Path: " + xpath); } - if (TRACE_VALUE) System.out.println("\t*xpath: " + xpath - + CldrUtility.LINE_SEPARATOR + "\t*source: " + currentSource.getClass().getName() - + CldrUtility.LINE_SEPARATOR + "\t*locale: " + currentSource.getLocaleID()); + if (TRACE_VALUE) + System.out.println( + "\t*xpath: " + + xpath + + CldrUtility.LINE_SEPARATOR + + "\t*source: " + + currentSource.getClass().getName() + + CldrUtility.LINE_SEPARATOR + + "\t*locale: " + + currentSource.getLocaleID()); String result = null; AliasLocation fullStatus = getCachedFullStatus(xpath, true /* skipInheritanceMarker */); if (fullStatus != null) { @@ -845,7 +836,9 @@ public SourceLocation getSourceLocation(String xpath) { // getCachedFullStatus wants a dPath AliasLocation fullStatus = getCachedFullStatus(dPath, true /* skipInheritanceMarker */); if (fullStatus != null) { - result = getSource(fullStatus).getSourceLocation(xpath); // getSourceLocation wants fullpath + result = + getSource(fullStatus) + .getSourceLocation(xpath); // getSourceLocation wants fullpath } return result; } @@ -868,7 +861,8 @@ public String getFullPathAtDPath(String xpath) { // and add them into the requested path. AliasLocation fullStatus = getCachedFullStatus(xpath, true /* skipInheritanceMarker */); if (fullStatus != null) { - String fullPathWhereFound = getSource(fullStatus).getFullPathAtDPath(fullStatus.pathWhereFound); + String fullPathWhereFound = + getSource(fullStatus).getFullPathAtDPath(fullStatus.pathWhereFound); if (fullPathWhereFound == null) { result = null; } else if (fullPathWhereFound.equals(fullStatus.pathWhereFound)) { @@ -893,18 +887,24 @@ public Date getChangeDateAtDPath(String xpath) { return result; } - private String getFullPath(String xpath, AliasLocation fullStatus, String fullPathWhereFound) { + private String getFullPath( + String xpath, AliasLocation fullStatus, String fullPathWhereFound) { String result = null; if (this.cachingIsEnabled) { result = getFullPathAtDPathCache.get(xpath); } if (result == null) { // find the differences, and add them into xpath - // we do this by walking through each element, adding the corresponding attribute values. + // we do this by walking through each element, adding the corresponding attribute + // values. // we add attributes FROM THE END, in case the lengths are different! - XPathParts xpathParts = XPathParts.getFrozenInstance(xpath).cloneAsThawed(); // not frozen, for putAttributeValue - XPathParts fullPathWhereFoundParts = XPathParts.getFrozenInstance(fullPathWhereFound); - XPathParts pathWhereFoundParts = XPathParts.getFrozenInstance(fullStatus.pathWhereFound); + XPathParts xpathParts = + XPathParts.getFrozenInstance(xpath) + .cloneAsThawed(); // not frozen, for putAttributeValue + XPathParts fullPathWhereFoundParts = + XPathParts.getFrozenInstance(fullPathWhereFound); + XPathParts pathWhereFoundParts = + XPathParts.getFrozenInstance(fullStatus.pathWhereFound); int offset = xpathParts.size() - pathWhereFoundParts.size(); for (int i = 0; i < pathWhereFoundParts.size(); ++i) { @@ -928,9 +928,10 @@ private String getFullPath(String xpath, AliasLocation fullStatus, String fullPa } /** - * Return the "George Bailey" value, i.e., the value that would obtain if the value didn't exist (in the first source). - * Often the Bailey value comes from the parent locale (such as "fr") of a sublocale (such as "fr_CA"). - * Sometimes the Bailey value comes from an alias which may be a different path in the same locale. + * Return the "George Bailey" value, i.e., the value that would obtain if the value didn't + * exist (in the first source). Often the Bailey value comes from the parent locale (such as + * "fr") of a sublocale (such as "fr_CA"). Sometimes the Bailey value comes from an alias + * which may be a different path in the same locale. * * @param xpath the given path * @param pathWhereFound if not null, to be filled in with the path where found @@ -938,8 +939,10 @@ private String getFullPath(String xpath, AliasLocation fullStatus, String fullPa * @return the Bailey value */ @Override - public String getBaileyValue(String xpath, Output pathWhereFound, Output localeWhereFound) { - AliasLocation fullStatus = getPathLocation(xpath, true /* skipFirst */, true /* skipInheritanceMarker */); + public String getBaileyValue( + String xpath, Output pathWhereFound, Output localeWhereFound) { + AliasLocation fullStatus = + getPathLocation(xpath, true /* skipFirst */, true /* skipInheritanceMarker */); if (localeWhereFound != null) { localeWhereFound.value = fullStatus.localeWhereFound; } @@ -969,16 +972,18 @@ private AliasLocation getCachedFullStatus(String xpath, boolean skipInheritanceM * There is no caching problem with skipFirst, since that is always false here -- though * getBaileyValue could use a cache if there was one for skipFirst true. */ - if (!skipInheritanceMarker || !cachingIsEnabled ) { + if (!skipInheritanceMarker || !cachingIsEnabled) { return getPathLocation(xpath, false /* skipFirst */, skipInheritanceMarker); } synchronized (getSourceLocaleIDCache) { AliasLocation fullStatus = getSourceLocaleIDCache.get(xpath); if (fullStatus == null) { -// if (xpath.equals("//ldml/localeDisplayNames/languages/language[@type=\"ug\"][@alt=\"variant\"]")) { -// int debug = 0; -// } - fullStatus = getPathLocation(xpath, false /* skipFirst */, skipInheritanceMarker); + // if + // (xpath.equals("//ldml/localeDisplayNames/languages/language[@type=\"ug\"][@alt=\"variant\"]")) { + // int debug = 0; + // } + fullStatus = + getPathLocation(xpath, false /* skipFirst */, skipInheritanceMarker); getSourceLocaleIDCache.put(xpath, fullStatus); // cache copy } return fullStatus; @@ -1009,12 +1014,13 @@ public String getWinningPath(String xpath) { */ @Override public String getSourceLocaleID(String distinguishedXPath, CLDRFile.Status status) { - return getSourceLocaleIdExtended(distinguishedXPath, status, true /* skipInheritanceMarker */); + return getSourceLocaleIdExtended( + distinguishedXPath, status, true /* skipInheritanceMarker */); } /** - * Same as ResolvingSource.getSourceLocaleID, with additional parameter skipInheritanceMarker, - * which is passed on to getCachedFullStatus and getPathLocation. + * Same as ResolvingSource.getSourceLocaleID, with additional parameter + * skipInheritanceMarker, which is passed on to getCachedFullStatus and getPathLocation. * * @param distinguishedXPath the given path * @param status if not null, to have status.pathWhereFound filled in @@ -1022,8 +1028,10 @@ public String getSourceLocaleID(String distinguishedXPath, CLDRFile.Status statu * @return the localeID, as a string */ @Override - public String getSourceLocaleIdExtended(String distinguishedXPath, CLDRFile.Status status, boolean skipInheritanceMarker) { - AliasLocation fullStatus = getCachedFullStatus(distinguishedXPath, skipInheritanceMarker); + public String getSourceLocaleIdExtended( + String distinguishedXPath, CLDRFile.Status status, boolean skipInheritanceMarker) { + AliasLocation fullStatus = + getCachedFullStatus(distinguishedXPath, skipInheritanceMarker); if (status != null) { status.pathWhereFound = fullStatus.pathWhereFound; } @@ -1033,33 +1041,33 @@ public String getSourceLocaleIdExtended(String distinguishedXPath, CLDRFile.Stat static final Pattern COUNT_EQUALS = PatternCache.get("\\[@count=\"[^\"]*\"]"); /** - * Get the AliasLocation, containing path and locale where found, for the given path, for this ResolvingSource. + * Get the AliasLocation, containing path and locale where found, for the given path, for + * this ResolvingSource. * * @param xpath the given path - * @param skipFirst true if we're getting the Bailey value (caller is getBaileyValue), - * else false (caller is getCachedFullStatus) + * @param skipFirst true if we're getting the Bailey value (caller is getBaileyValue), else + * false (caller is getCachedFullStatus) * @param skipInheritanceMarker if true, skip sources in which value is INHERITANCE_MARKER * @return the AliasLocation - * - * skipInheritanceMarker must be true when the caller is getBaileyValue, so that the caller - * will not return INHERITANCE_MARKER as the George Bailey value. When the caller is getMissingStatus, - * we're not getting the Bailey value, and skipping INHERITANCE_MARKER here could take us up - * to "root", which getMissingStatus would misinterpret to mean the item should be listed under - * Missing in the Dashboard. Therefore skipInheritanceMarker needs to be false when getMissingStatus - * is the caller. Note that we get INHERITANCE_MARKER when there are votes for inheritance, but when - * there are no votes getValueAtDPath returns null so we don't get INHERITANCE_MARKER. - * - * Situation for CheckCoverage.handleCheck may be similar to getMissingStatus, see ticket 11720. - * - * For other callers, we stick with skipInheritanceMarker true for now, to retain - * the behavior before the skipInheritanceMarker parameter was added, but we should be alert for the - * possibility that skipInheritanceMarker should be false in some other cases - * - * References: https://unicode.org/cldr/trac/ticket/11765 - * https://unicode.org/cldr/trac/ticket/11720 - * https://unicode.org/cldr/trac/ticket/11103 + *

skipInheritanceMarker must be true when the caller is getBaileyValue, so that the + * caller will not return INHERITANCE_MARKER as the George Bailey value. When the caller + * is getMissingStatus, we're not getting the Bailey value, and skipping + * INHERITANCE_MARKER here could take us up to "root", which getMissingStatus would + * misinterpret to mean the item should be listed under Missing in the Dashboard. + * Therefore skipInheritanceMarker needs to be false when getMissingStatus is the + * caller. Note that we get INHERITANCE_MARKER when there are votes for inheritance, but + * when there are no votes getValueAtDPath returns null so we don't get + * INHERITANCE_MARKER. + *

Situation for CheckCoverage.handleCheck may be similar to getMissingStatus, see + * ticket 11720. + *

For other callers, we stick with skipInheritanceMarker true for now, to retain the + * behavior before the skipInheritanceMarker parameter was added, but we should be alert + * for the possibility that skipInheritanceMarker should be false in some other cases + *

References: https://unicode.org/cldr/trac/ticket/11765 + * https://unicode.org/cldr/trac/ticket/11720 https://unicode.org/cldr/trac/ticket/11103 */ - private AliasLocation getPathLocation(String xpath, boolean skipFirst, boolean skipInheritanceMarker) { + private AliasLocation getPathLocation( + String xpath, boolean skipFirst, boolean skipInheritanceMarker) { boolean debugPath = DEBUG_PATH != null && DEBUG_PATH.matcher(xpath).matches(); for (XMLSource source : sources.values()) { if (skipFirst) { @@ -1072,7 +1080,8 @@ private AliasLocation getPathLocation(String xpath, boolean skipFirst, boolean s continue; } if (debugPath) { - System.out.println("found: " + source.getLocaleID() + " " + xpath + " " + value); + System.out.println( + "found: " + source.getLocaleID() + " " + xpath + " " + value); } return new AliasLocation(xpath, source.getLocaleID()); } @@ -1087,17 +1096,18 @@ private AliasLocation getPathLocation(String xpath, boolean skipFirst, boolean s // return the alias with the longest matching prefix since the // hashmap is sorted according to xpath. -// // The following is a work in progress -// // We need to recurse, since we might have a chain of aliases -// while (true) { - String possibleSubpath = aliases.lowerKey(xpath); - if (possibleSubpath != null && xpath.startsWith(possibleSubpath)) { - aliasedPath = aliases.get(possibleSubpath) + - xpath.substring(possibleSubpath.length()); -// xpath = aliasedPath; -// } else { -// break; -// } + // // The following is a work in progress + // // We need to recurse, since we might have a chain of aliases + // while (true) { + String possibleSubpath = aliases.lowerKey(xpath); + if (possibleSubpath != null && xpath.startsWith(possibleSubpath)) { + aliasedPath = + aliases.get(possibleSubpath) + + xpath.substring(possibleSubpath.length()); + // xpath = aliasedPath; + // } else { + // break; + // } } } @@ -1108,7 +1118,8 @@ private AliasLocation getPathLocation(String xpath, boolean skipFirst, boolean s // counts are special; they act like there is a root alias to 'other' // and in the special case of currencies, other => null - // //ldml/numbers/currencies/currency[@type="BRZ"]/displayName[@count="other"] => //ldml/numbers/currencies/currency[@type="BRZ"]/displayName + // //ldml/numbers/currencies/currency[@type="BRZ"]/displayName[@count="other"] => + // //ldml/numbers/currencies/currency[@type="BRZ"]/displayName if (aliasedPath == null && xpath.contains("[@count=")) { aliasedPath = COUNT_EQUALS.matcher(xpath).replaceAll("[@count=\"other\"]"); if (aliasedPath.equals(xpath)) { @@ -1133,12 +1144,14 @@ private AliasLocation getPathLocation(String xpath, boolean skipFirst, boolean s } /** - * We have to go through the source, add all the paths, then recurse to parents - * However, aliases are tricky, so watch it. + * We have to go through the source, add all the paths, then recurse to parents However, + * aliases are tricky, so watch it. */ static final boolean TRACE_FILL = CldrUtility.getProperty("TRACE_FILL", false); + static final String DEBUG_PATH_STRING = CldrUtility.getProperty("DEBUG_PATH", null); - static final Pattern DEBUG_PATH = DEBUG_PATH_STRING == null ? null : PatternCache.get(DEBUG_PATH_STRING); + static final Pattern DEBUG_PATH = + DEBUG_PATH_STRING == null ? null : PatternCache.get(DEBUG_PATH_STRING); static final boolean SKIP_FALLBACKID = CldrUtility.getProperty("SKIP_FALLBACKID", false); static final int MAX_LEVEL = 40; /* Throw an error if it goes past this. */ @@ -1146,9 +1159,8 @@ private AliasLocation getPathLocation(String xpath, boolean skipFirst, boolean s /** * Initialises the set of xpaths that a fully resolved XMLSource contains. * http://cldr.unicode.org/development/development-process/design-proposals/resolution-of-cldr-files. - * Information about the aliased path and source locale ID of each xpath - * is not precalculated here since it doesn't appear to improve overall - * performance. + * Information about the aliased path and source locale ID of each xpath is not + * precalculated here since it doesn't appear to improve overall performance. */ private Set fillKeys() { Set paths = findNonAliasedPaths(); @@ -1159,9 +1171,12 @@ private Set fillKeys() { do { // Debugging code to protect against an infinite loop. if (TRACE_FILL && DEBUG_PATH == null || level > MAX_LEVEL) { - System.out.println(Utility.repeat(TRACE_INDENT, level) + "# paths waiting to be aliased: " - + newPaths.size()); - System.out.println(Utility.repeat(TRACE_INDENT, level) + "# paths found: " + paths.size()); + System.out.println( + Utility.repeat(TRACE_INDENT, level) + + "# paths waiting to be aliased: " + + newPaths.size()); + System.out.println( + Utility.repeat(TRACE_INDENT, level) + "# paths found: " + paths.size()); } if (level > MAX_LEVEL) throw new IllegalArgumentException("Stack overflow"); @@ -1177,8 +1192,7 @@ private Set fillKeys() { } /** - * Creates the set of resolved paths for this ResolvingSource while - * ignoring aliasing. + * Creates the set of resolved paths for this ResolvingSource while ignoring aliasing. * * @return */ @@ -1191,7 +1205,8 @@ private Set findNonAliasedPaths() { sourceList.add(constructedItems); } - // Make a pass through, filling all the direct paths, excluding aliases, and collecting others + // Make a pass through, filling all the direct paths, excluding aliases, and collecting + // others for (XMLSource curSource : sourceList) { for (String xpath : curSource) { paths.add(xpath); @@ -1201,8 +1216,8 @@ private Set findNonAliasedPaths() { } /** - * Takes in a list of xpaths and returns a new set of paths that alias - * directly to those existing xpaths. + * Takes in a list of xpaths and returns a new set of paths that alias directly to those + * existing xpaths. * * @param paths a sorted list of xpaths * @return the new set of paths @@ -1215,8 +1230,7 @@ private Set getDirectAliases(String[] paths) { LinkedHashMap> reverseAliases = getReverseAliases(); for (String subpath : reverseAliases.keySet()) { // Find the first path that matches the current alias. - while (pathIndex < paths.length && - paths[pathIndex].compareTo(subpath) < 0) { + while (pathIndex < paths.length && paths[pathIndex].compareTo(subpath) < 0) { pathIndex++; } @@ -1227,9 +1241,9 @@ private Set getDirectAliases(String[] paths) { int suffixStart = subpath.length(); // Suffixes should always start with an element and not an // attribute to prevent invalid aliasing. - while (endIndex < paths.length && - (xpath = paths[endIndex]).startsWith(subpath) && - xpath.charAt(suffixStart) == '/') { + while (endIndex < paths.length + && (xpath = paths[endIndex]).startsWith(subpath) + && xpath.charAt(suffixStart) == '/') { String suffix = xpath.substring(suffixStart); for (String reverseAlias : list) { String reversePath = reverseAlias + suffix; @@ -1308,7 +1322,7 @@ public void valueChanged(String xpath, XMLSource nonResolvingSource) { // so clear them as well. // There's probably a more elegant way to fix the paths than simply // throwing everything out. - Set dependentPaths = getDirectAliases(new String[] { xpath }); + Set dependentPaths = getDirectAliases(new String[] {xpath}); if (dependentPaths.size() > 0) { for (String path : dependentPaths) { getSourceLocaleIDCache.remove(path); @@ -1320,13 +1334,13 @@ public void valueChanged(String xpath, XMLSource nonResolvingSource) { /** * Creates a new ResolvingSource with the given locale resolution chain. * - * @param sourceList - * the list of XMLSources to look in during resolution, - * ordered from the current locale up to root. + * @param sourceList the list of XMLSources to look in during resolution, ordered from the + * current locale up to root. */ public ResolvingSource(List sourceList) { // Sanity check for root. - if (sourceList == null || !sourceList.get(sourceList.size() - 1).getLocaleID().equals("root")) { + if (sourceList == null + || !sourceList.get(sourceList.size() - 1).getLocaleID().equals("root")) { throw new IllegalArgumentException("Last element should be root"); } currentSource = sourceList.get(0); // Convenience variable @@ -1348,145 +1362,139 @@ public String getLocaleID() { } private static final String[] keyDisplayNames = { - "calendar", - "cf", - "collation", - "currency", - "hc", - "lb", - "ms", - "numbers" + "calendar", "cf", "collation", "currency", "hc", "lb", "ms", "numbers" }; private static final String[][] typeDisplayNames = { - { "account", "cf" }, - { "ahom", "numbers" }, - { "arab", "numbers" }, - { "arabext", "numbers" }, - { "armn", "numbers" }, - { "armnlow", "numbers" }, - { "bali", "numbers" }, - { "beng", "numbers" }, - { "big5han", "collation" }, - { "brah", "numbers" }, - { "buddhist", "calendar" }, - { "cakm", "numbers" }, - { "cham", "numbers" }, - { "chinese", "calendar" }, - { "compat", "collation" }, - { "coptic", "calendar" }, - { "cyrl", "numbers" }, - { "dangi", "calendar" }, - { "deva", "numbers" }, - { "diak", "numbers" }, - { "dictionary", "collation" }, - { "ducet", "collation" }, - { "emoji", "collation" }, - { "eor", "collation" }, - { "ethi", "numbers" }, - { "ethiopic", "calendar" }, - { "ethiopic-amete-alem", "calendar" }, - { "fullwide", "numbers" }, - { "gb2312han", "collation" }, - { "geor", "numbers" }, - { "gong", "numbers" }, - { "gonm", "numbers" }, - { "gregorian", "calendar" }, - { "grek", "numbers" }, - { "greklow", "numbers" }, - { "gujr", "numbers" }, - { "guru", "numbers" }, - { "h11", "hc" }, - { "h12", "hc" }, - { "h23", "hc" }, - { "h24", "hc" }, - { "hanidec", "numbers" }, - { "hans", "numbers" }, - { "hansfin", "numbers" }, - { "hant", "numbers" }, - { "hantfin", "numbers" }, - { "hebr", "numbers" }, - { "hebrew", "calendar" }, - { "hmng", "numbers" }, - { "hmnp", "numbers" }, - { "indian", "calendar" }, - { "islamic", "calendar" }, - { "islamic-civil", "calendar" }, - { "islamic-rgsa", "calendar" }, - { "islamic-tbla", "calendar" }, - { "islamic-umalqura", "calendar" }, - { "iso8601", "calendar" }, - { "japanese", "calendar" }, - { "java", "numbers" }, - { "jpan", "numbers" }, - { "jpanfin", "numbers" }, - { "kali", "numbers" }, - { "kawi", "numbers" }, - { "khmr", "numbers" }, - { "knda", "numbers" }, - { "lana", "numbers" }, - { "lanatham", "numbers" }, - { "laoo", "numbers" }, - { "latn", "numbers" }, - { "lepc", "numbers" }, - { "limb", "numbers" }, - { "loose", "lb" }, - { "mathbold", "numbers" }, - { "mathdbl", "numbers" }, - { "mathmono", "numbers" }, - { "mathsanb", "numbers" }, - { "mathsans", "numbers" }, - { "metric", "ms" }, - { "mlym", "numbers" }, - { "modi", "numbers" }, - { "mong", "numbers" }, - { "mroo", "numbers" }, - { "mtei", "numbers" }, - { "mymr", "numbers" }, - { "mymrshan", "numbers" }, - { "mymrtlng", "numbers" }, - { "nagm", "numbers" }, - { "nkoo", "numbers" }, - { "normal", "lb" }, - { "olck", "numbers" }, - { "orya", "numbers" }, - { "osma", "numbers" }, - { "persian", "calendar" }, - { "phonebook", "collation" }, - { "pinyin", "collation" }, - { "reformed", "collation" }, - { "roc", "calendar" }, - { "rohg", "numbers" }, - { "roman", "numbers" }, - { "romanlow", "numbers" }, - { "saur", "numbers" }, - { "search", "collation" }, - { "searchjl", "collation" }, - { "shrd", "numbers" }, - { "sind", "numbers" }, - { "sinh", "numbers" }, - { "sora", "numbers" }, - { "standard", "cf" }, - { "standard", "collation" }, - { "strict", "lb" }, - { "stroke", "collation" }, - { "sund", "numbers" }, - { "takr", "numbers" }, - { "talu", "numbers" }, - { "taml", "numbers" }, - { "tamldec", "numbers" }, - { "tnsa", "numbers" }, - { "telu", "numbers" }, - { "thai", "numbers" }, - { "tibt", "numbers" }, - { "tirh", "numbers" }, - { "traditional", "collation" }, - { "unihan", "collation" }, - { "uksystem", "ms" }, - { "ussystem", "ms" }, - { "vaii", "numbers" }, - { "wara", "numbers" }, - { "wcho", "numbers" }, - { "zhuyin", "collation" } }; + {"account", "cf"}, + {"ahom", "numbers"}, + {"arab", "numbers"}, + {"arabext", "numbers"}, + {"armn", "numbers"}, + {"armnlow", "numbers"}, + {"bali", "numbers"}, + {"beng", "numbers"}, + {"big5han", "collation"}, + {"brah", "numbers"}, + {"buddhist", "calendar"}, + {"cakm", "numbers"}, + {"cham", "numbers"}, + {"chinese", "calendar"}, + {"compat", "collation"}, + {"coptic", "calendar"}, + {"cyrl", "numbers"}, + {"dangi", "calendar"}, + {"deva", "numbers"}, + {"diak", "numbers"}, + {"dictionary", "collation"}, + {"ducet", "collation"}, + {"emoji", "collation"}, + {"eor", "collation"}, + {"ethi", "numbers"}, + {"ethiopic", "calendar"}, + {"ethiopic-amete-alem", "calendar"}, + {"fullwide", "numbers"}, + {"gb2312han", "collation"}, + {"geor", "numbers"}, + {"gong", "numbers"}, + {"gonm", "numbers"}, + {"gregorian", "calendar"}, + {"grek", "numbers"}, + {"greklow", "numbers"}, + {"gujr", "numbers"}, + {"guru", "numbers"}, + {"h11", "hc"}, + {"h12", "hc"}, + {"h23", "hc"}, + {"h24", "hc"}, + {"hanidec", "numbers"}, + {"hans", "numbers"}, + {"hansfin", "numbers"}, + {"hant", "numbers"}, + {"hantfin", "numbers"}, + {"hebr", "numbers"}, + {"hebrew", "calendar"}, + {"hmng", "numbers"}, + {"hmnp", "numbers"}, + {"indian", "calendar"}, + {"islamic", "calendar"}, + {"islamic-civil", "calendar"}, + {"islamic-rgsa", "calendar"}, + {"islamic-tbla", "calendar"}, + {"islamic-umalqura", "calendar"}, + {"iso8601", "calendar"}, + {"japanese", "calendar"}, + {"java", "numbers"}, + {"jpan", "numbers"}, + {"jpanfin", "numbers"}, + {"kali", "numbers"}, + {"kawi", "numbers"}, + {"khmr", "numbers"}, + {"knda", "numbers"}, + {"lana", "numbers"}, + {"lanatham", "numbers"}, + {"laoo", "numbers"}, + {"latn", "numbers"}, + {"lepc", "numbers"}, + {"limb", "numbers"}, + {"loose", "lb"}, + {"mathbold", "numbers"}, + {"mathdbl", "numbers"}, + {"mathmono", "numbers"}, + {"mathsanb", "numbers"}, + {"mathsans", "numbers"}, + {"metric", "ms"}, + {"mlym", "numbers"}, + {"modi", "numbers"}, + {"mong", "numbers"}, + {"mroo", "numbers"}, + {"mtei", "numbers"}, + {"mymr", "numbers"}, + {"mymrshan", "numbers"}, + {"mymrtlng", "numbers"}, + {"nagm", "numbers"}, + {"nkoo", "numbers"}, + {"normal", "lb"}, + {"olck", "numbers"}, + {"orya", "numbers"}, + {"osma", "numbers"}, + {"persian", "calendar"}, + {"phonebook", "collation"}, + {"pinyin", "collation"}, + {"reformed", "collation"}, + {"roc", "calendar"}, + {"rohg", "numbers"}, + {"roman", "numbers"}, + {"romanlow", "numbers"}, + {"saur", "numbers"}, + {"search", "collation"}, + {"searchjl", "collation"}, + {"shrd", "numbers"}, + {"sind", "numbers"}, + {"sinh", "numbers"}, + {"sora", "numbers"}, + {"standard", "cf"}, + {"standard", "collation"}, + {"strict", "lb"}, + {"stroke", "collation"}, + {"sund", "numbers"}, + {"takr", "numbers"}, + {"talu", "numbers"}, + {"taml", "numbers"}, + {"tamldec", "numbers"}, + {"tnsa", "numbers"}, + {"telu", "numbers"}, + {"thai", "numbers"}, + {"tibt", "numbers"}, + {"tirh", "numbers"}, + {"traditional", "collation"}, + {"unihan", "collation"}, + {"uksystem", "ms"}, + {"ussystem", "ms"}, + {"vaii", "numbers"}, + {"wara", "numbers"}, + {"wcho", "numbers"}, + {"zhuyin", "collation"} + }; private static final boolean SKIP_SINGLEZONES = false; private static XMLSource constructedItems = new SimpleXMLSource(CODE_FALLBACK_ID); @@ -1498,11 +1506,12 @@ public String getLocaleID() { for (int typeNo = 0; typeNo <= CLDRFile.TZ_START; ++typeNo) { String type = CLDRFile.getNameName(typeNo); - String type2 = (typeNo == CLDRFile.CURRENCY_SYMBOL) ? CLDRFile.getNameName(CLDRFile.CURRENCY_NAME) - : (typeNo >= CLDRFile.TZ_START) ? "tzid" - : type; + String type2 = + (typeNo == CLDRFile.CURRENCY_SYMBOL) + ? CLDRFile.getNameName(CLDRFile.CURRENCY_NAME) + : (typeNo >= CLDRFile.TZ_START) ? "tzid" : type; Set codes = sc.getSurveyToolDisplayCodes(type2); - for (Iterator codeIt = codes.iterator(); codeIt.hasNext();) { + for (Iterator codeIt = codes.iterator(); codeIt.hasNext(); ) { String code = codeIt.next(); String value = code; if (typeNo == CLDRFile.TZ_EXEMPLAR) { // skip single-zone countries @@ -1522,17 +1531,9 @@ public String getLocaleID() { } String[] extraCodes = { - "ar_001", - "de_AT", "de_CH", - "en_AU", "en_CA", "en_GB", "en_US", "es_419", "es_ES", "es_MX", - "fa_AF", "fr_CA", "fr_CH", "frc", - "hi_Latn", - "lou", - "nds_NL", "nl_BE", - "pt_BR", "pt_PT", - "ro_MD", - "sw_CD", - "zh_Hans", "zh_Hant" + "ar_001", "de_AT", "de_CH", "en_AU", "en_CA", "en_GB", "en_US", "es_419", "es_ES", + "es_MX", "fa_AF", "fr_CA", "fr_CH", "frc", "hi_Latn", "lou", "nds_NL", "nl_BE", + "pt_BR", "pt_PT", "ro_MD", "sw_CD", "zh_Hans", "zh_Hant" }; for (String extraCode : extraCodes) { addFallbackCode(CLDRFile.LANGUAGE_NAME, extraCode, extraCode); @@ -1559,7 +1560,8 @@ public String getLocaleID() { addFallbackCode(CLDRFile.TERRITORY_NAME, "PS", "PS", "short"); addFallbackCode(CLDRFile.TERRITORY_NAME, "US", "US", "short"); - addFallbackCode(CLDRFile.TERRITORY_NAME, "CD", "CD", "variant"); // add other geopolitical items + addFallbackCode( + CLDRFile.TERRITORY_NAME, "CD", "CD", "variant"); // add other geopolitical items addFallbackCode(CLDRFile.TERRITORY_NAME, "CG", "CG", "variant"); addFallbackCode(CLDRFile.TERRITORY_NAME, "CI", "CI", "variant"); addFallbackCode(CLDRFile.TERRITORY_NAME, "CZ", "CZ", "variant"); @@ -1572,28 +1574,51 @@ public String getLocaleID() { addFallbackCode(CLDRFile.TERRITORY_NAME, "NZ", "NZ", "variant"); addFallbackCode(CLDRFile.TERRITORY_NAME, "TR", "TR", "variant"); - addFallbackCode(CLDRFile.TERRITORY_NAME, "XA", "XA"); addFallbackCode(CLDRFile.TERRITORY_NAME, "XB", "XB"); - addFallbackCode("//ldml/dates/calendars/calendar[@type=\"gregorian\"]/eras/eraAbbr/era[@type=\"0\"]", "BCE", "variant"); - addFallbackCode("//ldml/dates/calendars/calendar[@type=\"gregorian\"]/eras/eraAbbr/era[@type=\"1\"]", "CE", "variant"); - addFallbackCode("//ldml/dates/calendars/calendar[@type=\"gregorian\"]/eras/eraNames/era[@type=\"0\"]", "BCE", "variant"); - addFallbackCode("//ldml/dates/calendars/calendar[@type=\"gregorian\"]/eras/eraNames/era[@type=\"1\"]", "CE", "variant"); - addFallbackCode("//ldml/dates/calendars/calendar[@type=\"gregorian\"]/eras/eraNarrow/era[@type=\"0\"]", "BCE", "variant"); - addFallbackCode("//ldml/dates/calendars/calendar[@type=\"gregorian\"]/eras/eraNarrow/era[@type=\"1\"]", "CE", "variant"); + addFallbackCode( + "//ldml/dates/calendars/calendar[@type=\"gregorian\"]/eras/eraAbbr/era[@type=\"0\"]", + "BCE", + "variant"); + addFallbackCode( + "//ldml/dates/calendars/calendar[@type=\"gregorian\"]/eras/eraAbbr/era[@type=\"1\"]", + "CE", + "variant"); + addFallbackCode( + "//ldml/dates/calendars/calendar[@type=\"gregorian\"]/eras/eraNames/era[@type=\"0\"]", + "BCE", + "variant"); + addFallbackCode( + "//ldml/dates/calendars/calendar[@type=\"gregorian\"]/eras/eraNames/era[@type=\"1\"]", + "CE", + "variant"); + addFallbackCode( + "//ldml/dates/calendars/calendar[@type=\"gregorian\"]/eras/eraNarrow/era[@type=\"0\"]", + "BCE", + "variant"); + addFallbackCode( + "//ldml/dates/calendars/calendar[@type=\"gregorian\"]/eras/eraNarrow/era[@type=\"1\"]", + "CE", + "variant"); for (int i = 0; i < keyDisplayNames.length; ++i) { constructedItems.putValueAtPath( - "//ldml/localeDisplayNames/keys/key" + - "[@type=\"" + keyDisplayNames[i] + "\"]", + "//ldml/localeDisplayNames/keys/key" + + "[@type=\"" + + keyDisplayNames[i] + + "\"]", keyDisplayNames[i]); } for (int i = 0; i < typeDisplayNames.length; ++i) { constructedItems.putValueAtPath( - "//ldml/localeDisplayNames/types/type" - + "[@key=\"" + typeDisplayNames[i][1] + "\"]" - + "[@type=\"" + typeDisplayNames[i][0] + "\"]", + "//ldml/localeDisplayNames/types/type" + + "[@key=\"" + + typeDisplayNames[i][1] + + "\"]" + + "[@type=\"" + + typeDisplayNames[i][0] + + "\"]", typeDisplayNames[i][0]); } constructedItems.freeze(); @@ -1607,20 +1632,27 @@ private static void addFallbackCode(int typeNo, String code, String value) { private static void addFallbackCode(int typeNo, String code, String value, String alt) { String fullpath = CLDRFile.getKey(typeNo, code); String distinguishingPath = addFallbackCodeToConstructedItems(fullpath, value, alt); - if (typeNo == CLDRFile.LANGUAGE_NAME || typeNo == CLDRFile.SCRIPT_NAME || typeNo == CLDRFile.TERRITORY_NAME) { + if (typeNo == CLDRFile.LANGUAGE_NAME + || typeNo == CLDRFile.SCRIPT_NAME + || typeNo == CLDRFile.TERRITORY_NAME) { allowDuplicates.put(distinguishingPath, code); } } - private static void addFallbackCode(String fullpath, String value, String alt) { // assumes no allowDuplicates for this + private static void addFallbackCode( + String fullpath, String value, String alt) { // assumes no allowDuplicates for this addFallbackCodeToConstructedItems(fullpath, value, alt); // ignore unneeded return value } - private static String addFallbackCodeToConstructedItems(String fullpath, String value, String alt) { + private static String addFallbackCodeToConstructedItems( + String fullpath, String value, String alt) { if (alt != null) { // Insert the @alt= string after the last occurrence of "]" StringBuffer fullpathBuf = new StringBuffer(fullpath); - fullpath = fullpathBuf.insert(fullpathBuf.lastIndexOf("]") + 1, "[@alt=\"" + alt + "\"]").toString(); + fullpath = + fullpathBuf + .insert(fullpathBuf.lastIndexOf("]") + 1, "[@alt=\"" + alt + "\"]") + .toString(); } return constructedItems.putValueAtPath(fullpath, value); } @@ -1706,8 +1738,8 @@ public boolean isWinningPath(String path) { } /** - * See CLDRFile getWinningPath for documentation. - * Default implementation is that it removes draft and [@alt="...proposed..." if possible + * See CLDRFile getWinningPath for documentation. Default implementation is that it removes + * draft and [@alt="...proposed..." if possible * * @param path * @return @@ -1723,9 +1755,7 @@ public String getWinningPath(String path) { return path; } - /** - * Adds a listener to this XML source. - */ + /** Adds a listener to this XML source. */ public void addListener(Listener listener) { listeners.add(new WeakReference<>(listener)); } @@ -1733,8 +1763,7 @@ public void addListener(Listener listener) { /** * Notifies all listeners that the winning value for the given path has changed. * - * @param xpath - * the xpath where the change occurred. + * @param xpath the xpath where the change occurred. */ public void notifyListeners(String xpath) { int i = 0; @@ -1750,9 +1779,8 @@ public void notifyListeners(String xpath) { } /** - * return true if the path in this file (without resolution). Default implementation is to just see if the path has - * a value. - * The resolved source must just test the top level. + * return true if the path in this file (without resolution). Default implementation is to just + * see if the path has a value. The resolved source must just test the top level. * * @param path * @return @@ -1768,14 +1796,16 @@ public boolean isHere(String path) { * @param pathPrefix * @param result */ - public abstract void getPathsWithValue(String valueToMatch, String pathPrefix, Set result); + public abstract void getPathsWithValue( + String valueToMatch, String pathPrefix, Set result); public VersionInfo getDtdVersionInfo() { return null; } @SuppressWarnings("unused") - public String getBaileyValue(String xpath, Output pathWhereFound, Output localeWhereFound) { + public String getBaileyValue( + String xpath, Output pathWhereFound, Output localeWhereFound) { return null; // only a resolving xmlsource will return a value } @@ -1789,10 +1819,9 @@ public DtdType getDtdType() { return null; } - /** - * XMLNormalizingDtdType is set in XMLNormalizingHandler loading XML process - */ + /** XMLNormalizingDtdType is set in XMLNormalizingHandler loading XML process */ private DtdType XMLNormalizingDtdType; + private static final boolean LOG_PROGRESS = false; public DtdType getXMLNormalizingDtdType() { @@ -1804,8 +1833,8 @@ public void setXMLNormalizingDtdType(DtdType dtdType) { } /** - * Sets the initial comment, replacing everything that was there - * Use in XMLNormalizingHandler only + * Sets the initial comment, replacing everything that was there Use in XMLNormalizingHandler + * only */ public XMLSource setInitialComment(String comment) { if (locked) throw new UnsupportedOperationException("Attempt to modify locked object"); @@ -1814,16 +1843,17 @@ public XMLSource setInitialComment(String comment) { return this; } - /** - * Use in XMLNormalizingHandler only - */ + /** Use in XMLNormalizingHandler only */ public XMLSource addComment(String xpath, String comment, Comments.CommentType type) { if (locked) throw new UnsupportedOperationException("Attempt to modify locked object"); Log.logln(LOG_PROGRESS, "ADDING Comment: \t" + type + "\t" + xpath + " \t" + comment); if (xpath == null || xpath.length() == 0) { - this.getXpathComments().setFinalComment( - CldrUtility.joinWithSeparation(this.getXpathComments().getFinalComment(), XPathParts.NEWLINE, - comment)); + this.getXpathComments() + .setFinalComment( + CldrUtility.joinWithSeparation( + this.getXpathComments().getFinalComment(), + XPathParts.NEWLINE, + comment)); } else { xpath = CLDRFile.getDistinguishingXPath(xpath, null); this.getXpathComments().addComment(type, xpath, comment); @@ -1831,50 +1861,52 @@ public XMLSource addComment(String xpath, String comment, Comments.CommentType t return this; } - /** - * Use in XMLNormalizingHandler only - */ + /** Use in XMLNormalizingHandler only */ public String getFullXPath(String xpath) { if (xpath == null) { throw new NullPointerException("Null distinguishing xpath"); } String result = this.getFullPath(xpath); - return result != null ? result : xpath; // we can't add any non-distinguishing values if there is nothing there. + return result != null + ? result + : xpath; // we can't add any non-distinguishing values if there is nothing there. } - /** - * Add a new element to a XMLSource - * Use in XMLNormalizingHandler only - */ + /** Add a new element to a XMLSource Use in XMLNormalizingHandler only */ public XMLSource add(String currentFullXPath, String value) { if (locked) throw new UnsupportedOperationException("Attempt to modify locked object"); - Log.logln(LOG_PROGRESS, "ADDING: \t" + currentFullXPath + " \t" + value + "\t" + currentFullXPath); + Log.logln( + LOG_PROGRESS, + "ADDING: \t" + currentFullXPath + " \t" + value + "\t" + currentFullXPath); try { this.putValueAtPath(currentFullXPath, value); } catch (RuntimeException e) { - throw new IllegalArgumentException("failed adding " + currentFullXPath + ",\t" + value, e); + throw new IllegalArgumentException( + "failed adding " + currentFullXPath + ",\t" + value, e); } return this; } /** * Get frozen normalized XMLSource + * * @param localeId * @param dirs * @param minimalDraftStatus * @return XMLSource */ - public static XMLSource getFrozenInstance(String localeId, List dirs, DraftStatus minimalDraftStatus) { + public static XMLSource getFrozenInstance( + String localeId, List dirs, DraftStatus minimalDraftStatus) { return XMLNormalizingLoader.getFrozenInstance(localeId, dirs, minimalDraftStatus); } /** * Does the value in question either match or inherent the current value in this XMLSource? * - * To match, the value in question and the current value must be non-null and equal. + *

To match, the value in question and the current value must be non-null and equal. * - * To inherit the current value, the value in question must be INHERITANCE_MARKER - * and the current value must equal the bailey value. + *

To inherit the current value, the value in question must be INHERITANCE_MARKER and the + * current value must equal the bailey value. * * @param value the value in question * @param curValue the current value, that is, getValueAtDPath(xpathString) @@ -1902,8 +1934,8 @@ public boolean equalsOrInheritsCurrentValue(String value, String curValue, Strin } /** - * Add a SourceLocation to this full XPath. - * Base implementation does nothing. + * Add a SourceLocation to this full XPath. Base implementation does nothing. + * * @param currentFullXPath * @param location * @return @@ -1913,8 +1945,8 @@ public XMLSource addSourceLocation(String currentFullXPath, SourceLocation locat } /** - * Get the SourceLocation for a specific XPath. - * Base implementation always returns null. + * Get the SourceLocation for a specific XPath. Base implementation always returns null. + * * @param fullXPath * @return */