diff options
Diffstat (limited to 'icu4j/main/classes/core/src/com/ibm/icu/number/Precision.java')
-rw-r--r-- | icu4j/main/classes/core/src/com/ibm/icu/number/Precision.java | 83 |
1 files changed, 67 insertions, 16 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 } |