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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal byte
Converts thisBigDecimal
to abyte
, checking for lost information.final int
final BigDecimal
final double
final boolean
final boolean
A slightly faster version ofequals(Object)
.final float
final int
hashCode()
final int
intValue()
final int
Converts thisBigDecimal
to anint
, checking for lost information.final long
final long
Converts thisBigDecimal
to along
, checking for lost information.static Decimal64
maxValueIn
(int scale) Return the maximum value supported in specified scale.static Decimal64
minValueIn
(int scale) Return the minimum value supported in specified scale.static Decimal64
of
(int scale, long unscaledValue) Return aDecimal64
with specified scale and unscaled value.final int
scale()
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 short
Converts thisBigDecimal
to ashort
, checking for lost information.final CanonicalValueSupport<Decimal64>
support()
Return theCanonicalValue
associated with this type.final String
Return the canonical string representation of this value.final String
toString()
final long
Return the unscaled value of this decimal.static Decimal64
valueOf
(double doubleVal, RoundingMode rounding) static Decimal64
valueOf
(float floatVal, RoundingMode rounding) static Decimal64
valueOf
(int scale, byte byteVal) static Decimal64
valueOf
(int scale, int intVal) static Decimal64
valueOf
(int scale, long longVal) static Decimal64
valueOf
(int scale, short shortVal) static Decimal64
Attempt to parse a String into a Decimal64.static Decimal64
valueOf
(BigDecimal decimalVal) Methods inherited from class java.lang.Number
byteValue, shortValue
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.opendaylight.yangtools.yang.common.CanonicalValue
validator
-
Constructor Details
-
Decimal64
-
-
Method Details
-
of
Return aDecimal64
with specified scale and unscaled value.- Parameters:
scale
- scale to useunscaledValue
- unscaled value to use- Returns:
- A Decimal64 instance
- Throws:
IllegalArgumentException
- ifscale
is 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
- ifscale
is 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
- ifscale
is 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 androundingMode
isRoundingMode.UNNECESSARY
.IllegalArgumentException
- ifscale
is not validNullPointerException
- ifroundingMode
isnull
-
decimalValue
-
intValue
public final int intValue() -
longValue
public final long longValue() -
floatValue
public final float floatValue()- Specified by:
floatValue
in classNumber
-
doubleValue
public final double doubleValue()- Specified by:
doubleValue
in classNumber
-
byteValueExact
public final byte byteValueExact()Converts thisBigDecimal
to abyte
, checking for lost information. If thisDecimal64
has a nonzero fractional part or is out of the possible range for abyte
result then anArithmeticException
is thrown.- Returns:
- this
Decimal64
converted to abyte
. - Throws:
ArithmeticException
- ifthis
has a nonzero fractional part, or will not fit in abyte
.
-
shortValueExact
public final short shortValueExact()Converts thisBigDecimal
to ashort
, checking for lost information. If thisDecimal64
has a nonzero fractional part or is out of the possible range for ashort
result then anArithmeticException
is thrown.- Returns:
- this
Decimal64
converted to ashort
. - Throws:
ArithmeticException
- ifthis
has a nonzero fractional part, or will not fit in ashort
.
-
intValueExact
public final int intValueExact()Converts thisBigDecimal
to anint
, checking for lost information. If thisDecimal64
has a nonzero fractional part or is out of the possible range for anint
result then anArithmeticException
is thrown.- Returns:
- this
Decimal64
converted to anint
. - Throws:
ArithmeticException
- ifthis
has a nonzero fractional part, or will not fit in anint
.
-
longValueExact
public final long longValueExact()Converts thisBigDecimal
to along
, checking for lost information. If thisDecimal64
has a nonzero fractional part then anArithmeticException
is thrown.- Returns:
- this
Decimal64
converted to along
. - Throws:
ArithmeticException
- ifthis
has a nonzero fractional part.
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Decimal64>
-
toCanonicalString
Description copied from interface:CanonicalValue
Return the canonical string representation of this value.- Specified by:
toCanonicalString
in interfaceCanonicalValue<Decimal64>
- Returns:
- Canonical string
-
support
Description copied from interface:CanonicalValue
Return theCanonicalValue
associated with this type. It can be used to create new instances of this representation.- Specified by:
support
in interfaceCanonicalValue<Decimal64>
- Returns:
- A
CanonicalValue
instance.
-
hashCode
public final int hashCode() -
equals
-
equals
A slightly faster version ofequals(Object)
.- Parameters:
obj
- Decimal64 object- Returns:
true
if this object is the same as the obj argument;false
otherwise.
-
toString
-