Class DecimalQuantity_DualStorageBCD

java.lang.Object
com.ibm.icu.impl.number.DecimalQuantity_AbstractBCD
com.ibm.icu.impl.number.DecimalQuantity_DualStorageBCD
All Implemented Interfaces:
DecimalQuantity, PluralRules.IFixedDecimal

public final class DecimalQuantity_DualStorageBCD extends DecimalQuantity_AbstractBCD
A DecimalQuantity with internal storage as a 64-bit BCD, with fallback to a byte array for numbers that don't fit into the standard BCD.
  • Field Details

    • bcdBytes

      private byte[] bcdBytes
      The BCD of the 16 digits of the number represented by this object. Every 4 bits of the long map to one digit. For example, the number "12345" in BCD is "0x12345".

      Whenever bcd changes internally, compact() must be called, except in special cases like setting the digit to zero.

    • bcdLong

      private long bcdLong
    • usingBytes

      private boolean usingBytes
  • Constructor Details

    • DecimalQuantity_DualStorageBCD

      public DecimalQuantity_DualStorageBCD()
    • DecimalQuantity_DualStorageBCD

      public DecimalQuantity_DualStorageBCD(long input)
    • DecimalQuantity_DualStorageBCD

      public DecimalQuantity_DualStorageBCD(int input)
    • DecimalQuantity_DualStorageBCD

      public DecimalQuantity_DualStorageBCD(double input)
    • DecimalQuantity_DualStorageBCD

      public DecimalQuantity_DualStorageBCD(BigInteger input)
    • DecimalQuantity_DualStorageBCD

      public DecimalQuantity_DualStorageBCD(BigDecimal input)
    • DecimalQuantity_DualStorageBCD

      public DecimalQuantity_DualStorageBCD(DecimalQuantity_DualStorageBCD other)
    • DecimalQuantity_DualStorageBCD

      public DecimalQuantity_DualStorageBCD(Number number)
  • Method Details

    • maxRepresentableDigits

      public int maxRepresentableDigits()
    • createCopy

      public DecimalQuantity createCopy()
      Description copied from interface: DecimalQuantity
      Like clone, but without the restrictions of the Cloneable interface clone.
      Returns:
      A copy of this instance which can be mutated without affecting this instance.
    • fromExponentString

      public static DecimalQuantity fromExponentString(String num)
      Returns a DecimalQuantity after parsing the input string.
      Parameters:
      s - The String to parse
    • getVisibleFractionCount

      private static int getVisibleFractionCount(String value)
    • getDigitPos

      protected byte getDigitPos(int position)
      Description copied from class: DecimalQuantity_AbstractBCD
      Returns a single digit from the BCD list. No internal state is changed by calling this method.
      Specified by:
      getDigitPos in class DecimalQuantity_AbstractBCD
      Parameters:
      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.
      Returns:
      The digit at the specified location.
    • setDigitPos

      protected void setDigitPos(int position, byte value)
      Description copied from class: DecimalQuantity_AbstractBCD
      Sets the digit in the BCD list. This method only sets the digit; it is the caller's responsibility to call 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.
      Specified by:
      setDigitPos in class DecimalQuantity_AbstractBCD
      Parameters:
      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.
    • shiftLeft

      protected void shiftLeft(int numDigits)
      Description copied from class: DecimalQuantity_AbstractBCD
      Adds zeros to the end of the BCD list. This will result in an invalid BCD representation; it is the caller's responsibility to do further manipulation and then call DecimalQuantity_AbstractBCD.compact().
      Specified by:
      shiftLeft in class DecimalQuantity_AbstractBCD
      Parameters:
      numDigits - The number of zeros to add.
    • shiftRight

      protected void shiftRight(int numDigits)
      Description copied from class: DecimalQuantity_AbstractBCD
      Removes digits from the end of the BCD list. This may result in an invalid BCD representation; it is the caller's responsibility to follow-up with a call to DecimalQuantity_AbstractBCD.compact().
      Specified by:
      shiftRight in class DecimalQuantity_AbstractBCD
      Parameters:
      numDigits - The number of digits to remove.
    • popFromLeft

      protected void popFromLeft(int numDigits)
      Description copied from class: DecimalQuantity_AbstractBCD
      Directly removes digits from the front of the BCD list. Updates precision. CAUTION: it is the caller's responsibility to call DecimalQuantity_AbstractBCD.compact() after this method.
      Specified by:
      popFromLeft in class DecimalQuantity_AbstractBCD
    • setBcdToZero

      protected void setBcdToZero()
      Description copied from class: DecimalQuantity_AbstractBCD
      Sets the internal representation to zero. Clears any values stored in scale, precision, hasDouble, origDouble, origDelta, exponent, and BCD data.
      Specified by:
      setBcdToZero in class DecimalQuantity_AbstractBCD
    • readIntToBcd

      protected void readIntToBcd(int n)
      Description copied from class: DecimalQuantity_AbstractBCD
      Sets the internal BCD state to represent the value in the given int. The int is guaranteed to be either positive. The internal state is guaranteed to be empty when this method is called.
      Specified by:
      readIntToBcd in class DecimalQuantity_AbstractBCD
    • readLongToBcd

      protected void readLongToBcd(long n)
      Description copied from class: DecimalQuantity_AbstractBCD
      Sets the internal BCD state to represent the value in the given long. The long is guaranteed to be either positive. The internal state is guaranteed to be empty when this method is called.
      Specified by:
      readLongToBcd in class DecimalQuantity_AbstractBCD
    • readBigIntegerToBcd

      protected void readBigIntegerToBcd(BigInteger n)
      Description copied from class: DecimalQuantity_AbstractBCD
      Sets the internal BCD state to represent the value in the given BigInteger. The BigInteger is guaranteed to be positive, and it is guaranteed to be larger than Long.MAX_VALUE. The internal state is guaranteed to be empty when this method is called.
      Specified by:
      readBigIntegerToBcd in class DecimalQuantity_AbstractBCD
    • bcdToBigDecimal

      protected BigDecimal bcdToBigDecimal()
      Description copied from class: DecimalQuantity_AbstractBCD
      Returns a BigDecimal encoding the internal BCD value.
      Specified by:
      bcdToBigDecimal in class DecimalQuantity_AbstractBCD
      Returns:
      A BigDecimal representation of the internal BCD.
    • compact

      protected void compact()
      Description copied from class: DecimalQuantity_AbstractBCD
      Removes trailing zeros from the BCD (adjusting the scale as required) and then computes the precision. The precision is the number of digits in the number up through the greatest nonzero digit.

      This method must always be called when bcd changes in order for assumptions to be correct in methods like DecimalQuantity_AbstractBCD.fractionCount().

      Specified by:
      compact in class DecimalQuantity_AbstractBCD
    • ensureCapacity

      private void ensureCapacity()
      Ensure that a byte array of at least 40 digits is allocated.
    • ensureCapacity

      private void ensureCapacity(int capacity)
    • switchStorage

      private void switchStorage()
      Switches the internal storage mechanism between the 64-bit long and the byte array.
    • copyBcdFrom

      protected void copyBcdFrom(DecimalQuantity _other)
      Specified by:
      copyBcdFrom in class DecimalQuantity_AbstractBCD
    • checkHealth

      @Deprecated public String checkHealth()
      Deprecated.
      This API is for ICU internal use only.
      Checks whether the bytes stored in this instance are all valid. For internal unit testing only.
      Returns:
      An error message if this instance is invalid, or null if this instance is healthy.
    • isUsingBytes

      @Deprecated public boolean isUsingBytes()
      Deprecated.
      This API is ICU internal only.
      Checks whether this DecimalQuantity_DualStorageBCD is using its internal byte array storage mechanism.
      Returns:
      true if an internal byte array is being used; false if a long is being used.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toNumberString

      private String toNumberString()