public interface JsonNumber extends JsonValue
JsonNumber
represents an immutable JSON number value
A BigDecimal
may be used to store the numeric value internally.
The BigDecimal
may be constructed using
,
int
,
long
,
BigInteger
and
double
.
Some of the method semantics in this class are defined using the
String
BigDecimal
semantics.
Modifier and Type | Interface and Description |
---|---|
static class |
JsonNumber.NumberType
JSON number type that is used to find out if a number is numerically
integer or a decimal.
|
JsonValue.ValueType
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj)
Compares the specified object with this JsonNumber for equality.
|
BigDecimal |
getBigDecimalValue()
Returns JSON number as a
BigDecimal |
BigInteger |
getBigIntegerValue()
Returns JSON number as a
BigInteger number. |
BigInteger |
getBigIntegerValueExact()
Returns JSON number as a
BigDecimal number. |
double |
getDoubleValue()
Returns JSON number as a
double number. |
int |
getIntValue()
Returns JSON number as an
int number. |
int |
getIntValueExact()
Returns JSON number as an
int number. |
long |
getLongValue()
Returns JSON number as a
long number. |
long |
getLongValueExact()
Returns JSON number as a
long number. |
JsonNumber.NumberType |
getNumberType()
Returns a JSON number type for this number.
|
int |
hashCode()
Returns the hash code value for this JsonNumber object.
|
String |
toString()
Returns a JSON representation of the JSON number value.
|
getValueType
JsonNumber.NumberType getNumberType()
BigDecimal
may be used to store the numeric value internally
and the semantics of this method is defined using
BigDecimal.scale()
.
If the scale of a value is zero, then its number type is
INTEGER
else DECIMAL
.
The number type can be used to invoke appropriate accessor methods to get numeric value for the number.
For example:
switch(getNumberType()) {
case INTEGER :
long l = getLongValue(); break;
case DECIMAL :
BigDecimal bd = getBigDecimalValue(); break;
}
int getIntValue()
int
number. Note that this conversion
can lose information about the overall magnitude and precision of the
number value as well as return a result with the opposite sign.int
for JSON number.BigDecimal.intValue()
int getIntValueExact()
int
number.int
for JSON numberArithmeticException
- cause if the number has a nonzero fractional
part, or will not fit in an int
BigDecimal.intValueExact()
long getLongValue()
long
number. Note that this conversion
can lose information about the overall magnitude and precision of the
number value as well as return a result with the opposite sign.long
for JSON number.BigDecimal.longValue()
long getLongValueExact()
long
number.long
for JSON numberArithmeticException
- if the number has a nonzero fractional
part, or will not fit in a long
.BigDecimal.longValueExact()
BigInteger getBigIntegerValue()
BigInteger
number. It is more of
a convenience method for getBigDecimalValue().toBigInteger()
.
Note that this conversion can lose information about the overall
magnitude and precision of the number value as well as return a result
with the opposite sign.BigDecimal.toBigInteger()
BigInteger getBigIntegerValueExact()
BigDecimal
number. It is more of
a convenience method for getBigDecimalValue().toBigIntegerExact()
.BigInteger
for JSON numberArithmeticException
- if the number has a nonzero fractional part.BigDecimal.toBigIntegerExact()
double getDoubleValue()
double
number. It is more of
a convenience method for getBigDecimalValue().doubleValue()
.
Note that this conversion can lose information about the overall
magnitude and precision of the number value as well as return a result
with the opposite sign.double
for JSON numberBigDecimal.doubleValue()
BigDecimal getBigDecimalValue()
BigDecimal
BigDecimal
for JSON numberString toString()
BigDecimal.toString()
.boolean equals(Object obj)
true
if and only if the specified object is also a
JsonNumber, and their getBigDecimalValue()
objects are
equalint hashCode()
getBigDecimalValue()
object's hash code.Copyright © 2013. All Rights Reserved.