summaryrefslogtreecommitdiff
path: root/icu4j
diff options
context:
space:
mode:
authorMarkus Scherer <markus.icu@gmail.com>2016-01-07 00:45:28 +0000
committerFredrik Roubert <roubert@google.com>2016-01-28 17:11:36 +0100
commit8cf2ea9dc34722269d7c772820b0878aa2398a76 (patch)
tree8a6e700b9d29dca6572ec2d80b0344eb12403e9b /icu4j
parent9ed78814084b919478a4e43666f80824bc96d38b (diff)
downloadicu-8cf2ea9dc34722269d7c772820b0878aa2398a76.tar.gz
Cherry-pick: ticket:12032: remove SimplePatternFormatter wrapper objects from MeasureFormat range formatting, too
http://bugs.icu-project.org/trac/changeset/38156 Change-Id: I35f92589a0dd1299c51c44f4e227b03bb1bff201
Diffstat (limited to 'icu4j')
-rw-r--r--icu4j/main/classes/core/src/com/ibm/icu/text/MeasureFormat.java30
-rw-r--r--icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/PluralRangesTest.java8
-rw-r--r--icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TestAll.java3
3 files changed, 14 insertions, 27 deletions
diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/MeasureFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/MeasureFormat.java
index 2235b493c..edab3e448 100644
--- a/icu4j/main/classes/core/src/com/ibm/icu/text/MeasureFormat.java
+++ b/icu4j/main/classes/core/src/com/ibm/icu/text/MeasureFormat.java
@@ -426,8 +426,8 @@ public class MeasureFormat extends UFormat {
StandardPlural.fromString(keywordLow),
StandardPlural.fromString(keywordHigh));
- SimplePatternFormatter rangeFormatter = getRangeFormat(getLocale(), formatWidth);
- String formattedNumber = rangeFormatter.format(lowFormatted, highFormatted);
+ String rangeFormatter = getRangeFormat(getLocale(), formatWidth);
+ String formattedNumber = SimplePatternFormatter.formatCompiledPattern(rangeFormatter, lowFormatted, highFormatted);
if (isCurrency) {
// Nasty hack
@@ -1412,11 +1412,11 @@ public class MeasureFormat extends UFormat {
return values[ordinal];
}
- static final Map<ULocale, SimplePatternFormatter> localeIdToRangeFormat
- = new ConcurrentHashMap<ULocale, SimplePatternFormatter>();
+ private static final Map<ULocale, String> localeIdToRangeFormat =
+ new ConcurrentHashMap<ULocale, String>();
/**
- * Return a simple pattern formatter for a range, such as "{0}–{1}".
+ * Return a formatter (compiled SimplePatternFormatter pattern) for a range, such as "{0}–{1}".
* @param forLocale locale to get the format for
* @param width the format width
* @return range formatter, such as "{0}–{1}"
@@ -1424,13 +1424,12 @@ public class MeasureFormat extends UFormat {
* @deprecated This API is ICU internal only.
*/
@Deprecated
-
- public static SimplePatternFormatter getRangeFormat(ULocale forLocale, FormatWidth width) {
+ public static String getRangeFormat(ULocale forLocale, FormatWidth width) {
// TODO fix Hack for French
if (forLocale.getLanguage().equals("fr")) {
return getRangeFormat(ULocale.ROOT, width);
}
- SimplePatternFormatter result = localeIdToRangeFormat.get(forLocale);
+ String result = localeIdToRangeFormat.get(forLocale);
if (result == null) {
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.
getBundleInstance(ICUData.ICU_BASE_NAME, forLocale);
@@ -1452,7 +1451,7 @@ public class MeasureFormat extends UFormat {
} catch ( MissingResourceException ex ) {
resultString = rb.getStringWithFallback("NumberElements/latn/patterns/range");
}
- result = SimplePatternFormatter.compileMinMaxPlaceholders(resultString, 2, 2);
+ result = SimplePatternFormatter.compileToStringMinMaxPlaceholders(resultString, new StringBuilder(), 2, 2);
localeIdToRangeFormat.put(forLocale, result);
if (!forLocale.equals(realLocale)) {
localeIdToRangeFormat.put(realLocale, result);
@@ -1460,17 +1459,4 @@ public class MeasureFormat extends UFormat {
}
return result;
}
-
- /**
- * Return a simple pattern pattern for a range, such as "{0}–{1}" or "{0}~{1}".
- * @param forLocale locale to get the range pattern for
- * @param width the format width.
- * @return range pattern
- * @internal
- * @deprecated This API is ICU internal only.
- */
- @Deprecated
- public static String getRangePattern(ULocale forLocale, FormatWidth width) {
- return getRangeFormat(forLocale, width).toString();
- }
}
diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/PluralRangesTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/PluralRangesTest.java
index 641e6450a..77b5da255 100644
--- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/PluralRangesTest.java
+++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/PluralRangesTest.java
@@ -1,6 +1,6 @@
/*
*******************************************************************************
- * Copyright (C) 2008-2015, International Business Machines Corporation and
+ * Copyright (C) 2008-2016, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*/
@@ -9,6 +9,7 @@ package com.ibm.icu.dev.test.format;
import java.util.Arrays;
import com.ibm.icu.dev.test.TestFmwk;
+import com.ibm.icu.impl.SimplePatternFormatter;
import com.ibm.icu.impl.StandardPlural;
import com.ibm.icu.text.MeasureFormat;
import com.ibm.icu.text.MeasureFormat.FormatWidth;
@@ -60,11 +61,12 @@ public class PluralRangesTest extends TestFmwk {
ULocale ulocale = new ULocale(test[0]);
FormatWidth width = FormatWidth.valueOf(test[1]);
String expected = test[2];
- String actual = MeasureFormat.getRangePattern(ulocale, width);
+ String formatter = MeasureFormat.getRangeFormat(ulocale, width);
+ String actual = SimplePatternFormatter.formatCompiledPattern(formatter, "{0}", "{1}");
assertEquals("range pattern " + Arrays.asList(test), expected, actual);
}
}
-
+
public void TestFormatting() {
Object[][] tests = {
{0.0, 1.0, ULocale.FRANCE, FormatWidth.WIDE, MeasureUnit.FAHRENHEIT, "0–1 degré Fahrenheit"},
diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TestAll.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TestAll.java
index 52f267ba6..b73a91139 100644
--- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TestAll.java
+++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TestAll.java
@@ -1,6 +1,6 @@
/*
*******************************************************************************
- * Copyright (c) 2004-2014, International Business Machines
+ * Copyright (c) 2004-2016, International Business Machines
* Corporation and others. All Rights Reserved.
* Copyright (C) 2010 , Yahoo! Inc.
*******************************************************************************
@@ -64,7 +64,6 @@ public class TestAll extends TestGroup {
"IntlTestDecimalFormatAPIC",
"IntlTestDecimalFormatSymbols",
"IntlTestDecimalFormatSymbolsC",
- "PluralRangesTest",
});
}
}