Class Decimal64

java.lang.Object
java.lang.Number
org.opendaylight.yangtools.yang.common.Decimal64
All Implemented Interfaces:
Serializable, Comparable<Decimal64>, Immutable, CanonicalValue<Decimal64>

@NonNullByDefault public class Decimal64 extends Number implements CanonicalValue<Decimal64>
Dedicated type for YANG's 'type decimal64' type. This class is similar to BigDecimal, but provides more efficient storage, as it has fixed precision.
See Also:
  • Constructor Details

    • Decimal64

      protected Decimal64(Decimal64 other)
  • Method Details

    • of

      public static Decimal64 of(int scale, long unscaledValue)
      Return a Decimal64 with specified scale and unscaled value.
      Parameters:
      scale - scale to use
      unscaledValue - unscaled value to use
      Returns:
      A Decimal64 instance
      Throws:
      IllegalArgumentException - if scale is not in range [1..18]
    • minValueIn

      public static Decimal64 minValueIn(int scale)
      Return the minimum value supported in specified scale.
      Parameters:
      scale - scale to use
      Returns:
      Minimum value in that scale
      Throws:
      IllegalArgumentException - if scale is not in range [1..18]
    • maxValueIn

      public static Decimal64 maxValueIn(int scale)
      Return the maximum value supported in specified scale.
      Parameters:
      scale - scale to use
      Returns:
      Maximum value in that scale
      Throws:
      IllegalArgumentException - if scale is not in range [1..18]
    • valueOf

      public static Decimal64 valueOf(int scale, byte byteVal)
    • valueOf

      public static Decimal64 valueOf(int scale, short shortVal)
    • valueOf

      public static Decimal64 valueOf(int scale, int intVal)
    • valueOf

      public static Decimal64 valueOf(int scale, long longVal)
    • valueOf

      public static Decimal64 valueOf(float floatVal, RoundingMode rounding)
    • valueOf

      public static Decimal64 valueOf(double doubleVal, RoundingMode rounding)
    • valueOf

      public static Decimal64 valueOf(BigDecimal decimalVal)
    • valueOf

      public static Decimal64 valueOf(String str)
      Attempt to parse a String into a Decimal64. This method uses minimum fraction digits required to hold the entire value.
      Parameters:
      str - String to parser
      Returns:
      A Decimal64 instance
      Throws:
      NullPointerException - if value is null.
      NumberFormatException - if the string does not contain a parsable decimal64.
    • scale

      public final int scale()
      Return the scale of this decimal. This is the number of fraction digits, in range [1..18].
      Returns:
      This decimal's scale
    • unscaledValue

      public final long unscaledValue()
      Return the unscaled value of this decimal.
      Returns:
      This decimal's unscaled value
    • scaleTo

      public Decimal64 scaleTo(int scale)
      Return this decimal in the specified scale.
      Parameters:
      scale - target scale
      Returns:
      Scaled number
      Throws:
      ArithmeticException - if the conversion would overflow or require rounding
    • scaleTo

      public Decimal64 scaleTo(int scale, RoundingMode roundingMode)
      Return this decimal in the specified scale.
      Parameters:
      scale - scale
      roundingMode - rounding mode
      Returns:
      Scaled number
      Throws:
      ArithmeticException - if the conversion would overflow or require rounding and roundingMode is RoundingMode.UNNECESSARY.
      IllegalArgumentException - if scale is not valid
      NullPointerException - if roundingMode is null
    • decimalValue

      public final BigDecimal decimalValue()
    • intValue

      public final int intValue()
      Specified by:
      intValue in class Number
    • longValue

      public final long longValue()
      Specified by:
      longValue in class Number
    • floatValue

      public final float floatValue()
      Specified by:
      floatValue in class Number
    • doubleValue

      public final double doubleValue()
      Specified by:
      doubleValue in class Number
    • byteValueExact

      public final byte byteValueExact()
      Converts this BigDecimal to a byte, checking for lost information. If this Decimal64 has a nonzero fractional part or is out of the possible range for a byte result then an ArithmeticException is thrown.
      Returns:
      this Decimal64 converted to a byte.
      Throws:
      ArithmeticException - if this has a nonzero fractional part, or will not fit in a byte.
    • shortValueExact

      public final short shortValueExact()
      Converts this BigDecimal to a short, checking for lost information. If this Decimal64 has a nonzero fractional part or is out of the possible range for a short result then an ArithmeticException is thrown.
      Returns:
      this Decimal64 converted to a short.
      Throws:
      ArithmeticException - if this has a nonzero fractional part, or will not fit in a short.
    • intValueExact

      public final int intValueExact()
      Converts this BigDecimal to an int, checking for lost information. If this Decimal64 has a nonzero fractional part or is out of the possible range for an int result then an ArithmeticException is thrown.
      Returns:
      this Decimal64 converted to an int.
      Throws:
      ArithmeticException - if this has a nonzero fractional part, or will not fit in an int.
    • longValueExact

      public final long longValueExact()
      Converts this BigDecimal to a long, checking for lost information. If this Decimal64 has a nonzero fractional part then an ArithmeticException is thrown.
      Returns:
      this Decimal64 converted to a long.
      Throws:
      ArithmeticException - if this has a nonzero fractional part.
    • compareTo

      public final int compareTo(Decimal64 o)
      Specified by:
      compareTo in interface Comparable<Decimal64>
    • toCanonicalString

      public final String toCanonicalString()
      Description copied from interface: CanonicalValue
      Return the canonical string representation of this value.
      Specified by:
      toCanonicalString in interface CanonicalValue<Decimal64>
      Returns:
      Canonical string
    • support

      public final CanonicalValueSupport<Decimal64> support()
      Description copied from interface: CanonicalValue
      Return the CanonicalValue associated with this type. It can be used to create new instances of this representation.
      Specified by:
      support in interface CanonicalValue<Decimal64>
      Returns:
      A CanonicalValue instance.
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public final boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • equals

      public final boolean equals(@Nullable Decimal64 obj)
      A slightly faster version of equals(Object).
      Parameters:
      obj - Decimal64 object
      Returns:
      true if this object is the same as the obj argument; false otherwise.
    • toString

      public final String toString()
      Overrides:
      toString in class Object