]> granicus.if.org Git - icu/commitdiff
ICU-12032 remove SimplePatternFormatter wrapper objects from MeasureFormat range...
authorMarkus Scherer <markus.icu@gmail.com>
Thu, 7 Jan 2016 00:45:28 +0000 (00:45 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Thu, 7 Jan 2016 00:45:28 +0000 (00:45 +0000)
X-SVN-Rev: 38156

icu4j/main/classes/core/src/com/ibm/icu/text/MeasureFormat.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/PluralRangesTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TestAll.java

index 2ddc92dbee6c3f050c13354c532db8b92295dd45..cff1437e25a93fb70f92f9e34b6de02d55220a17 100644 (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();
-    }
 }
index 641e6450a3de0765ec85ec4cd3f00e47deff26f9..77b5da25534364af8e5c7bd6221b2e5c08d06dce 100644 (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, "0–1 degré Fahrenheit"},
index 52f267ba624c78b5e118e2f0fb18a3ab097230de..b73a911394b63e731c36fdb70db144b086c0e249 100644 (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",
             });
         }
     }