Class MutableBigDecimal

All Implemented Interfaces:
ICloneable<MutableBigDecimal>, IComparable<MutableBigDecimal>, INumber, IMutableNumeric<MutableBigDecimal>, IMutableObject<MutableBigDecimal>, IGenericImplTrait<MutableBigDecimal>, Serializable, Comparable<MutableBigDecimal>

@NotThreadSafe public class MutableBigDecimal extends AbstractMutableNumeric<MutableBigDecimal>
Object wrapper around a BigDecimal so that it can be passed a final object but is mutable.
Author:
Philip Helger
See Also:
  • Constructor Details

    • MutableBigDecimal

      public MutableBigDecimal(long nValue)
      Initialize with a certain long value.
      Parameters:
      nValue - The value to be used.
    • MutableBigDecimal

      public MutableBigDecimal(double dValue)
      Initialize with a certain double value.
      Parameters:
      dValue - The value to be used.
    • MutableBigDecimal

      public MutableBigDecimal(@NonNull MutableBigDecimal aOther)
      Copy constructor.
      Parameters:
      aOther - The object to copy from. May not be null.
    • MutableBigDecimal

      public MutableBigDecimal(@NonNull BigDecimal aValue)
      Initialize with a certain BigDecimal value.
      Parameters:
      aValue - The value to be used. May not be null.
  • Method Details

    • getAsBigDecimal

      public @NonNull BigDecimal getAsBigDecimal()
    • doubleValue

      public double doubleValue()
      Description copied from interface: INumber
      Returns the value of the specified number as a double, which may involve rounding.
      Specified by:
      doubleValue in interface INumber
      Specified by:
      doubleValue in class Number
      Returns:
      the numeric value represented by this object after conversion to type double.
    • floatValue

      public float floatValue()
      Description copied from interface: INumber
      Returns the value of the specified number as a float, which may involve rounding.
      Specified by:
      floatValue in interface INumber
      Specified by:
      floatValue in class Number
      Returns:
      the numeric value represented by this object after conversion to type float.
    • intValue

      public int intValue()
      Description copied from interface: INumber
      Returns the value of the specified number as an int, which may involve rounding or truncation.
      Specified by:
      intValue in interface INumber
      Specified by:
      intValue in class Number
      Returns:
      the numeric value represented by this object after conversion to type int.
    • longValue

      public long longValue()
      Description copied from interface: INumber
      Returns the value of the specified number as a long, which may involve rounding or truncation.
      Specified by:
      longValue in interface INumber
      Specified by:
      longValue in class Number
      Returns:
      the numeric value represented by this object after conversion to type long.
    • inc

      public @NonNull BigDecimal inc()
      Increment by 1 and return the modified value.
      Returns:
      The by 1 incremented value.
    • inc

      public @NonNull BigDecimal inc(long nDelta)
      Increment by the given delta and return the modified value.
      Parameters:
      nDelta - The delta to add.
      Returns:
      The new value after incrementing. Never null.
    • inc

      public @NonNull BigDecimal inc(double dDelta)
      Increment by the given delta and return the modified value.
      Parameters:
      dDelta - The delta to add.
      Returns:
      The new value after incrementing. Never null.
    • inc

      public @NonNull BigDecimal inc(@NonNull MutableBigDecimal aDelta)
      Increment by the given delta and return the modified value.
      Parameters:
      aDelta - The delta to add. May not be null.
      Returns:
      The new value after incrementing. Never null.
    • inc

      public @NonNull BigDecimal inc(@NonNull BigDecimal aDelta)
      Increment by the given delta and return the modified value.
      Parameters:
      aDelta - The delta to add. May not be null.
      Returns:
      The new value after incrementing. Never null.
    • dec

      public @NonNull BigDecimal dec()
      Decrement by 1 and return the modified value.
      Returns:
      The by 1 decremented value. Never null.
    • dec

      public @NonNull BigDecimal dec(long nDelta)
      Decrement by the given delta and return the modified value.
      Parameters:
      nDelta - The delta to subtract.
      Returns:
      The new value after decrementing. Never null.
    • dec

      public @NonNull BigDecimal dec(double dDelta)
      Decrement by the given delta and return the modified value.
      Parameters:
      dDelta - The delta to subtract.
      Returns:
      The new value after decrementing. Never null.
    • dec

      public @NonNull BigDecimal dec(@NonNull BigDecimal aDelta)
      Decrement by the given delta and return the modified value.
      Parameters:
      aDelta - The delta to subtract. May not be null.
      Returns:
      The new value after decrementing. Never null.
    • dec

      public @NonNull BigDecimal dec(@NonNull MutableBigDecimal aDelta)
      Decrement by the given delta and return the modified value.
      Parameters:
      aDelta - The delta to subtract. May not be null.
      Returns:
      The new value after decrementing. Never null.
    • divide

      public @NonNull BigDecimal divide(long nDivisor, @Nonnegative int nScale, @NonNull RoundingMode eRoundingMode)
      Divide the current value by the given divisor.
      Parameters:
      nDivisor - The divisor to use.
      nScale - The scale for the division result.
      eRoundingMode - The rounding mode to use. May not be null.
      Returns:
      The new value after division. Never null.
    • divide

      public @NonNull BigDecimal divide(double dDivisor, @Nonnegative int nScale, @NonNull RoundingMode eRoundingMode)
      Divide the current value by the given divisor.
      Parameters:
      dDivisor - The divisor to use.
      nScale - The scale for the division result.
      eRoundingMode - The rounding mode to use. May not be null.
      Returns:
      The new value after division. Never null.
    • divide

      public @NonNull BigDecimal divide(@NonNull MutableBigDecimal aDivisor, @Nonnegative int nScale, @NonNull RoundingMode eRoundingMode)
      Divide the current value by the given divisor.
      Parameters:
      aDivisor - The divisor to use. May not be null.
      nScale - The scale for the division result.
      eRoundingMode - The rounding mode to use. May not be null.
      Returns:
      The new value after division. Never null.
    • divide

      public @NonNull BigDecimal divide(@NonNull BigDecimal aDivisor, @Nonnegative int nScale, @NonNull RoundingMode eRoundingMode)
      Divide the current value by the given divisor.
      Parameters:
      aDivisor - The divisor to use. May not be null.
      nScale - The scale for the division result.
      eRoundingMode - The rounding mode to use. May not be null.
      Returns:
      The new value after division. Never null.
    • multiply

      public @NonNull BigDecimal multiply(long nMultiplicand)
      Multiply the current value by the given multiplicand.
      Parameters:
      nMultiplicand - The multiplicand to use.
      Returns:
      The new value after multiplication. Never null.
    • multiply

      public @NonNull BigDecimal multiply(double dMultiplicand)
      Multiply the current value by the given multiplicand.
      Parameters:
      dMultiplicand - The multiplicand to use.
      Returns:
      The new value after multiplication. Never null.
    • multiply

      public @NonNull BigDecimal multiply(@NonNull MutableBigDecimal aMultiplicand)
      Multiply the current value by the given multiplicand.
      Parameters:
      aMultiplicand - The multiplicand to use. May not be null.
      Returns:
      The new value after multiplication. Never null.
    • multiply

      public @NonNull BigDecimal multiply(@NonNull BigDecimal aMultiplicand)
      Multiply the current value by the given multiplicand.
      Parameters:
      aMultiplicand - The multiplicand to use. May not be null.
      Returns:
      The new value after multiplication. Never null.
    • set

      public @NonNull EChange set(long nDelta)
      Set a new value.
      Parameters:
      nDelta - The new value to set.
      Returns:
      EChange.CHANGED if the value was changed.
    • set

      public @NonNull EChange set(double dDelta)
      Set a new value.
      Parameters:
      dDelta - The new value to set.
      Returns:
      EChange.CHANGED if the value was changed.
    • set

      public @NonNull EChange set(@NonNull MutableBigDecimal aValue)
      Set a new value.
      Parameters:
      aValue - The new value to set. May not be null.
      Returns:
      EChange.CHANGED if the value was changed.
    • set

      public @NonNull EChange set(@NonNull BigDecimal aValue)
      Set a new value.
      Parameters:
      aValue - The new value to set. May not be null.
      Returns:
      EChange.CHANGED if the value was changed.
    • is0

      public boolean is0()
      Returns:
      true if the value is 0
    • isLT0

      public boolean isLT0()
      Returns:
      true if the value is < 0
    • isLE0

      public boolean isLE0()
      Returns:
      true if the value is ≤ 0
    • isGT0

      public boolean isGT0()
      Returns:
      true if the value is > 0
    • isGE0

      public boolean isGE0()
      Returns:
      true if the value is ≥ 0
    • getAndInc

      public @NonNull BigDecimal getAndInc()
      Get the current value and then increment by 1.
      Returns:
      The value before incrementing. Never null.
    • incAndGet

      public @NonNull BigDecimal incAndGet()
      Increment by 1 and then get the new value.
      Returns:
      The value after incrementing. Never null.
    • compareTo

      public int compareTo(@NonNull MutableBigDecimal rhs)
    • getClone

      public @NonNull MutableBigDecimal getClone()
      Returns:
      A 100% deep-copy of the implementing class.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object