diff options
Diffstat (limited to 'android_icu4j/src')
-rw-r--r-- | android_icu4j/src/main/java/android/icu/number/Precision.java | 82 | ||||
-rw-r--r-- | android_icu4j/src/main/java/android/icu/number/ScientificNotation.java | 25 |
2 files changed, 78 insertions, 29 deletions
diff --git a/android_icu4j/src/main/java/android/icu/number/Precision.java b/android_icu4j/src/main/java/android/icu/number/Precision.java index 0de71b5a0..3049d44c2 100644 --- a/android_icu4j/src/main/java/android/icu/number/Precision.java +++ b/android_icu4j/src/main/java/android/icu/number/Precision.java @@ -21,7 +21,7 @@ import android.icu.util.Currency.CurrencyUsage; * * @see NumberFormatter */ -public abstract class Precision implements Cloneable { +public abstract class Precision { /* package-private final */ MathContext mathContext; @@ -324,24 +324,13 @@ public abstract class Precision implements Cloneable { if (this.mathContext.equals(mathContext)) { return this; } - Precision other = (Precision) this.clone(); + Precision other = createCopy(); other.mathContext = mathContext; return other; } - /** - * {@inheritDoc} - * @hide draft / provisional / internal are hidden on Android - */ - @Override - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException e) { - // Should not happen since parent is Object - throw new AssertionError(e); - } - } + /** Package-private clone method */ + abstract Precision createCopy(); /** * @deprecated ICU 60 This API is ICU internal only. @@ -549,6 +538,13 @@ public abstract class Precision implements Cloneable { value.roundToInfinity(); value.setMinFraction(0); } + + @Override + InfiniteRounderImpl createCopy() { + InfiniteRounderImpl copy = new InfiniteRounderImpl(); + copy.mathContext = mathContext; + return copy; + } } static class FractionRounderImpl extends FractionPrecision { @@ -565,6 +561,13 @@ public abstract class Precision implements Cloneable { value.roundToMagnitude(getRoundingMagnitudeFraction(maxFrac), mathContext); value.setMinFraction(Math.max(0, -getDisplayMagnitudeFraction(minFrac))); } + + @Override + FractionRounderImpl createCopy() { + FractionRounderImpl copy = new FractionRounderImpl(minFrac, maxFrac); + copy.mathContext = mathContext; + return copy; + } } static class SignificantRounderImpl extends Precision { @@ -594,6 +597,13 @@ public abstract class Precision implements Cloneable { assert quantity.isZeroish(); quantity.setMinFraction(minSig - minInt); } + + @Override + SignificantRounderImpl createCopy() { + SignificantRounderImpl copy = new SignificantRounderImpl(minSig, maxSig); + copy.mathContext = mathContext; + return copy; + } } static class FracSigRounderImpl extends Precision { @@ -625,6 +635,13 @@ public abstract class Precision implements Cloneable { value.roundToMagnitude(roundingMag, mathContext); value.setMinFraction(Math.max(0, -displayMag)); } + + @Override + FracSigRounderImpl createCopy() { + FracSigRounderImpl copy = new FracSigRounderImpl(minFrac, maxFrac, minSig, maxSig); + copy.mathContext = mathContext; + return copy; + } } /** @@ -642,6 +659,13 @@ public abstract class Precision implements Cloneable { value.roundToIncrement(increment, mathContext); value.setMinFraction(increment.scale()); } + + @Override + IncrementRounderImpl createCopy() { + IncrementRounderImpl copy = new IncrementRounderImpl(increment); + copy.mathContext = mathContext; + return copy; + } } /** @@ -664,6 +688,13 @@ public abstract class Precision implements Cloneable { value.roundToMagnitude(-maxFrac, mathContext); value.setMinFraction(minFrac); } + + @Override + IncrementOneRounderImpl createCopy() { + IncrementOneRounderImpl copy = new IncrementOneRounderImpl(increment, minFrac, maxFrac); + copy.mathContext = mathContext; + return copy; + } } /** @@ -684,6 +715,13 @@ public abstract class Precision implements Cloneable { value.roundToNickel(-maxFrac, mathContext); value.setMinFraction(minFrac); } + + @Override + IncrementFiveRounderImpl createCopy() { + IncrementFiveRounderImpl copy = new IncrementFiveRounderImpl(increment, minFrac, maxFrac); + copy.mathContext = mathContext; + return copy; + } } static class CurrencyRounderImpl extends CurrencyPrecision { @@ -698,6 +736,13 @@ public abstract class Precision implements Cloneable { // Call .withCurrency() before .apply()! throw new AssertionError(); } + + @Override + CurrencyRounderImpl createCopy() { + CurrencyRounderImpl copy = new CurrencyRounderImpl(usage); + copy.mathContext = mathContext; + return copy; + } } static class PassThroughRounderImpl extends Precision { @@ -706,6 +751,13 @@ public abstract class Precision implements Cloneable { } @Override + Precision createCopy() { + PassThroughRounderImpl copy = new PassThroughRounderImpl(); + copy.mathContext = mathContext; + return copy; + } + + @Override public void apply(DecimalQuantity value) { // TODO: Assert that value has already been rounded } diff --git a/android_icu4j/src/main/java/android/icu/number/ScientificNotation.java b/android_icu4j/src/main/java/android/icu/number/ScientificNotation.java index a144a79d6..d5637afe3 100644 --- a/android_icu4j/src/main/java/android/icu/number/ScientificNotation.java +++ b/android_icu4j/src/main/java/android/icu/number/ScientificNotation.java @@ -27,7 +27,7 @@ import android.icu.text.NumberFormat; * * @see NumberFormatter */ -public class ScientificNotation extends Notation implements Cloneable { +public class ScientificNotation extends Notation { int engineeringInterval; boolean requireMinInt; @@ -60,7 +60,7 @@ public class ScientificNotation extends Notation implements Cloneable { */ public ScientificNotation withMinExponentDigits(int minExponentDigits) { if (minExponentDigits >= 1 && minExponentDigits <= RoundingUtils.MAX_INT_FRAC_SIG) { - ScientificNotation other = (ScientificNotation) this.clone(); + ScientificNotation other = createCopy(); other.minExponentDigits = minExponentDigits; return other; } else { @@ -84,22 +84,19 @@ public class ScientificNotation extends Notation implements Cloneable { * @see NumberFormatter */ public ScientificNotation withExponentSignDisplay(SignDisplay exponentSignDisplay) { - ScientificNotation other = (ScientificNotation) this.clone(); + ScientificNotation other = createCopy(); other.exponentSignDisplay = exponentSignDisplay; return other; } - /** - * @hide draft / provisional / internal are hidden on Android - */ - @Override - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException e) { - // Should not happen since parent is Object - throw new AssertionError(e); - } + /** Package-private clone method */ + ScientificNotation createCopy() { + return new ScientificNotation( + engineeringInterval, + requireMinInt, + minExponentDigits, + exponentSignDisplay + ); } /* package-private */ MicroPropsGenerator withLocaleData( |