diff options
author | Victor Chang <vichang@google.com> | 2020-03-12 23:21:34 +0000 |
---|---|---|
committer | Victor Chang <vichang@google.com> | 2020-03-13 14:57:39 +0000 |
commit | dce2772864d2436d3ccd4b2657a54a5370cb594a (patch) | |
tree | fcad57b5c2ca5977db9bed1cb7febaaf2b9d4311 /icu4j/main/classes/core/src/com | |
parent | 1f09f12add39877c300cbb0bb1ac33e0e484c568 (diff) | |
download | icu-dce2772864d2436d3ccd4b2657a54a5370cb594a.tar.gz |
Cherry-pick: ICU-20806 Remove "implements Cloneable" from android.icu.number.Precision and ScientificNotation
This CL replaces clone() with a new hidden createCopy() method
A partial cherry-pick from https://github.com/unicode-org/icu/pull/1034
Bug: 151133612
Test: m droid
Merged-In: I4c09b38fc1f266b493d9f99ee1b27f10ccac4215
Change-Id: I4c09b38fc1f266b493d9f99ee1b27f10ccac4215
(cherry picked from commit bc87dcacd4f90a0f0108316750e56dd8c1d28eaf)
Diffstat (limited to 'icu4j/main/classes/core/src/com')
-rw-r--r-- | icu4j/main/classes/core/src/com/ibm/icu/number/Precision.java | 83 | ||||
-rw-r--r-- | icu4j/main/classes/core/src/com/ibm/icu/number/ScientificNotation.java | 26 |
2 files changed, 78 insertions, 31 deletions
diff --git a/icu4j/main/classes/core/src/com/ibm/icu/number/Precision.java b/icu4j/main/classes/core/src/com/ibm/icu/number/Precision.java index 0aa395f8b..3a70c79de 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/number/Precision.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/number/Precision.java @@ -21,7 +21,7 @@ import com.ibm.icu.util.Currency.CurrencyUsage; * @stable ICU 62 * @see NumberFormatter */ -public abstract class Precision implements Cloneable { +public abstract class Precision { /* package-private final */ MathContext mathContext; @@ -336,25 +336,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} - * @draft ICU 62 - * @provisional This API might change or be removed in a future release. - */ - @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(); /** * @internal @@ -562,6 +550,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 { @@ -578,6 +573,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 { @@ -607,6 +609,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 { @@ -638,6 +647,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; + } } /** @@ -655,6 +671,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; + } } /** @@ -677,6 +700,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; + } } /** @@ -697,6 +727,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 { @@ -711,6 +748,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 { @@ -719,6 +763,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/icu4j/main/classes/core/src/com/ibm/icu/number/ScientificNotation.java b/icu4j/main/classes/core/src/com/ibm/icu/number/ScientificNotation.java index 10945cd85..cc3dd7710 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/number/ScientificNotation.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/number/ScientificNotation.java @@ -27,7 +27,7 @@ import com.ibm.icu.text.NumberFormat; * @stable ICU 60 * @see NumberFormatter */ -public class ScientificNotation extends Notation implements Cloneable { +public class ScientificNotation extends Notation { int engineeringInterval; boolean requireMinInt; @@ -61,7 +61,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 { @@ -86,23 +86,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; } - /** - * @draft ICU 60 - * @provisional This API might change or be removed in a future release. - */ - @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( |