abstract class JsonNumberImpl extends java.lang.Object implements JsonNumber
| Modifier and Type | Class and Description |
|---|---|
private static class |
JsonNumberImpl.JsonBigDecimalNumber |
private static class |
JsonNumberImpl.JsonIntNumber |
private static class |
JsonNumberImpl.JsonLongNumber |
JsonValue.ValueType| Constructor and Description |
|---|
JsonNumberImpl() |
| Modifier and Type | Method and Description |
|---|---|
java.math.BigInteger |
bigIntegerValue()
Returns this JSON number as a
BigInteger object. |
java.math.BigInteger |
bigIntegerValueExact()
Returns this JSON number as a
BigDecimal object. |
double |
doubleValue()
Returns this JSON number as a
double. |
boolean |
equals(java.lang.Object obj)
Compares the specified object with this
JsonNumber object for
equality. |
(package private) static JsonNumber |
getJsonNumber(java.math.BigDecimal value) |
(package private) static JsonNumber |
getJsonNumber(java.math.BigInteger value) |
(package private) static JsonNumber |
getJsonNumber(double value) |
(package private) static JsonNumber |
getJsonNumber(int num) |
(package private) static JsonNumber |
getJsonNumber(long num) |
JsonValue.ValueType |
getValueType()
Returns the value type of this JSON value.
|
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. |
java.lang.String |
toString()
Returns a JSON text representation of the JSON number.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitbigDecimalValuestatic JsonNumber getJsonNumber(int num)
static JsonNumber getJsonNumber(long num)
static JsonNumber getJsonNumber(java.math.BigInteger value)
static JsonNumber getJsonNumber(double value)
static JsonNumber getJsonNumber(java.math.BigDecimal value)
public boolean isIntegral()
JsonNumberbigDecimalValue().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
}
isIntegral in interface JsonNumberpublic int intValue()
JsonNumberint. 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.intValue in interface JsonNumberint representation of the JSON numberBigDecimal.intValue()public int intValueExact()
JsonNumberint.intValueExact in interface JsonNumberint representation of the JSON numberBigDecimal.intValueExact()public long longValue()
JsonNumberlong. 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.longValue in interface JsonNumberlong representation of the JSON number.BigDecimal.longValue()public long longValueExact()
JsonNumberlong.longValueExact in interface JsonNumberlong representation of the JSON numberBigDecimal.longValueExact()public double doubleValue()
JsonNumberdouble. 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.doubleValue in interface JsonNumberdouble representation of the JSON numberBigDecimal.doubleValue()public java.math.BigInteger bigIntegerValue()
JsonNumberBigInteger 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.bigIntegerValue in interface JsonNumberBigInteger representation of the JSON number.BigDecimal.toBigInteger()public java.math.BigInteger bigIntegerValueExact()
JsonNumberBigDecimal object. This is a
convenience method for bigDecimalValue().toBigIntegerExact().bigIntegerValueExact in interface JsonNumberBigInteger representation of the JSON numberBigDecimal.toBigIntegerExact()public JsonValue.ValueType getValueType()
JsonValuegetValueType in interface JsonValuepublic int hashCode()
JsonNumberJsonNumber object. The
hash code of a JsonNumber object is defined as the hash code of
its JsonNumber.bigDecimalValue() object.hashCode in interface JsonNumberhashCode in class java.lang.ObjectJsonNumber objectpublic boolean equals(java.lang.Object obj)
JsonNumberJsonNumber object for
equality. Returns true if and only if the type of the specified
object is also JsonNumber and their JsonNumber.bigDecimalValue()
objects are equalequals in interface JsonNumberequals in class java.lang.Objectobj - the object to be compared for equality with
this JsonNumbertrue if the specified object is equal to this
JsonNumberpublic java.lang.String toString()
JsonNumberBigDecimal.toString().toString in interface JsonNumbertoString in interface JsonValuetoString in class java.lang.Object