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
abstract class JsonNumberImpl extends java.lang.Object implements JsonNumber
JsonNumber impl. Subclasses provide optimized implementations when backed by int, long, BigDecimal
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
JsonNumberImpl.JsonBigDecimalNumber
private static class
JsonNumberImpl.JsonIntNumber
private static class
JsonNumberImpl.JsonLongNumber
-
Nested classes/interfaces inherited from interface javax.json.JsonValue
JsonValue.ValueType
-
-
Constructor Summary
Constructors Constructor Description JsonNumberImpl()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.math.BigInteger
bigIntegerValue()
Returns this JSON number as aBigInteger
object.java.math.BigInteger
bigIntegerValueExact()
Returns this JSON number as aBigDecimal
object.double
doubleValue()
Returns this JSON number as adouble
.boolean
equals(java.lang.Object obj)
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(java.math.BigDecimal value)
(package private) static JsonNumber
getJsonNumber(java.math.BigInteger value)
JsonValue.ValueType
getValueType()
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
intValueExact()
Returns this JSON number as anint
.boolean
isIntegral()
Returns true if this JSON number is a integral number.long
longValue()
Returns this JSON number as along
.long
longValueExact()
Returns this JSON number as along
.java.lang.String
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
-
-
-
-
Method Detail
-
getJsonNumber
static JsonNumber getJsonNumber(int num)
-
getJsonNumber
static JsonNumber getJsonNumber(long num)
-
getJsonNumber
static JsonNumber getJsonNumber(java.math.BigInteger value)
-
getJsonNumber
static JsonNumber getJsonNumber(double value)
-
getJsonNumber
static JsonNumber getJsonNumber(java.math.BigDecimal value)
-
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:
BigDecimal.intValue()
-
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:
BigDecimal.intValueExact()
-
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:
BigDecimal.longValue()
-
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:
BigDecimal.longValueExact()
-
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:
BigDecimal.doubleValue()
-
bigIntegerValue
public java.math.BigInteger 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:
BigDecimal.toBigInteger()
-
bigIntegerValueExact
public java.math.BigInteger bigIntegerValueExact()
Description copied from interface:JsonNumber
Returns this JSON number as aBigDecimal
object. This is a convenience method forbigDecimalValue().toBigIntegerExact()
.- Specified by:
bigIntegerValueExact
in interfaceJsonNumber
- Returns:
- a
BigInteger
representation of the JSON number - See Also:
BigDecimal.toBigIntegerExact()
-
getValueType
public JsonValue.ValueType 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 classjava.lang.Object
- Returns:
- the hash code value for this
JsonNumber
object
-
equals
public boolean equals(java.lang.Object obj)
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 classjava.lang.Object
- Parameters:
obj
- the object to be compared for equality with thisJsonNumber
- Returns:
true
if the specified object is equal to thisJsonNumber
-
toString
public java.lang.String toString()
Description copied from interface:JsonNumber
Returns a JSON text representation of the JSON number. The representation is equivalent toBigDecimal.toString()
.- Specified by:
toString
in interfaceJsonNumber
- Specified by:
toString
in interfaceJsonValue
- Overrides:
toString
in classjava.lang.Object
- Returns:
- JSON text representation of the number
-
-