Package org.glassfish.json
Class JsonNumberImpl
java.lang.Object
org.glassfish.json.JsonNumberImpl
- All Implemented Interfaces:
JsonNumber
,JsonValue
- Direct Known Subclasses:
JsonNumberImpl.JsonBigDecimalNumber
,JsonNumberImpl.JsonIntNumber
,JsonNumberImpl.JsonLongNumber
JsonNumber impl. Subclasses provide optimized implementations
when backed by int, long, BigDecimal
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
private static final class
private static final class
Nested classes/interfaces inherited from interface javax.json.JsonValue
JsonValue.ValueType
-
Field Summary
Fields inherited from interface javax.json.JsonValue
EMPTY_JSON_ARRAY, EMPTY_JSON_OBJECT, FALSE, NULL, TRUE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns this JSON number as aBigInteger
object.Returns this JSON number as aBigInteger
object.double
Returns this JSON number as adouble
.boolean
Compares the specified object with thisJsonNumber
object for equality.(package private) static JsonNumber
getJsonNumber
(double value) (package private) static JsonNumber
getJsonNumber
(int num) (package private) static JsonNumber
getJsonNumber
(long num) (package private) static JsonNumber
getJsonNumber
(BigDecimal value) (package private) static JsonNumber
getJsonNumber
(BigInteger value) Returns the value type of this JSON value.int
hashCode()
Returns the hash code value for thisJsonNumber
object.int
intValue()
Returns this JSON number as anint
.int
Returns this JSON number as anint
.boolean
Returns true if this JSON number is a integral number.long
Returns this JSON number as along
.long
Returns this JSON number as along
.toString()
Returns a JSON text representation of the JSON number.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface javax.json.JsonNumber
bigDecimalValue, numberValue
Methods inherited from interface javax.json.JsonValue
asJsonArray, asJsonObject
-
Constructor Details
-
JsonNumberImpl
JsonNumberImpl()
-
-
Method Details
-
getJsonNumber
-
getJsonNumber
-
getJsonNumber
-
getJsonNumber
-
getJsonNumber
-
isIntegral
public boolean isIntegral()Description copied from interface:JsonNumber
Returns true if this JSON number is a integral number. This method semantics are defined usingbigDecimalValue().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 }
- Specified by:
isIntegral
in interfaceJsonNumber
- Returns:
- true if this number is a integral number, otherwise false
-
intValue
public int intValue()Description copied from interface:JsonNumber
Returns this JSON number as anint
. 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.- Specified by:
intValue
in interfaceJsonNumber
- Returns:
- an
int
representation of the JSON number - See Also:
-
intValueExact
public int intValueExact()Description copied from interface:JsonNumber
Returns this JSON number as anint
.- Specified by:
intValueExact
in interfaceJsonNumber
- Returns:
- an
int
representation of the JSON number - See Also:
-
longValue
public long longValue()Description copied from interface:JsonNumber
Returns this JSON number as along
. 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.- Specified by:
longValue
in interfaceJsonNumber
- Returns:
- a
long
representation of the JSON number. - See Also:
-
longValueExact
public long longValueExact()Description copied from interface:JsonNumber
Returns this JSON number as along
.- Specified by:
longValueExact
in interfaceJsonNumber
- Returns:
- a
long
representation of the JSON number - See Also:
-
doubleValue
public double doubleValue()Description copied from interface:JsonNumber
Returns this JSON number as adouble
. This is a a convenience method forbigDecimalValue().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.- Specified by:
doubleValue
in interfaceJsonNumber
- Returns:
- a
double
representation of the JSON number - See Also:
-
bigIntegerValue
Description copied from interface:JsonNumber
Returns this JSON number as aBigInteger
object. This is a a convenience method forbigDecimalValue().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.- Specified by:
bigIntegerValue
in interfaceJsonNumber
- Returns:
- a
BigInteger
representation of the JSON number. - See Also:
-
bigIntegerValueExact
Description copied from interface:JsonNumber
Returns this JSON number as aBigInteger
object. This is a convenience method forbigDecimalValue().toBigIntegerExact()
.- Specified by:
bigIntegerValueExact
in interfaceJsonNumber
- Returns:
- a
BigInteger
representation of the JSON number - See Also:
-
getValueType
Description copied from interface:JsonValue
Returns the value type of this JSON value.- Specified by:
getValueType
in interfaceJsonValue
- Returns:
- JSON value type
-
hashCode
public int hashCode()Description copied from interface:JsonNumber
Returns the hash code value for thisJsonNumber
object. The hash code of aJsonNumber
object is defined as the hash code of itsJsonNumber.bigDecimalValue()
object.- Specified by:
hashCode
in interfaceJsonNumber
- Overrides:
hashCode
in classObject
- Returns:
- the hash code value for this
JsonNumber
object
-
equals
Description copied from interface:JsonNumber
Compares the specified object with thisJsonNumber
object for equality. Returnstrue
if and only if the type of the specified object is alsoJsonNumber
and theirJsonNumber.bigDecimalValue()
objects are equal- Specified by:
equals
in interfaceJsonNumber
- Overrides:
equals
in classObject
- Parameters:
obj
- the object to be compared for equality with thisJsonNumber
- Returns:
true
if the specified object is equal to thisJsonNumber
-
toString
Description copied from interface:JsonNumber
Returns a JSON text representation of the JSON number. The representation is equivalent toBigDecimal.toString()
.
-