]> granicus.if.org Git - icu/commitdiff
ICU-9604 Move JAVA CompactDecimalFormat factory methods and LONG/SHORT enum from...
authorTravis Keep <keep94@gmail.com>
Thu, 27 Sep 2012 18:25:47 +0000 (18:25 +0000)
committerTravis Keep <keep94@gmail.com>
Thu, 27 Sep 2012 18:25:47 +0000 (18:25 +0000)
X-SVN-Rev: 32437

icu4j/main/classes/core/src/com/ibm/icu/text/CompactDecimalFormat.java
icu4j/main/classes/core/src/com/ibm/icu/text/NumberFormat.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/CompactDecimalFormatTest.java

index 9ae08cdb78105214baba4e440be86ba83f9a7aa8..eb62daadfd8cfbc099e0ea311881d1d45566eb2f 100644 (file)
@@ -18,6 +18,7 @@ import java.text.FieldPosition;
 import java.text.ParsePosition;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
 
 import com.ibm.icu.text.CompactDecimalDataCache.Data;
@@ -61,6 +62,52 @@ public class CompactDecimalFormat extends DecimalFormat {
     // null if created internally using explicit prefixes and suffixes.
     private final PluralRules pluralRules;
 
+    /**
+     * Style parameter for CompactDecimalFormat.
+     * @draft ICU 50
+     * @provisional This API might change or be removed in a future release.
+     */
+    public enum CompactStyle {
+        /**
+         * Short version, like "1.2T"
+         * @draft ICU 50
+         * @provisional This API might change or be removed in a future release.
+         */
+        SHORT,
+        /**
+         * Longer version, like "1.2 trillion", if available. May return same result as SHORT if not.
+         * @draft ICU 50
+         * @provisional This API might change or be removed in a future release.
+         */
+        LONG
+    }
+
+    /**
+     * Create a CompactDecimalFormat appropriate for a locale. The result may
+     * be affected by the number system in the locale, such as ar-u-nu-latn.
+     *
+     * @param locale the desired locale
+     * @param style the compact style
+     * @draft ICU 50
+     * @provisional This API might change or be removed in a future release.
+     */
+    public static CompactDecimalFormat getCompactDecimalInstance(ULocale locale, CompactStyle style) {
+        return new CompactDecimalFormat(locale, style);
+    }
+
+    /**
+     * Create a CompactDecimalFormat appropriate for a locale. The result may
+     * be affected by the number system in the locale, such as ar-u-nu-latn.
+     *
+     * @param locale the desired locale
+     * @param style the compact style
+     * @draft ICU 50
+     * @provisional This API might change or be removed in a future release.
+     */
+    public static CompactDecimalFormat getCompactDecimalInstance(Locale locale, CompactStyle style) {
+        return new CompactDecimalFormat(ULocale.forLocale(locale), style);
+    }
+
     /**
      * The public mechanism is NumberFormat.getCompactDecimalInstance().
      *
index 95924eb5402530c7804f56241319b537d037248b..a3af4fee3cda4997309b272b1d001aa1de510f36 100644 (file)
@@ -230,6 +230,7 @@ public abstract class NumberFormat extends UFormat {
      * @see java.text.Format#format(Object, StringBuffer, FieldPosition)
      * @stable ICU 2.0
      */
+    @Override
     public StringBuffer format(Object number,
                                StringBuffer toAppendTo,
                                FieldPosition pos) {
@@ -258,6 +259,7 @@ public abstract class NumberFormat extends UFormat {
      * @see java.text.NumberFormat#parseObject(String, ParsePosition)
      * @stable ICU 2.0
      */
+    @Override
     public final Object parseObject(String source,
                                     ParsePosition parsePosition) {
         return parse(source, parsePosition);
@@ -714,53 +716,6 @@ public abstract class NumberFormat extends UFormat {
         return getInstance(inLocale, SCIENTIFICSTYLE);
     }
 
-    /**
-     * Style parameter for CompactDecimalFormat.
-     * @draft ICU 49
-     * @provisional This API might change or be removed in a future release.
-     */
-    public enum CompactStyle {
-        /**
-         * Short version, like "1.2T"
-         * @draft ICU 49
-         * @provisional This API might change or be removed in a future release.
-         */
-        SHORT, 
-        /**
-         * Longer version, like "1.2 trillion", if available. May return same result as SHORT if not.
-         * @draft ICU 49
-         * @provisional This API might change or be removed in a future release.
-         */
-        LONG
-    }
-
-    /**
-     * Create a CompactDecimalFormat appropriate for a locale. The result may
-     * be affected by the number system in the locale, such as ar-u-nu-latn.
-     * 
-     * @param locale the desired locale
-     * @param style the compact style 
-     * @draft ICU 49
-     * @provisional This API might change or be removed in a future release.
-     */
-    public static final CompactDecimalFormat getCompactDecimalInstance(ULocale locale, CompactStyle style) {
-        return new CompactDecimalFormat(locale, style);
-    }
-
-    /**
-     * Create a CompactDecimalFormat appropriate for a locale. The result may
-     * be affected by the number system in the locale, such as ar-u-nu-latn.
-     * 
-     * @param locale the desired locale
-     * @param style the compact style 
-     * @draft ICU 49
-     * @provisional This API might change or be removed in a future release.
-     */
-    public static final CompactDecimalFormat getCompactDecimalInstance(Locale locale, CompactStyle style) {
-        return new CompactDecimalFormat(ULocale.forLocale(locale), style);
-    }
-
-
     // ===== Factory stuff =====
     /**
      * A NumberFormatFactory is used to register new number formats.  The factory
@@ -914,6 +869,7 @@ public abstract class NumberFormat extends UFormat {
          * {@inheritDoc}
          * @stable ICU 2.6
          */
+        @Override
         public final boolean visible() {
             return visible;
         }
@@ -922,6 +878,7 @@ public abstract class NumberFormat extends UFormat {
          * {@inheritDoc}
          * @stable ICU 2.6
          */
+        @Override
         public final Set<String> getSupportedLocaleNames() {
             return localeNames;
         }
@@ -1025,6 +982,7 @@ public abstract class NumberFormat extends UFormat {
      * Overrides hashCode.
      * @stable ICU 2.0
      */
+    @Override
     public int hashCode() {
         return maximumIntegerDigits * 37 + maxFractionDigits;
         // just enough fields for a reasonable distribution
@@ -1039,6 +997,7 @@ public abstract class NumberFormat extends UFormat {
      * @return true if the object is equal to this.
      * @stable ICU 2.0
      */
+    @Override
     public boolean equals(Object obj) {
         if (obj == null) return false;
         if (this == obj)
@@ -1059,6 +1018,7 @@ public abstract class NumberFormat extends UFormat {
      * Overrides clone.
      * @stable ICU 2.0
      */
+    @Override
     public Object clone() {
         NumberFormat other = (NumberFormat) super.clone();
         return other;
@@ -1247,6 +1207,7 @@ public abstract class NumberFormat extends UFormat {
      * @internal
      * @deprecated This API is ICU internal only.
      */
+    @Deprecated
     protected Currency getEffectiveCurrency() {
         Currency c = getCurrency();
         if (c == null) {
@@ -1410,6 +1371,7 @@ public abstract class NumberFormat extends UFormat {
      * @return the pattern
      * @deprecated ICU 3.4 subclassers should override getPattern(ULocale, int) instead of this method.
      */
+    @Deprecated
     protected static String getPattern(Locale forLocale, int choice) {
         return getPattern(ULocale.forLocale(forLocale), choice);
     }
@@ -1469,19 +1431,19 @@ public abstract class NumberFormat extends UFormat {
         int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE :
                 ((choice == ISOCURRENCYSTYLE || choice == PLURALCURRENCYSTYLE)?
                 CURRENCYSTYLE : choice); //[Richard/GCL]
-        
+
         ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.
         getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, forLocale);
         String[] numberPatternKeys = { "decimalFormat", "currencyFormat", "percentFormat", "scientificFormat" };
         NumberingSystem ns = NumberingSystem.getInstance(forLocale);
-        
+
         String result = null;
         try {
             result = rb.getStringWithFallback("NumberElements/" + ns.getName() + "/patterns/"+numberPatternKeys[entry]);
         } catch ( MissingResourceException ex ) {
             result = rb.getStringWithFallback("NumberElements/latn/patterns/"+numberPatternKeys[entry]);
         }
-        
+
         return result;
     }
 
@@ -1817,6 +1779,7 @@ public abstract class NumberFormat extends UFormat {
          * NumberFormat.Field values
          * @stable ICU 3.6
          */
+        @Override
         protected Object readResolve() throws InvalidObjectException {
             if (this.getName().equals(INTEGER.getName()))
                 return INTEGER;
index 19cbdbcf3b4f700200a0f04c0247a20f6d72a424..9c6b920d279a273779af702f945ac025d4f427c4 100644 (file)
@@ -11,8 +11,8 @@ import java.text.CharacterIterator;
 
 import com.ibm.icu.dev.test.TestFmwk;
 import com.ibm.icu.text.CompactDecimalFormat;
+import com.ibm.icu.text.CompactDecimalFormat.CompactStyle;
 import com.ibm.icu.text.NumberFormat;
-import com.ibm.icu.text.NumberFormat.CompactStyle;
 import com.ibm.icu.util.ULocale;
 
 public class CompactDecimalFormatTest extends TestFmwk {
@@ -110,7 +110,7 @@ public class CompactDecimalFormatTest extends TestFmwk {
 
     public void TestCharacterIterator() {
         CompactDecimalFormat cdf =
-                NumberFormat.getCompactDecimalInstance(ULocale.ENGLISH, CompactStyle.SHORT);
+                CompactDecimalFormat.getCompactDecimalInstance(ULocale.ENGLISH, CompactStyle.SHORT);
         AttributedCharacterIterator iter = cdf.formatToCharacterIterator(12346);
         assertEquals("CharacterIterator", "12K", iterToString(iter));
         iter = cdf.formatToCharacterIterator(12346);
@@ -125,7 +125,7 @@ public class CompactDecimalFormatTest extends TestFmwk {
 
     public void TestArabicLongStyle() {
         NumberFormat cdf =
-                NumberFormat.getCompactDecimalInstance(
+                CompactDecimalFormat.getCompactDecimalInstance(
                         ULocale.forLanguageTag("ar"), CompactStyle.LONG);
         assertEquals("Arabic Long", "٥٫٣ ألف", cdf.format(5300));
     }
@@ -147,7 +147,7 @@ public class CompactDecimalFormatTest extends TestFmwk {
     }
 
     public void checkLocale(ULocale locale, CompactStyle style, Object[][] testData) {
-        CompactDecimalFormat cdf = NumberFormat.getCompactDecimalInstance(locale, style);
+        CompactDecimalFormat cdf = CompactDecimalFormat.getCompactDecimalInstance(locale, style);
         for (Object[] row : testData) {
             assertEquals(locale + " (" + locale.getDisplayName(locale) + ")", row[1], cdf.format(row[0]));
         }