summaryrefslogtreecommitdiff
path: root/android_icu4j/src/main/java/android/icu/number/Precision.java
diff options
context:
space:
mode:
Diffstat (limited to 'android_icu4j/src/main/java/android/icu/number/Precision.java')
-rw-r--r--android_icu4j/src/main/java/android/icu/number/Precision.java82
1 files changed, 67 insertions, 15 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
}