ICU-12032 remove SimplePatternFormatter wrapper objects from MeasureFormat range formatting, too

X-SVN-Rev: 38156
This commit is contained in:
Markus Scherer 2016-01-07 00:45:28 +00:00
parent 9eb5fc1b11
commit 0183cad1d7
3 changed files with 14 additions and 27 deletions

View file

@ -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
@ -1410,11 +1410,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}"
@ -1422,13 +1422,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);
@ -1450,7 +1449,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);
@ -1458,17 +1457,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();
}
}

View file

@ -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, "01 degré Fahrenheit"},

View file

@ -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",
});
}
}