public abstract class DecimalQuantity_AbstractBCD extends Object implements DecimalQuantity
| Modifier and Type | Field and Description |
|---|---|
protected int |
exponent
The value of the (suppressed) exponent after the number has been put into
a notation with exponents (ex: compact, scientific).
|
protected byte |
flags
A bitmask of properties relating to the number represented by this object.
|
protected static int |
INFINITY_FLAG |
protected boolean |
isApproximate
Whether the value in the BCD comes from the double fast path without having been rounded to ensure
correctness
|
protected int |
lReqPos |
protected static int |
NAN_FLAG |
protected static int |
NEGATIVE_FLAG |
protected int |
origDelta
The change in magnitude relative to the original double.
|
protected double |
origDouble
The original number provided by the user and which is represented in BCD.
|
protected int |
precision
The number of digits in the BCD.
|
protected int |
rReqPos |
protected int |
scale
The power of ten corresponding to the least significant digit in the BCD.
|
| Constructor and Description |
|---|
DecimalQuantity_AbstractBCD() |
| Modifier and Type | Method and Description |
|---|---|
void |
adjustExponent(int delta)
Adjusts the value for the (suppressed) exponent stored when using
notation with exponents (ex: compact, scientific).
|
void |
adjustMagnitude(int delta)
Scales the number by a power of ten.
|
void |
applyMaxInteger(int maxInt)
Truncates digits from the upper magnitude of the number in order to satisfy the
specified maximum number of integer digits.
|
protected abstract BigDecimal |
bcdToBigDecimal()
Returns a BigDecimal encoding the internal BCD value.
|
DecimalQuantity_AbstractBCD |
clear() |
protected abstract void |
compact()
Removes trailing zeros from the BCD (adjusting the scale as required) and then computes the
precision.
|
protected abstract void |
copyBcdFrom(DecimalQuantity _other) |
void |
copyFrom(DecimalQuantity _other)
Sets this instance to be equal to another instance.
|
boolean |
equals(Object other) |
boolean |
fitsInLong()
Returns whether or not a Long can fully represent the value stored in this DecimalQuantity.
|
byte |
getDigit(int magnitude)
Gets the digit at the specified magnitude.
|
protected abstract byte |
getDigitPos(int position)
Returns a single digit from the BCD list.
|
int |
getExponent() |
int |
getLowerDisplayMagnitude()
Gets the smallest power of ten that needs to be displayed.
|
int |
getMagnitude() |
double |
getPluralOperand(PluralRules.Operand operand) |
long |
getPositionFingerprint()
This method is for internal testing only.
|
StandardPlural |
getStandardPlural(PluralRules rules)
Computes the plural form for this number based on the specified set of rules.
|
int |
getUpperDisplayMagnitude()
Gets the largest power of ten that needs to be displayed.
|
boolean |
isHasIntegerValue() |
boolean |
isInfinite() |
boolean |
isNaN() |
boolean |
isNegative() |
boolean |
isZeroish() |
void |
multiplyBy(BigDecimal multiplicand)
Multiply the internal value.
|
void |
negate()
Flips the sign from positive to negative and back.
|
protected abstract void |
popFromLeft(int numDigits)
Directly removes digits from the front of the BCD list.
|
void |
populateUFieldPosition(FieldPosition fp)
If the given
FieldPosition is a UFieldPosition, populates it with the fraction
length and fraction long value. |
protected abstract void |
readBigIntegerToBcd(BigInteger input)
Sets the internal BCD state to represent the value in the given BigInteger.
|
protected abstract void |
readIntToBcd(int input)
Sets the internal BCD state to represent the value in the given int.
|
protected abstract void |
readLongToBcd(long input)
Sets the internal BCD state to represent the value in the given long.
|
void |
resetExponent()
Resets the DecimalQuantity to the value before adjustMagnitude and adjustExponent.
|
void |
roundToIncrement(BigDecimal roundingIncrement,
MathContext mathContext)
Rounds the number to a specified interval, such as 0.05.
|
void |
roundToInfinity()
Rounds the number to an infinite number of decimal points.
|
void |
roundToMagnitude(int magnitude,
MathContext mathContext)
Rounds the number to a specified magnitude (power of ten).
|
void |
roundToNickel(int magnitude,
MathContext mathContext)
Rounds the number to the nearest multiple of 5 at the specified magnitude.
|
protected abstract void |
setBcdToZero()
Sets the internal representation to zero.
|
protected abstract void |
setDigitPos(int position,
byte value)
Sets the digit in the BCD list.
|
void |
setMinFraction(int minFrac)
Sets the minimum fraction digits that this
DecimalQuantity should generate. |
void |
setMinInteger(int minInt)
Sets the minimum integer digits that this
DecimalQuantity should generate. |
void |
setToBigDecimal(BigDecimal n)
Sets the internal BCD state to represent the value in the given BigDecimal.
|
void |
setToBigInteger(BigInteger n) |
void |
setToDouble(double n)
Sets the internal BCD state to represent the value in the given double.
|
void |
setToInt(int n) |
void |
setToLong(long n) |
protected abstract void |
shiftLeft(int numDigits)
Adds zeros to the end of the BCD list.
|
protected abstract void |
shiftRight(int numDigits)
Removes digits from the end of the BCD list.
|
Modifier.Signum |
signum() |
BigDecimal |
toBigDecimal() |
double |
toDouble()
Returns a double approximating the internal BCD.
|
String |
toExponentString()
Returns the string using ASCII digits and using exponential notation for non-zero
exponents, following the UTS 35 specification for plural rule samples.
|
long |
toFractionLong(boolean includeTrailingZeros)
This returns a long representing the fraction digits of the number, as required by PluralRules.
|
long |
toLong(boolean truncateIfOverflow)
Returns a long approximating the decimal quantity.
|
String |
toPlainString()
Returns the string in "plain" format (no exponential notation) using ASCII digits.
|
void |
toPlainString(StringBuilder result) |
String |
toScientificString() |
void |
toScientificString(StringBuilder result) |
void |
truncate()
Removes all fraction digits.
|
clone, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcreateCopy, maxRepresentableDigitsprotected int scale
Note that in BigDecimal, the scale is defined differently: the number of digits
after the decimal place, which is the negative of our definition of scale.
protected int precision
This value must be re-calculated whenever the value in bcd changes by using
#computePrecisionAndCompact().
protected byte flags
protected static final int NEGATIVE_FLAG
protected static final int INFINITY_FLAG
protected static final int NAN_FLAG
protected double origDouble
protected int origDelta
protected boolean isApproximate
protected int lReqPos
protected int rReqPos
protected int exponent
public void copyFrom(DecimalQuantity _other)
DecimalQuantitycopyFrom in interface DecimalQuantity_other - The instance to copy from.public DecimalQuantity_AbstractBCD clear()
public void setMinInteger(int minInt)
DecimalQuantityDecimalQuantity should generate.
This method does not perform rounding.setMinInteger in interface DecimalQuantityminInt - The minimum number of integer digits.public void setMinFraction(int minFrac)
DecimalQuantityDecimalQuantity should generate.
This method does not perform rounding.setMinFraction in interface DecimalQuantityminFrac - The minimum number of fraction digits.public void applyMaxInteger(int maxInt)
DecimalQuantityapplyMaxInteger in interface DecimalQuantitymaxInt - The maximum number of integer digits.public long getPositionFingerprint()
DecimalQuantitygetPositionFingerprint in interface DecimalQuantitypublic void roundToIncrement(BigDecimal roundingIncrement, MathContext mathContext)
DecimalQuantity
If rounding to a power of ten, use the more efficient DecimalQuantity.roundToMagnitude(int, java.math.MathContext) instead.
roundToIncrement in interface DecimalQuantityroundingIncrement - The increment to which to round.mathContext - The MathContext to use if rounding is necessary. Undefined behavior if null.public void multiplyBy(BigDecimal multiplicand)
DecimalQuantitymultiplyBy in interface DecimalQuantitymultiplicand - The value by which to multiply.public void negate()
DecimalQuantitynegate in interface DecimalQuantitypublic int getMagnitude()
throws ArithmeticException
getMagnitude in interface DecimalQuantityArithmeticException - If the value represented is zero.public void adjustMagnitude(int delta)
DecimalQuantityadjustMagnitude in interface DecimalQuantitydelta - The number of magnitudes of ten to change by.public int getExponent()
getExponent in interface DecimalQuantitypublic void adjustExponent(int delta)
DecimalQuantityAdjusting the exponent is decoupled from DecimalQuantity.adjustMagnitude(int) in
order to allow flexibility for StandardPlural to be selected in
formatting (ex: for compact notation) either with or without the exponent
applied in the value of the number.
adjustExponent in interface DecimalQuantitydelta - The value to adjust the exponent by.public void resetExponent()
DecimalQuantityresetExponent in interface DecimalQuantitypublic boolean isHasIntegerValue()
public StandardPlural getStandardPlural(PluralRules rules)
DecimalQuantitygetStandardPlural in interface DecimalQuantityrules - A PluralRules object representing the set of rules.StandardPlural according to the PluralRules. If the plural form is not in the
set of standard plurals, StandardPlural.OTHER is returned instead.public double getPluralOperand(PluralRules.Operand operand)
public void populateUFieldPosition(FieldPosition fp)
DecimalQuantityFieldPosition is a UFieldPosition, populates it with the fraction
length and fraction long value. If the argument is not a UFieldPosition, nothing happens.populateUFieldPosition in interface DecimalQuantityfp - The UFieldPosition to populate.public int getUpperDisplayMagnitude()
DecimalQuantitygetUpperDisplayMagnitude in interface DecimalQuantitypublic int getLowerDisplayMagnitude()
DecimalQuantitygetLowerDisplayMagnitude in interface DecimalQuantitypublic byte getDigit(int magnitude)
DecimalQuantitygetDigit in interface DecimalQuantitymagnitude - The magnitude of the digit.public boolean isNegative()
isNegative in interface DecimalQuantityDecimalQuantity is less than zero.public Modifier.Signum signum()
signum in interface DecimalQuantitypublic boolean isInfinite()
isInfinite in interface DecimalQuantityDecimalQuantity is infinite.public boolean isNaN()
isNaN in interface DecimalQuantityDecimalQuantity is not a number.public boolean isZeroish()
isZeroish in interface DecimalQuantityDecimalQuantity is
zero, infinity, or NaN.public void setToInt(int n)
public void setToLong(long n)
public void setToBigInteger(BigInteger n)
public void setToDouble(double n)
n - The value to consume.public void setToBigDecimal(BigDecimal n)
setToBigDecimal in interface DecimalQuantityn - The value to consume.public long toLong(boolean truncateIfOverflow)
DecimalQuantitygetExponent (for cases such as compact notation) to return the proper long
value represented by the result.toLong in interface DecimalQuantitytruncateIfOverflow - if false and the number does NOT fit, fails with an error.
See comment about call site guards in DecimalQuantity_AbstractBCD.javapublic long toFractionLong(boolean includeTrailingZeros)
exponent
(for cases such as compact notation) to return the proper long value
represented by the result.public boolean fitsInLong()
public double toDouble()
toDouble in interface DecimalQuantitypublic BigDecimal toBigDecimal()
toBigDecimal in interface DecimalQuantitypublic void truncate()
public void roundToNickel(int magnitude,
MathContext mathContext)
DecimalQuantityroundToNickel in interface DecimalQuantitymagnitude - The magnitude at which the digit should become either 0 or 5.mathContext - Rounding strategy.public void roundToMagnitude(int magnitude,
MathContext mathContext)
DecimalQuantityroundToMagnitude in interface DecimalQuantitymagnitude - The power of ten to which to round. For example, a value of -2 will round to 2 decimal
places.mathContext - The MathContext to use if rounding is necessary. Undefined behavior if null.public void roundToInfinity()
DecimalQuantityDecimalQuantity_AbstractBCD to adopt its exact representation.roundToInfinity in interface DecimalQuantitypublic String toPlainString()
DecimalQuantitytoPlainString in interface DecimalQuantitypublic void toPlainString(StringBuilder result)
public String toScientificString()
public void toScientificString(StringBuilder result)
public String toExponentString()
DecimalQuantitytoExponentString in interface DecimalQuantityprotected abstract byte getDigitPos(int position)
position - The position of the digit to pop, counted in BCD units from the least significant
digit. If outside the range supported by the implementation, zero is returned.protected abstract void setDigitPos(int position,
byte value)
DecimalQuantity_AbstractBCD.compact() after setting the digit, and to ensure
that the precision field is updated to reflect the correct number of digits if a
nonzero digit is added to the decimal.position - The position of the digit to pop, counted in BCD units from the least significant
digit. If outside the range supported by the implementation, an AssertionError is
thrown.value - The digit to set at the specified location.protected abstract void shiftLeft(int numDigits)
DecimalQuantity_AbstractBCD.compact().numDigits - The number of zeros to add.protected abstract void shiftRight(int numDigits)
DecimalQuantity_AbstractBCD.compact().numDigits - The number of digits to remove.protected abstract void popFromLeft(int numDigits)
DecimalQuantity_AbstractBCD.compact() after this method.protected abstract void setBcdToZero()
protected abstract void readIntToBcd(int input)
n - The value to consume.protected abstract void readLongToBcd(long input)
n - The value to consume.protected abstract void readBigIntegerToBcd(BigInteger input)
n - The value to consume.protected abstract BigDecimal bcdToBigDecimal()
protected abstract void copyBcdFrom(DecimalQuantity _other)
protected abstract void compact()
This method must always be called when bcd changes in order for assumptions to be correct in
methods like DecimalQuantity_AbstractBCD.fractionCount().