diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/test/CheckCLDR.java b/tools/cldr-code/src/main/java/org/unicode/cldr/test/CheckCLDR.java index edab700459c..18588668af8 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/test/CheckCLDR.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/test/CheckCLDR.java @@ -7,7 +7,10 @@ package org.unicode.cldr.test; +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.common.collect.ComparisonChain; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.ibm.icu.dev.util.ElapsedTimer; import com.ibm.icu.impl.Row.R3; @@ -718,10 +721,9 @@ public CheckCLDR setCldrFileToCheck( // we must load filters here, as they are used by check() // Shortlist error filters for this locale. - loadFilters(); String locale = cldrFileToCheck.getLocaleID(); filtersForLocale.clear(); - for (R3 filter : allFilters) { + for (R3 filter : getAllFilters()) { if (filter.get0() == null || !filter.get0().matcher(locale).matches()) continue; Subtype subtype = filter.get1(); List xpaths = filtersForLocale.get(subtype); @@ -1563,26 +1565,32 @@ public void setPhase(Phase phase) { } /** A map of error/warning types to their filters. */ - private static List> allFilters; - - /** Loads the set of filters used for CheckCLDR results. */ - private void loadFilters() { - if (allFilters != null) return; - allFilters = new ArrayList<>(); - RegexFileParser fileParser = new RegexFileParser(); - fileParser.setLineParser( - new RegexLineParser() { - @Override - public void parse(String line) { - String[] fields = line.split("\\s*;\\s*"); - Subtype subtype = Subtype.valueOf(fields[0]); - Pattern locale = PatternCache.get(fields[1]); - Pattern xpathRegex = - PatternCache.get(fields[2].replaceAll("\\[@", "\\\\[@")); - allFilters.add(new R3<>(locale, subtype, xpathRegex)); - } - }); - fileParser.parse(CheckCLDR.class, "/org/unicode/cldr/util/data/CheckCLDR-exceptions.txt"); + private static Supplier>> filterSupplier = + Suppliers.memoize( + () -> { + final List> newFilters = new ArrayList<>(); + RegexFileParser fileParser = new RegexFileParser(); + fileParser.setLineParser( + new RegexLineParser() { + @Override + public void parse(String line) { + String[] fields = line.split("\\s*;\\s*"); + Subtype subtype = Subtype.valueOf(fields[0]); + Pattern locale = PatternCache.get(fields[1]); + Pattern xpathRegex = + PatternCache.get( + fields[2].replaceAll("\\[@", "\\\\[@")); + newFilters.add(new R3<>(locale, subtype, xpathRegex)); + } + }); + fileParser.parse( + CheckCLDR.class, + "/org/unicode/cldr/util/data/CheckCLDR-exceptions.txt"); + return ImmutableList.copyOf(newFilters); + }); + + private static final List> getAllFilters() { + return filterSupplier.get(); } /** diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/test/ConsoleCheckCLDR.java b/tools/cldr-code/src/main/java/org/unicode/cldr/test/ConsoleCheckCLDR.java index eeefa83326c..506b30fd150 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/test/ConsoleCheckCLDR.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/test/ConsoleCheckCLDR.java @@ -1781,9 +1781,9 @@ private static String getIdString(String path, String value) { private static void showValue( CLDRFile cldrFile, String prettyPath, - String localeID, + final String localeID, String example, - String path, + final String path, String value, String fullPath, String statusString, @@ -2031,27 +2031,30 @@ private static String guessFilePath(Pair locPath) { final File base = new File(CLDRPaths.BASE_DIRECTORY); final String loc = locPath.getFirst(); final String path = locPath.getSecond(); - String subdir = "main"; - if (path.startsWith("//ldml/annotations")) { - subdir = "annotations"; - } else if (path.startsWith("//ldml/subdivisions")) { - subdir = "subdivisions"; - } - File inCommon = new File(base, "common"); - File subsub = new File(inCommon, subdir); - if (subsub.isDirectory()) { - File subFile = new File(subsub, loc + ".xml"); - if (subFile.canRead()) - return subFile.getAbsolutePath().substring(base.getAbsolutePath().length() + 1); - } + if (path != null) { + String subdir = "main"; + if (path.startsWith("//ldml/annotations")) { + subdir = "annotations"; + } else if (path.startsWith("//ldml/subdivisions")) { + subdir = "subdivisions"; + } + File inCommon = new File(base, "common"); + File subsub = new File(inCommon, subdir); + if (subsub.isDirectory()) { + File subFile = new File(subsub, loc + ".xml"); + if (subFile.canRead()) + return subFile.getAbsolutePath().substring(base.getAbsolutePath().length() + 1); + } - File inSeed = new File(base, "seed"); - subsub = new File(inSeed, subdir); - if (subsub.isDirectory()) { - File subFile = new File(subsub, loc + ".xml"); - if (subFile.canRead()) - return subFile.getAbsolutePath().substring(base.getAbsolutePath().length() + 1); + File inSeed = new File(base, "seed"); + subsub = new File(inSeed, subdir); + if (subsub.isDirectory()) { + File subFile = new File(subsub, loc + ".xml"); + if (subFile.canRead()) + return subFile.getAbsolutePath().substring(base.getAbsolutePath().length() + 1); + } } + // no XPath - could be an entire-locale error. return loc + ".xml"; }