From 2f995bd7e3be62ea6c7b325e2ee4fa24a8880d6e Mon Sep 17 00:00:00 2001 From: Yoshito Umaoka Date: Tue, 11 Mar 2014 21:35:11 +0000 Subject: [PATCH] ICU-10374 Fixed some issues introduced by r35403. Also fixed compiler warnings in LocaleMatcher. X-SVN-Rev: 35409 --- .../src/com/ibm/icu/text/PluralRules.java | 6 +++- .../src/com/ibm/icu/util/LocaleMatcher.java | 36 +++++++++---------- .../icu/dev/test/util/LocaleMatcherTest.java | 18 +++++----- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/PluralRules.java b/icu4j/main/classes/core/src/com/ibm/icu/text/PluralRules.java index c83c51a92a7..4e3620e3c6d 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/PluralRules.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/PluralRules.java @@ -665,7 +665,11 @@ public class PluralRules implements Serializable { } else { String buf = String.format(Locale.ENGLISH, "%1.15e", n); int ePos = buf.lastIndexOf('e'); - String exponentStr = buf.substring(ePos+1); + int expNumPos = ePos + 1; + if (buf.charAt(expNumPos) == '+') { + expNumPos++; + } + String exponentStr = buf.substring(expNumPos); int exponent = Integer.parseInt(exponentStr); int numFractionDigits = ePos - 2 - exponent; if (numFractionDigits < 0) { diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/LocaleMatcher.java b/icu4j/main/classes/core/src/com/ibm/icu/util/LocaleMatcher.java index ef801e9ef19..62694396dcc 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/LocaleMatcher.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/LocaleMatcher.java @@ -46,7 +46,7 @@ import com.ibm.icu.impl.Row.R3; */ public class LocaleMatcher { - private static boolean DEBUG = true; + private static boolean DEBUG = false; private static final ULocale UNKNOWN_LOCALE = new ULocale("und"); @@ -397,14 +397,12 @@ public class LocaleMatcher { } private static class ScoreData implements Freezable { - /** - * - */ + @SuppressWarnings("unused") private static final double maxUnequal_changeD_sameS = 0.5; - /** - * - */ + + @SuppressWarnings("unused") private static final double maxUnequal_changeEqual = 0.75; + LinkedHashSet> scores = new LinkedHashSet>(); final Level level; @@ -448,21 +446,21 @@ public class LocaleMatcher { // example: input en-GB, supported en en-GB // we want to have a closer match with - boolean desiredChange = desiredRaw.equals(desiredMax); - boolean supportedChange = supportedRaw.equals(supportedMax); +// boolean desiredChange = desiredRaw.equals(desiredMax); +// boolean supportedChange = supportedRaw.equals(supportedMax); double distance = 0; if (!desiredMax.equals(supportedMax)) { - // Map>> lang_result = scores.get(desiredMax); - // if (lang_result == null) { - // distance = worst; - // } else { - // Set> result = lang_result.get(supportedMax); - // skip: - // if (result == null) { - // distance = worst; - // } else { +// Map>> lang_result = scores.get(desiredMax); +// if (lang_result == null) { +// distance = worst; +// } else { +// Set> result = lang_result.get(supportedMax); +// skip: +// if (result == null) { +// distance = worst; +// } else { distance = getRawScore(dMax, sMax); - // } +// } // if (desiredChange == supportedChange) { // distance *= maxUnequal_changeEqual; // if (DEBUG) { diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/LocaleMatcherTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/LocaleMatcherTest.java index a2d5038b6e9..8cdd9be0dca 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/LocaleMatcherTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/LocaleMatcherTest.java @@ -31,14 +31,16 @@ public class LocaleMatcherTest extends TestFmwk { LocaleMatcher matcher = new LocaleMatcher("zh_CN, zh_TW, iw"); ULocale taiwanChinese = new ULocale("zh_TW"); ULocale chinaChinese = new ULocale("zh_CN"); -// assertEquals("zh_CN, zh_TW, iw;", taiwanChinese, matcher.getBestMatch("zh_Hant_TW")); -// assertEquals("zh_CN, zh_TW, iw;", taiwanChinese, matcher.getBestMatch("zh_Hant")); -// assertEquals("zh_CN, zh_TW, iw;", taiwanChinese, matcher.getBestMatch("zh_TW")); -// assertEquals("zh_CN, zh_TW, iw;", chinaChinese, matcher.getBestMatch("zh_Hans_CN")); -// assertEquals("zh_CN, zh_TW, iw;", chinaChinese, matcher.getBestMatch("zh_CN")); -// assertEquals("zh_CN, zh_TW, iw;", chinaChinese, matcher.getBestMatch("zh")); - - assertEquals("zh_CN, zh_TW, iw;", taiwanChinese, matcher.getBestMatch("zh_Hant_HK")); + assertEquals("zh_CN, zh_TW, iw;", taiwanChinese, matcher.getBestMatch("zh_Hant_TW")); + assertEquals("zh_CN, zh_TW, iw;", taiwanChinese, matcher.getBestMatch("zh_Hant")); + assertEquals("zh_CN, zh_TW, iw;", taiwanChinese, matcher.getBestMatch("zh_TW")); + assertEquals("zh_CN, zh_TW, iw;", chinaChinese, matcher.getBestMatch("zh_Hans_CN")); + assertEquals("zh_CN, zh_TW, iw;", chinaChinese, matcher.getBestMatch("zh_CN")); + assertEquals("zh_CN, zh_TW, iw;", chinaChinese, matcher.getBestMatch("zh")); + + if (!logKnownIssue("10745", "Needs the latest languageMatching data imported from CLDR 25")) { + assertEquals("zh_CN, zh_TW, iw;", taiwanChinese, matcher.getBestMatch("zh_Hant_HK")); + } } public void testenGB() { -- 2.40.0