summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-03-14 02:55:33 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-03-14 02:55:33 +0000
commit98a71cf80265d84505dd00e59923cb4bdc7341b1 (patch)
treefcad57b5c2ca5977db9bed1cb7febaaf2b9d4311
parent1f09f12add39877c300cbb0bb1ac33e0e484c568 (diff)
parent9ffd1cf4392b014ce6299913c508bcdf1e560334 (diff)
downloadicu-98a71cf80265d84505dd00e59923cb4bdc7341b1.tar.gz
Cherry-pick: ICU-20806 Remove "implements Cloneable" from android.icu.number.Precision and ScientificNotation am: dce2772864 am: 9ffd1cf439
Change-Id: I7c1f538fbc1f5c1317f6f097763848edf4060f77
-rw-r--r--android_icu4j/src/main/java/android/icu/number/Precision.java82
-rw-r--r--android_icu4j/src/main/java/android/icu/number/ScientificNotation.java25
-rw-r--r--icu4j/main/classes/core/src/com/ibm/icu/number/Precision.java83
-rw-r--r--icu4j/main/classes/core/src/com/ibm/icu/number/ScientificNotation.java26
4 files changed, 156 insertions, 60 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(
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(