Package org.glassfish.json
Class JsonNumberImpl.JsonLongNumber
- java.lang.Object
-
- org.glassfish.json.JsonNumberImpl
-
- org.glassfish.json.JsonNumberImpl.JsonLongNumber
-
- All Implemented Interfaces:
JsonNumber
,JsonValue
- Enclosing class:
- JsonNumberImpl
private static final class JsonNumberImpl.JsonLongNumber extends JsonNumberImpl
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface javax.json.JsonValue
JsonValue.ValueType
-
-
Field Summary
Fields Modifier and Type Field Description private java.math.BigDecimal
bigDecimal
private long
num
-
Fields inherited from interface javax.json.JsonValue
EMPTY_JSON_ARRAY, EMPTY_JSON_OBJECT, FALSE, NULL, TRUE
-
-
Constructor Summary
Constructors Constructor Description JsonLongNumber(long num)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.math.BigDecimal
bigDecimalValue()
Returns this JSON number as aBigDecimal
object.double
doubleValue()
Returns this JSON number as adouble
.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.Number
numberValue()
Returns this JSON number as aNumber
object.java.lang.String
toString()
Returns a JSON text representation of the JSON number.-
Methods inherited from class org.glassfish.json.JsonNumberImpl
bigIntegerValue, bigIntegerValueExact, equals, getJsonNumber, getJsonNumber, getJsonNumber, getJsonNumber, getJsonNumber, getValueType, hashCode
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface javax.json.JsonValue
asJsonArray, asJsonObject
-
-
-
-
Method Detail
-
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
- Overrides:
isIntegral
in classJsonNumberImpl
- 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
- Overrides:
intValue
in classJsonNumberImpl
- 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
- Overrides:
intValueExact
in classJsonNumberImpl
- 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
- Overrides:
longValue
in classJsonNumberImpl
- 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
- Overrides:
longValueExact
in classJsonNumberImpl
- 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
- Overrides:
doubleValue
in classJsonNumberImpl
- Returns:
- a
double
representation of the JSON number - See Also:
BigDecimal.doubleValue()
-
bigDecimalValue
public java.math.BigDecimal bigDecimalValue()
Description copied from interface:JsonNumber
Returns this JSON number as aBigDecimal
object.- Returns:
- a
BigDecimal
representation of the JSON number
-
numberValue
public java.lang.Number numberValue()
Description copied from interface:JsonNumber
Returns this JSON number as aNumber
object.- Returns:
- a
Number
representation of the JSON number
-
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 classJsonNumberImpl
- Returns:
- JSON text representation of the number
-
-