Class Decimal64
java.lang.Object
java.lang.Number
org.opendaylight.yangtools.yang.common.Decimal64
- All Implemented Interfaces:
Serializable,Comparable<Decimal64>,Immutable,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:
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal byteConverts thisBigDecimalto abyte, checking for lost information.final intfinal BigDecimalfinal doublefinal booleanfinal booleanA slightly faster version ofequals(Object).final floatfinal inthashCode()final intintValue()final intConverts thisBigDecimalto anint, checking for lost information.final longfinal longConverts thisBigDecimalto along, checking for lost information.static Decimal64maxValueIn(int scale) Return the maximum value supported in specified scale.static Decimal64minValueIn(int scale) Return the minimum value supported in specified scale.static Decimal64of(int scale, long unscaledValue) Return aDecimal64with specified scale and unscaled value.final intscale()Return the scale of this decimal.scaleTo(int scale) Return this decimal in the specified scale.scaleTo(int scale, RoundingMode roundingMode) Return this decimal in the specified scale.final shortConverts thisBigDecimalto ashort, checking for lost information.final CanonicalValueSupport<Decimal64>support()Return theCanonicalValueassociated with this type.final StringReturn the canonical string representation of this value.final StringtoString()final longReturn the unscaled value of this decimal.static Decimal64valueOf(double doubleVal, RoundingMode rounding) static Decimal64valueOf(float floatVal, RoundingMode rounding) static Decimal64valueOf(int scale, byte byteVal) static Decimal64valueOf(int scale, int intVal) static Decimal64valueOf(int scale, long longVal) static Decimal64valueOf(int scale, short shortVal) static Decimal64Attempt to parse a String into a Decimal64.static Decimal64valueOf(BigDecimal decimalVal) Methods inherited from class java.lang.Number
byteValue, shortValueMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.opendaylight.yangtools.yang.common.CanonicalValue
validator
-
Constructor Details
-
Decimal64
-
-
Method Details
-
of
Return aDecimal64with specified scale and unscaled value.- Parameters:
scale- scale to useunscaledValue- unscaled value to use- Returns:
- A Decimal64 instance
- Throws:
IllegalArgumentException- ifscaleis not in range[1..18]
-
minValueIn
Return the minimum value supported in specified scale.- Parameters:
scale- scale to use- Returns:
- Minimum value in that scale
- Throws:
IllegalArgumentException- ifscaleis not in range[1..18]
-
maxValueIn
Return the maximum value supported in specified scale.- Parameters:
scale- scale to use- Returns:
- Maximum value in that scale
- Throws:
IllegalArgumentException- ifscaleis not in range[1..18]
-
valueOf
-
valueOf
-
valueOf
-
valueOf
-
valueOf
-
valueOf
-
valueOf
-
valueOf
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
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
Return this decimal in the specified scale.- Parameters:
scale- scaleroundingMode- rounding mode- Returns:
- Scaled number
- Throws:
ArithmeticException- if the conversion would overflow or require rounding androundingModeisRoundingMode.UNNECESSARY.IllegalArgumentException- ifscaleis not validNullPointerException- ifroundingModeisnull
-
decimalValue
-
intValue
public final int intValue() -
longValue
public final long longValue() -
floatValue
public final float floatValue()- Specified by:
floatValuein classNumber
-
doubleValue
public final double doubleValue()- Specified by:
doubleValuein classNumber
-
byteValueExact
public final byte byteValueExact()Converts thisBigDecimalto abyte, checking for lost information. If thisDecimal64has a nonzero fractional part or is out of the possible range for abyteresult then anArithmeticExceptionis thrown.- Returns:
- this
Decimal64converted to abyte. - Throws:
ArithmeticException- ifthishas a nonzero fractional part, or will not fit in abyte.
-
shortValueExact
public final short shortValueExact()Converts thisBigDecimalto ashort, checking for lost information. If thisDecimal64has a nonzero fractional part or is out of the possible range for ashortresult then anArithmeticExceptionis thrown.- Returns:
- this
Decimal64converted to ashort. - Throws:
ArithmeticException- ifthishas a nonzero fractional part, or will not fit in ashort.
-
intValueExact
public final int intValueExact()Converts thisBigDecimalto anint, checking for lost information. If thisDecimal64has a nonzero fractional part or is out of the possible range for anintresult then anArithmeticExceptionis thrown.- Returns:
- this
Decimal64converted to anint. - Throws:
ArithmeticException- ifthishas a nonzero fractional part, or will not fit in anint.
-
longValueExact
public final long longValueExact()Converts thisBigDecimalto along, checking for lost information. If thisDecimal64has a nonzero fractional part then anArithmeticExceptionis thrown.- Returns:
- this
Decimal64converted to along. - Throws:
ArithmeticException- ifthishas a nonzero fractional part.
-
compareTo
- Specified by:
compareToin interfaceComparable<Decimal64>
-
toCanonicalString
Description copied from interface:CanonicalValueReturn the canonical string representation of this value.- Specified by:
toCanonicalStringin interfaceCanonicalValue<Decimal64>- Returns:
- Canonical string
-
support
Description copied from interface:CanonicalValueReturn theCanonicalValueassociated with this type. It can be used to create new instances of this representation.- Specified by:
supportin interfaceCanonicalValue<Decimal64>- Returns:
- A
CanonicalValueinstance.
-
hashCode
public final int hashCode() -
equals
-
equals
A slightly faster version ofequals(Object).- Parameters:
obj- Decimal64 object- Returns:
trueif this object is the same as the obj argument;falseotherwise.
-
toString
-