Class Decimal64
- java.lang.Object
-
- java.lang.Number
-
- org.opendaylight.yangtools.yang.common.Decimal64
-
- All Implemented Interfaces:
Serializable
,Comparable<Decimal64>
,Immutable
,MutationBehaviour<Immutable>
,CanonicalValue<Decimal64>
@Beta @NonNullByDefault public class Decimal64 extends Number implements CanonicalValue<Decimal64>
Dedicated type for YANG's 'type decimal64' type. This class is similar toBigDecimal
, but provides more efficient storage, as it has fixed precision.- Author:
- Robert Varga
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Decimal64.Support
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description byte
byteValueExact()
Converts thisBigDecimal
to abyte
, checking for lost information.int
compareTo(Decimal64 o)
BigDecimal
decimalValue()
double
doubleValue()
boolean
equals(@Nullable Object obj)
boolean
equals(@Nullable Decimal64 obj)
A slightly faster version ofequals(Object)
.float
floatValue()
int
hashCode()
int
intValue()
int
intValueExact()
Converts thisBigDecimal
to anint
, checking for lost information.long
longValue()
long
longValueExact()
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.int
scale()
Return the scale of this decimal.short
shortValueExact()
Converts thisBigDecimal
to ashort
, checking for lost information.CanonicalValueSupport<Decimal64>
support()
Return theCanonicalValue
associated with this type.String
toCanonicalString()
Return the canonical string representation of this value.String
toString()
long
unscaledValue()
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
valueOf(String str)
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 Detail
-
Decimal64
protected Decimal64(Decimal64 other)
-
-
Method Detail
-
of
public static Decimal64 of(int scale, long unscaledValue)
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
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
- ifscale
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
- ifscale
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
-
decimalValue
public final BigDecimal decimalValue()
-
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
public final int compareTo(Decimal64 o)
- Specified by:
compareTo
in interfaceComparable<Decimal64>
-
toCanonicalString
public final String toCanonicalString()
Description copied from interface:CanonicalValue
Return the canonical string representation of this value.- Specified by:
toCanonicalString
in interfaceCanonicalValue<Decimal64>
- Returns:
- Canonical string
-
support
public final CanonicalValueSupport<Decimal64> 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.
-
equals
public final boolean equals(@Nullable Decimal64 obj)
A slightly faster version ofequals(Object)
.- Parameters:
obj
- Decimal64 object- Returns:
true
if this object is the same as the obj argument;false
otherwise.
-
-