@PublicEvolving public final class DecimalData extends Object implements Comparable<DecimalData>
DecimalType
.
This data structure is immutable and might store decimal values in a compact representation (as a long value) if values are small enough.
Modifier and Type | Method and Description |
---|---|
int |
compareTo(DecimalData that) |
DecimalData |
copy()
Returns a copy of this
DecimalData object. |
boolean |
equals(Object o) |
static DecimalData |
fromBigDecimal(BigDecimal bd,
int precision,
int scale)
Creates an instance of
DecimalData from a BigDecimal and the given precision
and scale. |
static DecimalData |
fromUnscaledBytes(byte[] unscaledBytes,
int precision,
int scale)
Creates an instance of
DecimalData from an unscaled byte array value and the given
precision and scale. |
static DecimalData |
fromUnscaledLong(long unscaledLong,
int precision,
int scale)
Creates an instance of
DecimalData from an unscaled long value and the given
precision and scale. |
int |
hashCode() |
boolean |
isCompact()
Returns whether the decimal value is small enough to be stored in a long.
|
static boolean |
isCompact(int precision)
Returns whether the decimal value is small enough to be stored in a long.
|
int |
precision()
Returns the precision of this
DecimalData . |
int |
scale()
Returns the scale of this
DecimalData . |
BigDecimal |
toBigDecimal()
Converts this
DecimalData into an instance of BigDecimal . |
String |
toString() |
byte[] |
toUnscaledBytes()
Returns a byte array describing the unscaled value of this
DecimalData . |
long |
toUnscaledLong()
Returns a long describing the unscaled value of this
DecimalData . |
static DecimalData |
zero(int precision,
int scale)
Creates an instance of
DecimalData for a zero value with the given precision and
scale. |
public int precision()
DecimalData
.
The precision is the number of digits in the unscaled value.
public int scale()
DecimalData
.public BigDecimal toBigDecimal()
DecimalData
into an instance of BigDecimal
.public long toUnscaledLong()
DecimalData
.ArithmeticException
- if this DecimalData
does not exactly fit in a long.public byte[] toUnscaledBytes()
DecimalData
.DecimalData
.public boolean isCompact()
public DecimalData copy()
DecimalData
object.public int compareTo(@Nonnull DecimalData that)
compareTo
in interface Comparable<DecimalData>
@Nullable public static DecimalData fromBigDecimal(BigDecimal bd, int precision, int scale)
DecimalData
from a BigDecimal
and the given precision
and scale.
The returned decimal value may be rounded to have the desired scale. The precision will be checked. If the precision overflows, null will be returned.
public static DecimalData fromUnscaledLong(long unscaledLong, int precision, int scale)
DecimalData
from an unscaled long value and the given
precision and scale.public static DecimalData fromUnscaledBytes(byte[] unscaledBytes, int precision, int scale)
DecimalData
from an unscaled byte array value and the given
precision and scale.@Nullable public static DecimalData zero(int precision, int scale)
DecimalData
for a zero value with the given precision and
scale.
The precision will be checked. If the precision overflows, null will be returned.
public static boolean isCompact(int precision)
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.