From 16d37f5610926248ef72a0929306dc4efc6175de Mon Sep 17 00:00:00 2001 From: Tom Bishop Date: Tue, 5 Dec 2023 15:22:27 -0500 Subject: [PATCH] CLDR-13970 ST Examples used in patterns; make ISB_CAN_CLEAR_CACHE true (#3408) -Making ISB_CAN_CLEAR_CACHE true fixes the last known bug for this ticket -This PR may finish the ticket, depending on whether the performance cost is acceptable -Fix some compiler warnings (make some items final, remove some commented-out code, ...) -Comments: updated comment about seed/main, and deleted commented-out code referencing CLDRFile --- .../unicode/cldr/util/ICUServiceBuilder.java | 71 +++++-------------- 1 file changed, 17 insertions(+), 54 deletions(-) diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/ICUServiceBuilder.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/ICUServiceBuilder.java index 033b5b7cc35..212651b1159 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/ICUServiceBuilder.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/ICUServiceBuilder.java @@ -30,10 +30,10 @@ public class ICUServiceBuilder { public static Currency NO_CURRENCY = Currency.getInstance("XXX"); private CLDRFile cldrFile; private CLDRFile collationFile; - private static Map ISBMap = new HashMap<>(); + private static final Map ISBMap = new HashMap<>(); - private static TimeZone utc = TimeZone.getTimeZone("GMT"); - private static DateFormat iso = + private static final TimeZone utc = TimeZone.getTimeZone("GMT"); + private static final DateFormat iso = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", ULocale.ENGLISH); static { @@ -52,11 +52,11 @@ public static Date isoDateParse(String date) throws ParseException { return iso.parse(date); } - private Map cacheDateFormats = new HashMap<>(); - private Map cacheDateFormatSymbols = new HashMap<>(); - private Map cacheNumberFormats = new HashMap<>(); - private Map cacheDecimalFormatSymbols = new HashMap<>(); - private Map cacheRuleBasedCollators = new HashMap<>(); + private final Map cacheDateFormats = new HashMap<>(); + private final Map cacheDateFormatSymbols = new HashMap<>(); + private final Map cacheNumberFormats = new HashMap<>(); + private final Map cacheDecimalFormatSymbols = new HashMap<>(); + private final Map cacheRuleBasedCollators = new HashMap<>(); /** * Caching can be disabled for some ICUServiceBuilder instances while still enabled for others. @@ -70,9 +70,9 @@ public void setCachingEnabled(boolean enabled) { /** * TODO: the ability to clear the cache(s) is temporarily useful for debugging, and may or may * not be useful in the long run. In the meantime, this should be false except while debugging. - * Reference: https://unicode-org.atlassian.net/browse/CLDR-13970 + * Reference: CLDR-13970 */ - public static final boolean ISB_CAN_CLEAR_CACHE = false; + public static final boolean ISB_CAN_CLEAR_CACHE = true; public void clearCache() { if (ISB_CAN_CLEAR_CACHE) { @@ -86,10 +86,10 @@ public void clearCache() { private SupplementalDataInfo supplementalData; - private static int[] DateFormatValues = { + private static final int[] DateFormatValues = { -1, DateFormat.SHORT, DateFormat.MEDIUM, DateFormat.LONG, DateFormat.FULL }; - private static String[] DateFormatNames = {"none", "short", "medium", "long", "full"}; + private static final String[] DateFormatNames = {"none", "short", "medium", "long", "full"}; private static final String[] Days = {"sun", "mon", "tue", "wed", "thu", "fri", "sat"}; @@ -118,10 +118,10 @@ public static ICUServiceBuilder forLocale(CLDRLocale locale) { if (locale != null) { // CAUTION: this fails for files in seed, when called for DAIP, for CLDRModify, - // since - // CLDRPaths.MAIN_DIRECTORY is "common/main" NOT "seed/main" - // Fortunately it will be fixed soon (Oct 2022) for - // https://unicode-org.atlassian.net/browse/CLDR-6396 + // since CLDRPaths.MAIN_DIRECTORY is "common/main" NOT "seed/main". + // Fortunately CLDR no longer uses the "seed" directory -- as of 2023 it is empty + // except for README files. If CLDR ever uses "seed" again, however, this will + // become a problem again. result.cldrFile = Factory.make(CLDRPaths.MAIN_DIRECTORY, ".*") .make(locale.getBaseName(), true); @@ -261,7 +261,7 @@ private SimpleDateFormat getFullFormat( result.setNumberFormat((NumberFormat) numberFormat.clone()); // Need to put the field specific number format override formatters back in place, since // the previous result.setNumberFormat above nukes them. - if (numbersOverride != null && numbersOverride.indexOf("=") != -1) { + if (numbersOverride != null && numbersOverride.contains("=")) { String[] overrides = numbersOverride.split(","); for (String override : overrides) { String[] fields = override.split("=", 2); @@ -312,28 +312,16 @@ private DateFormatSymbols _getDateFormatSymbols(String calendar) { getDayPeriods(prefix, "format", "wide", "pm") })); checkFound(last); - // if (last[0] == null && notGregorian) { - // if (gregorianBackup == null) gregorianBackup = _getDateFormatSymbols("gregorian"); - // formatData.setAmPmStrings(last = gregorianBackup.getAmPmStrings()); - // } int minEras = (calendar.equals("chinese") || calendar.equals("dangi")) ? 0 : 1; List temp = getArray(prefix + "eras/eraAbbr/era[@type=\"", 0, null, "\"]", minEras); formatData.setEras(last = temp.toArray(new String[temp.size()])); if (minEras != 0) checkFound(last); - // if (temp.size() < 2 && notGregorian) { - // if (gregorianBackup == null) gregorianBackup = _getDateFormatSymbols("gregorian"); - // formatData.setEras(last = gregorianBackup.getEras()); - // } temp = getArray(prefix + "eras/eraNames/era[@type=\"", 0, null, "\"]", minEras); formatData.setEraNames(last = temp.toArray(new String[temp.size()])); if (minEras != 0) checkFound(last); - // if (temp.size() < 2 && notGregorian) { - // if (gregorianBackup == null) gregorianBackup = _getDateFormatSymbols("gregorian"); - // formatData.setEraNames(last = gregorianBackup.getEraNames()); - // } formatData.setMonths( getArray(prefix, "month", "format", "wide"), @@ -360,13 +348,6 @@ private DateFormatSymbols _getDateFormatSymbols(String calendar) { getArray(prefix, "month", "stand-alone", "narrow"), DateFormatSymbols.STANDALONE, DateFormatSymbols.NARROW); - - // formatData.setWeekdays(getArray(prefix, "day", "format", "wide")); - // if (last == null && notGregorian) { - // if (gregorianBackup == null) gregorianBackup = _getDateFormatSymbols("gregorian"); - // formatData.setWeekdays(gregorianBackup.getWeekdays()); - // } - formatData.setWeekdays( getArray(prefix, "day", "format", "wide"), DateFormatSymbols.FORMAT, @@ -666,33 +647,27 @@ public int hashCode() { static int CURRENCY = 0, OTHER_KEY = 1, PATTERN = 2; public DecimalFormat getCurrencyFormat(String currency) { - // CLDRFile cldrFile = cldrFactory.make(localeID, true); return _getNumberFormat(currency, CURRENCY, null, null); } public DecimalFormat getCurrencyFormat(String currency, String currencySymbol) { - // CLDRFile cldrFile = cldrFactory.make(localeID, true); return _getNumberFormat(currency, CURRENCY, currencySymbol, null); } public DecimalFormat getCurrencyFormat( String currency, String currencySymbol, String numberSystem) { - // CLDRFile cldrFile = cldrFactory.make(localeID, true); return _getNumberFormat(currency, CURRENCY, currencySymbol, numberSystem); } public DecimalFormat getNumberFormat(int index) { - // CLDRFile cldrFile = cldrFactory.make(localeID, true); return _getNumberFormat(NumberNames[index], OTHER_KEY, null, null); } public DecimalFormat getNumberFormat(int index, String numberSystem) { - // CLDRFile cldrFile = cldrFactory.make(localeID, true); return _getNumberFormat(NumberNames[index], OTHER_KEY, null, numberSystem); } public NumberFormat getGenericNumberFormat(String ns) { - // CLDRFile cldrFile = cldrFactory.make(localeID, true); NumberFormat result = cachingIsEnabled ? cacheNumberFormats.get(cldrFile.getLocaleID() + "@numbers=" + ns) @@ -708,12 +683,10 @@ public NumberFormat getGenericNumberFormat(String ns) { } public DecimalFormat getNumberFormat(String pattern) { - // CLDRFile cldrFile = cldrFactory.make(localeID, true); return _getNumberFormat(pattern, PATTERN, null, null); } public DecimalFormat getNumberFormat(String pattern, String numberSystem) { - // CLDRFile cldrFile = cldrFactory.make(localeID, true); return _getNumberFormat(pattern, PATTERN, null, numberSystem); } @@ -804,16 +777,6 @@ private DecimalFormat _getNumberFormat( currencySymbol, cldrFile.getWinningValueWithBailey(prefix + "displayName"), info); - - // String possible = null; - // possible = cldrFile.getWinningValueWithBailey(prefix + "decimal"); - // symbols.setMonetaryDecimalSeparator(possible != null ? possible.charAt(0) : - // symbols.getDecimalSeparator()); - // if ((possible = cldrFile.getWinningValueWithBailey(prefix + "pattern")) != null) - // pattern = possible; - // if ((possible = cldrFile.getWinningValueWithBailey(prefix + "group")) != null) - // symbols.setGroupingSeparator(possible.charAt(0)); - // ; } result = new DecimalFormat(pattern, symbols); if (mc != null) {