]> granicus.if.org Git - icu/commitdiff
ICU-13526 Adding package-private getNumberFormatInternal() to reduce unnecessary...
authorShane Carr <shane@unicode.org>
Sat, 3 Feb 2018 07:54:35 +0000 (07:54 +0000)
committerShane Carr <shane@unicode.org>
Sat, 3 Feb 2018 07:54:35 +0000 (07:54 +0000)
X-SVN-Rev: 40835

icu4j/main/classes/core/src/com/ibm/icu/text/CurrencyFormat.java
icu4j/main/classes/core/src/com/ibm/icu/text/MeasureFormat.java
icu4j/main/classes/core/src/com/ibm/icu/text/TimeUnitFormat.java

index d1e1618b8df238440907f4ad416e534b9bc243c7..c3cc93775cc30674333c3ad35e97c8d97108655a 100644 (file)
@@ -58,7 +58,7 @@ class CurrencyFormat extends MeasureFormat {
      */
     @Override
     public CurrencyAmount parseObject(String source, ParsePosition pos) {
-        return getNumberFormat().parseCurrency(source, pos);
+        return getNumberFormatInternal().parseCurrency(source, pos);
     }
 
     // Serialization
index 8af36321b45ec51e6ab060e89d5a42987b94a2d3..834d6c51ec9adfe9c36f3129b392d33133ce2423 100644 (file)
@@ -494,7 +494,7 @@ public class MeasureFormat extends UFormat {
         // A very slow but safe implementation.
         return getWidth() == rhs.getWidth()
                 && getLocale().equals(rhs.getLocale())
-                && getNumberFormat().equals(rhs.getNumberFormat());
+                && getNumberFormatInternal().equals(rhs.getNumberFormatInternal());
     }
 
     /**
@@ -505,7 +505,7 @@ public class MeasureFormat extends UFormat {
     @Override
     public final int hashCode() {
         // A very slow but safe implementation.
-        return (getLocale().hashCode() * 31 + getNumberFormat().hashCode()) * 31 + getWidth().hashCode();
+        return (getLocale().hashCode() * 31 + getNumberFormatInternal().hashCode()) * 31 + getWidth().hashCode();
     }
 
     /**
@@ -535,6 +535,13 @@ public class MeasureFormat extends UFormat {
         return (NumberFormat) numberFormat.clone();
     }
 
+    /**
+     * Get a copy of the number format without cloning. Internal method.
+     */
+    NumberFormat getNumberFormatInternal() {
+        return numberFormat;
+    }
+
     /**
      * Return a formatter for CurrencyAmount objects in the given locale.
      *
@@ -954,15 +961,15 @@ public class MeasureFormat extends UFormat {
     }
 
     Object toTimeUnitProxy() {
-        return new MeasureProxy(getLocale(), formatWidth, getNumberFormat(), TIME_UNIT_FORMAT);
+        return new MeasureProxy(getLocale(), formatWidth, getNumberFormatInternal(), TIME_UNIT_FORMAT);
     }
 
     Object toCurrencyProxy() {
-        return new MeasureProxy(getLocale(), formatWidth, getNumberFormat(), CURRENCY_FORMAT);
+        return new MeasureProxy(getLocale(), formatWidth, getNumberFormatInternal(), CURRENCY_FORMAT);
     }
 
     private Object writeReplace() throws ObjectStreamException {
-        return new MeasureProxy(getLocale(), formatWidth, getNumberFormat(), MEASURE_FORMAT);
+        return new MeasureProxy(getLocale(), formatWidth, getNumberFormatInternal(), MEASURE_FORMAT);
     }
 
     static class MeasureProxy implements Externalizable {
index 1c86f8dc3c02b9796d62128341700d9d639ea172..f8fff0b15f38ded6b29ea66db859fd23a2899986 100644 (file)
@@ -150,7 +150,7 @@ public class TimeUnitFormat extends MeasureFormat {
     @Deprecated
     public TimeUnitFormat(ULocale locale, int style) {
         super(locale, style == FULL_NAME ? FormatWidth.WIDE : FormatWidth.SHORT);
-        format = super.getNumberFormat();
+        format = super.getNumberFormatInternal();
         if (style < FULL_NAME || style >= TOTAL_STYLES) {
             throw new IllegalArgumentException("style should be either FULL_NAME or ABBREVIATED_NAME style");
         }
@@ -225,6 +225,11 @@ public class TimeUnitFormat extends MeasureFormat {
 
     @Override
     public NumberFormat getNumberFormat() {
+        return (NumberFormat) format.clone();
+    }
+
+    @Override
+    NumberFormat getNumberFormatInternal() {
         return format;
     }