Class MutableDouble

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

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

    • MutableDouble

      public MutableDouble(@NonNull Number aValue)
      Initialize with a certain value.
      Parameters:
      aValue - The value to be used.
    • MutableDouble

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

    • 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 double inc()
      Increment by 1 and return the modified value.
      Returns:
      The by 1 incremented value.
    • inc

      public double 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.
    • inc

      public double inc(@NonNull Number 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.
    • dec

      public double dec()
      Decrement by 1 and return the modified value.
      Returns:
      The by 1 decremented value.
    • dec

      public double 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.
    • dec

      public double dec(@NonNull Number 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.
    • divide

      public double divide(double dDivisor)
      Divide the current value by the given divisor.
      Parameters:
      dDivisor - The divisor to use.
      Returns:
      The new value after division.
    • divide

      public double divide(@NonNull Number aDivisor)
      Divide the current value by the given divisor.
      Parameters:
      aDivisor - The divisor to use. May not be null.
      Returns:
      The new value after division.
    • multiply

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

      public double multiply(@NonNull Number 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.
    • set

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

      public @NonNull EChange set(@NonNull Number 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 double getAndInc()
      Get the current value and then increment by 1.
      Returns:
      The value before incrementing.
    • incAndGet

      public double incAndGet()
      Increment by 1 and then get the new value.
      Returns:
      The value after incrementing.
    • compareTo

      public int compareTo(@NonNull MutableDouble rhs)
    • getClone

      public @NonNull MutableDouble 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