Class CSSSimpleValueWithUnit

java.lang.Object
com.helger.css.propertyvalue.CSSSimpleValueWithUnit

@NotThreadSafe public class CSSSimpleValueWithUnit extends Object
This class encapsulates a single numeric value and a unit (ECSSUnit).
Author:
Philip Helger
  • Constructor Details

    • CSSSimpleValueWithUnit

      public CSSSimpleValueWithUnit(@Nonnull BigDecimal aValue, @Nonnull ECSSUnit eUnit)
      Constructor
      Parameters:
      aValue - Numeric value. May not be null.
      eUnit - CSS unit to use. May not be null.
    • CSSSimpleValueWithUnit

      public CSSSimpleValueWithUnit(double dValue, @Nonnull ECSSUnit eUnit)
      Constructor
      Parameters:
      dValue - Numeric value
      eUnit - CSS unit to use. May not be null.
  • Method Details

    • setValue

      Set the numerical value.
      Parameters:
      aValue - The new value to set. May not be null.
      Returns:
      this
      Since:
      3.7.3
    • setValue

      @Nonnull public CSSSimpleValueWithUnit setValue(double dValue)
      Set the numerical value.
      Parameters:
      dValue - The new value to set.
      Returns:
      this
      Since:
      3.7.3
    • getAsBigDecimalValue

      @Nonnull public BigDecimal getAsBigDecimalValue()
      Returns:
      The numeric value as a decimal value (as passed in the constructor)
      Since:
      3.7.3
    • getValue

      public double getValue()
      Returns:
      The numeric value as a decimal value (as passed in the constructor)
    • getAsIntValue

      public int getAsIntValue()
      Returns:
      The numeric value as an int value - no check for validity is performed
    • getAsLongValue

      public long getAsLongValue()
      Returns:
      The numeric value as a long value - no check for validity is performed
    • setUnit

      Set the unit type.
      Parameters:
      eUnit - The new unit to set. May not be null.
      Returns:
      this
      Since:
      3.7.3
    • getUnit

      @Nonnull public ECSSUnit getUnit()
      Returns:
      The CSS unit of this value. Never null.
    • getFormatted

      @Nonnull @Nonempty public String getFormatted()
      Returns:
      The formatted string value of this item. Neither null nor empty.
      Since:
      3.7.3
    • add

      Get a new object with the same unit but an added value.
      Parameters:
      aDelta - The delta to be added. May not be null.
      Returns:
      A new object. Never null.
      Since:
      3.7.3
    • add

      Get a new object with the same unit but an added value.
      Parameters:
      dDelta - The delta to be added.
      Returns:
      A new object. Never null.
    • substract

      Get a new object with the same unit but a subtracted value.
      Parameters:
      aDelta - The delta to be subtracted. May not be null.
      Returns:
      A new object. Never null.
      Since:
      3.7.3
    • substract

      @Nonnull @CheckReturnValue public CSSSimpleValueWithUnit substract(double dDelta)
      Get a new object with the same unit but a subtracted value.
      Parameters:
      dDelta - The delta to be subtracted.
      Returns:
      A new object. Never null.
    • multiply

      Get a new object with the same unit but a multiplied value.
      Parameters:
      aValue - The value to be multiply with this value. May not be null.
      Returns:
      A new object. Never null.
      Since:
      3.7.3
    • multiply

      @Nonnull @CheckReturnValue public CSSSimpleValueWithUnit multiply(double dValue)
      Get a new object with the same unit but a multiplied value.
      Parameters:
      dValue - The value to be multiply with this value.
      Returns:
      A new object. Never null.
    • divide

      Get a new object with the same unit but an divided value.
      Parameters:
      aDivisor - The divisor to use. May not be null.
      nScale - The maximum fraction digits to use.
      eRoundingMode - The rounding mode to use. May not be null.
      Returns:
      A new object. Never null.
      Since:
      3.7.3
    • divide

      Get a new object with the same unit but an divided value. By default CCSS.CSS_MAXIMUM_FRACTION_DIGITS is used as scale and RoundingMode.HALF_UP is used as rounding mode.
      Parameters:
      aDivisor - The divisor to use. May not be null.
      Returns:
      A new object. Never null.
      Since:
      3.7.3
    • divide

      @Nonnull @CheckReturnValue public CSSSimpleValueWithUnit divide(double dDivisor)
      Get a new object with the same unit but an divided value.
      Parameters:
      dDivisor - The divisor to use.
      Returns:
      A new object. Never null.
    • 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