public interface JsonNumber extends JsonValue
Implementations may use a BigDecimal
object to store the numeric
value internally.
The BigDecimal
object can be constructed from the following types:
int
BigDecimal.BigDecimal(int)
,
long
BigDecimal.BigDecimal(long)
,
BigInteger
BigDecimal.BigDecimal(BigInteger)
,
double
BigDecimal.valueOf(double)
, and
String
BigDecimal.BigDecimal(String)
.
Some of the method semantics in this class are defined using the
BigDecimal
semantics.
JsonValue.ValueType
EMPTY_JSON_ARRAY, EMPTY_JSON_OBJECT, FALSE, NULL, TRUE
Modifier and Type | Method and Description |
---|---|
BigDecimal |
bigDecimalValue()
Returns this JSON number as a
BigDecimal object. |
BigInteger |
bigIntegerValue()
Returns this JSON number as a
BigInteger object. |
BigInteger |
bigIntegerValueExact()
Returns this JSON number as a
BigInteger object. |
double |
doubleValue()
Returns this JSON number as a
double . |
boolean |
equals(Object obj)
Compares the specified object with this
JsonNumber object for
equality. |
int |
hashCode()
Returns the hash code value for this
JsonNumber object. |
int |
intValue()
Returns this JSON number as an
int . |
int |
intValueExact()
Returns this JSON number as an
int . |
boolean |
isIntegral()
Returns true if this JSON number is a integral number.
|
long |
longValue()
Returns this JSON number as a
long . |
long |
longValueExact()
Returns this JSON number as a
long . |
default Number |
numberValue()
Returns this JSON number as a
Number object. |
String |
toString()
Returns a JSON text representation of the JSON number.
|
asJsonArray, asJsonObject, getValueType
boolean isIntegral()
bigDecimalValue().scale()
. If the
scale is zero, then it is considered integral type. This integral type
information can be used to invoke an appropriate accessor method to
obtain a numeric value as in the following example:
JsonNumber num = ...
if (num.isIntegral()) {
num.longValue(); // or other methods to get integral value
} else {
num.doubleValue(); // or other methods to get decimal number value
}
int intValue()
int
. 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
representation of the JSON numberBigDecimal.intValue()
int intValueExact()
int
.int
representation of the JSON numberArithmeticException
- if the number has a nonzero fractional
part or if it does not fit in an int
BigDecimal.intValueExact()
long longValue()
long
. 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
representation of the JSON number.BigDecimal.longValue()
long longValueExact()
long
.long
representation of the JSON numberArithmeticException
- if the number has a non-zero fractional
part or if it does not fit in a long
BigDecimal.longValueExact()
BigInteger bigIntegerValue()
BigInteger
object. This is a
a convenience method for bigDecimalValue().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.BigInteger
representation of the JSON number.BigDecimal.toBigInteger()
BigInteger bigIntegerValueExact()
BigInteger
object. This is a
convenience method for bigDecimalValue().toBigIntegerExact()
.BigInteger
representation of the JSON numberArithmeticException
- if the number has a nonzero fractional partBigDecimal.toBigIntegerExact()
double doubleValue()
double
. This is a
a convenience method for bigDecimalValue().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
representation of the JSON numberBigDecimal.doubleValue()
BigDecimal bigDecimalValue()
BigDecimal
object.BigDecimal
representation of the JSON numberdefault Number numberValue()
Number
object.Number
representation of the JSON numberString toString()
BigDecimal.toString()
.boolean equals(Object obj)
JsonNumber
object for
equality. Returns true
if and only if the type of the specified
object is also JsonNumber
and their bigDecimalValue()
objects are equalint hashCode()
JsonNumber
object. The
hash code of a JsonNumber
object is defined as the hash code of
its bigDecimalValue()
object.Copyright © 2019 Eclipse Foundation.
Use is subject to license terms.