1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 // © 2017 and later: Unicode, Inc. and others. 3 // License & terms of use: http://www.unicode.org/copyright.html#License 4 package ohos.global.icu.impl.number; 5 6 import java.math.BigDecimal; 7 import java.math.MathContext; 8 import java.text.FieldPosition; 9 10 import ohos.global.icu.impl.StandardPlural; 11 import ohos.global.icu.impl.number.Modifier.Signum; 12 import ohos.global.icu.text.PluralRules; 13 import ohos.global.icu.text.UFieldPosition; 14 15 /** 16 * An interface representing a number to be processed by the decimal formatting pipeline. Includes 17 * methods for rounding, plural rules, and decimal digit extraction. 18 * 19 * <p> 20 * By design, this is NOT IMMUTABLE and NOT THREAD SAFE. It is intended to be an intermediate object 21 * holding state during a pass through the decimal formatting pipeline. 22 * 23 * <p> 24 * Implementations of this interface are free to use any internal storage mechanism. 25 * 26 * <p> 27 * TODO: Should I change this to an abstract class so that logic for min/max digits doesn't need to be 28 * copied to every implementation? 29 * @hide exposed on OHOS 30 */ 31 public interface DecimalQuantity extends PluralRules.IFixedDecimal { 32 /** 33 * Sets the minimum integer digits that this {@link DecimalQuantity} should generate. 34 * This method does not perform rounding. 35 * 36 * @param minInt 37 * The minimum number of integer digits. 38 */ setMinInteger(int minInt)39 public void setMinInteger(int minInt); 40 41 /** 42 * Sets the minimum fraction digits that this {@link DecimalQuantity} should generate. 43 * This method does not perform rounding. 44 * 45 * @param minFrac 46 * The minimum number of fraction digits. 47 */ setMinFraction(int minFrac)48 public void setMinFraction(int minFrac); 49 50 /** 51 * Truncates digits from the upper magnitude of the number in order to satisfy the 52 * specified maximum number of integer digits. 53 * 54 * @param maxInt 55 * The maximum number of integer digits. 56 */ applyMaxInteger(int maxInt)57 public void applyMaxInteger(int maxInt); 58 59 /** 60 * Rounds the number to a specified interval, such as 0.05. 61 * 62 * <p> 63 * If rounding to a power of ten, use the more efficient {@link #roundToMagnitude} instead. 64 * 65 * @param roundingInterval 66 * The increment to which to round. 67 * @param mathContext 68 * The {@link MathContext} to use if rounding is necessary. Undefined behavior if null. 69 */ roundToIncrement(BigDecimal roundingInterval, MathContext mathContext)70 public void roundToIncrement(BigDecimal roundingInterval, MathContext mathContext); 71 72 /** 73 * Rounds the number to the nearest multiple of 5 at the specified magnitude. 74 * For example, when magnitude == -2, this performs rounding to the nearest 0.05. 75 * 76 * @param magnitude 77 * The magnitude at which the digit should become either 0 or 5. 78 * @param mathContext 79 * Rounding strategy. 80 */ roundToNickel(int magnitude, MathContext mathContext)81 public void roundToNickel(int magnitude, MathContext mathContext); 82 83 /** 84 * Rounds the number to a specified magnitude (power of ten). 85 * 86 * @param roundingMagnitude 87 * The power of ten to which to round. For example, a value of -2 will round to 2 decimal 88 * places. 89 * @param mathContext 90 * The {@link MathContext} to use if rounding is necessary. Undefined behavior if null. 91 */ roundToMagnitude(int roundingMagnitude, MathContext mathContext)92 public void roundToMagnitude(int roundingMagnitude, MathContext mathContext); 93 94 /** 95 * Rounds the number to an infinite number of decimal points. This has no effect except for forcing 96 * the double in {@link DecimalQuantity_AbstractBCD} to adopt its exact representation. 97 */ roundToInfinity()98 public void roundToInfinity(); 99 100 /** 101 * Multiply the internal value. 102 * 103 * @param multiplicand 104 * The value by which to multiply. 105 */ multiplyBy(BigDecimal multiplicand)106 public void multiplyBy(BigDecimal multiplicand); 107 108 /** Flips the sign from positive to negative and back. */ negate()109 void negate(); 110 111 /** 112 * Scales the number by a power of ten. For example, if the value is currently "1234.56", calling 113 * this method with delta=-3 will change the value to "1.23456". 114 * 115 * @param delta 116 * The number of magnitudes of ten to change by. 117 */ adjustMagnitude(int delta)118 public void adjustMagnitude(int delta); 119 120 /** 121 * @return The power of ten corresponding to the most significant nonzero digit. 122 * @throws ArithmeticException 123 * If the value represented is zero. 124 */ getMagnitude()125 public int getMagnitude() throws ArithmeticException; 126 127 /** 128 * @return The value of the (suppressed) exponent after the number has been 129 * put into a notation with exponents (ex: compact, scientific). Ex: given 130 * the number 1000 as "1K" / "1E3", the return value will be 3 (positive). 131 */ getExponent()132 public int getExponent(); 133 134 /** 135 * Adjusts the value for the (suppressed) exponent stored when using 136 * notation with exponents (ex: compact, scientific). 137 * 138 * <p>Adjusting the exponent is decoupled from {@link #adjustMagnitude} in 139 * order to allow flexibility for {@link StandardPlural} to be selected in 140 * formatting (ex: for compact notation) either with or without the exponent 141 * applied in the value of the number. 142 * @param delta 143 * The value to adjust the exponent by. 144 */ adjustExponent(int delta)145 public void adjustExponent(int delta); 146 147 /** 148 * @return Whether the value represented by this {@link DecimalQuantity} is 149 * zero, infinity, or NaN. 150 */ isZeroish()151 public boolean isZeroish(); 152 153 /** @return Whether the value represented by this {@link DecimalQuantity} is less than zero. */ isNegative()154 public boolean isNegative(); 155 156 /** @return The appropriate value from the Signum enum. */ signum()157 public Signum signum(); 158 159 /** @return Whether the value represented by this {@link DecimalQuantity} is infinite. */ 160 @Override isInfinite()161 public boolean isInfinite(); 162 163 /** @return Whether the value represented by this {@link DecimalQuantity} is not a number. */ 164 @Override isNaN()165 public boolean isNaN(); 166 167 /** @return The value contained in this {@link DecimalQuantity} approximated as a double. */ toDouble()168 public double toDouble(); 169 toBigDecimal()170 public BigDecimal toBigDecimal(); 171 setToBigDecimal(BigDecimal input)172 public void setToBigDecimal(BigDecimal input); 173 maxRepresentableDigits()174 public int maxRepresentableDigits(); 175 176 // TODO: Should this method be removed, since DecimalQuantity implements IFixedDecimal now? 177 /** 178 * Computes the plural form for this number based on the specified set of rules. 179 * 180 * @param rules 181 * A {@link PluralRules} object representing the set of rules. 182 * @return The {@link StandardPlural} according to the PluralRules. If the plural form is not in the 183 * set of standard plurals, {@link StandardPlural#OTHER} is returned instead. 184 */ getStandardPlural(PluralRules rules)185 public StandardPlural getStandardPlural(PluralRules rules); 186 187 /** 188 * Gets the digit at the specified magnitude. For example, if the represented number is 12.3, 189 * getDigit(-1) returns 3, since 3 is the digit corresponding to 10^-1. 190 * 191 * @param magnitude 192 * The magnitude of the digit. 193 * @return The digit at the specified magnitude. 194 */ getDigit(int magnitude)195 public byte getDigit(int magnitude); 196 197 /** 198 * Gets the largest power of ten that needs to be displayed. The value returned by this function will 199 * be bounded between minInt and maxInt. 200 * 201 * @return The highest-magnitude digit to be displayed. 202 */ getUpperDisplayMagnitude()203 public int getUpperDisplayMagnitude(); 204 205 /** 206 * Gets the smallest power of ten that needs to be displayed. The value returned by this function 207 * will be bounded between -minFrac and -maxFrac. 208 * 209 * @return The lowest-magnitude digit to be displayed. 210 */ getLowerDisplayMagnitude()211 public int getLowerDisplayMagnitude(); 212 213 /** 214 * Returns the string in "plain" format (no exponential notation) using ASCII digits. 215 */ toPlainString()216 public String toPlainString(); 217 218 /** 219 * Like clone, but without the restrictions of the Cloneable interface clone. 220 * 221 * @return A copy of this instance which can be mutated without affecting this instance. 222 */ createCopy()223 public DecimalQuantity createCopy(); 224 225 /** 226 * Sets this instance to be equal to another instance. 227 * 228 * @param other 229 * The instance to copy from. 230 */ copyFrom(DecimalQuantity other)231 public void copyFrom(DecimalQuantity other); 232 233 /** This method is for internal testing only. */ getPositionFingerprint()234 public long getPositionFingerprint(); 235 236 /** 237 * If the given {@link FieldPosition} is a {@link UFieldPosition}, populates it with the fraction 238 * length and fraction long value. If the argument is not a {@link UFieldPosition}, nothing happens. 239 * 240 * @param fp 241 * The {@link UFieldPosition} to populate. 242 */ populateUFieldPosition(FieldPosition fp)243 public void populateUFieldPosition(FieldPosition fp); 244 } 245