Package javax.json
Interface JsonNumber
-
- All Superinterfaces:
JsonValue
public interface JsonNumber extends JsonValue
An immutable JSON number value.
This is a near-exact copy of the same-titled Java EE 8 Class:javax.json.JsonNumber
Commenting has been slightly modified to accompany HiLiting the Code Examples.
Java Source Code remains identical to the Sun-Oracle & 'GlassFish' Released Distributions.
Read included License:HERE
, and theCDDL+GPL-1.1
Alljavax.json.*
Code Obtained From:GitHub JavaEE jsonp
Public Archive.
Implementations may use aBigDecimal
object to store the numeric value internally. TheBigDecimal
object can be constructed from the following types:int
BigDecimal(int)
long
BigDecimal(long)
BigInteger
BigDecimal(BigInteger)
double
BigDecimal.valueOf(double)
String
BigDecimal(String)
.
Some of the method semantics in this class are defined using theBigDecimal
semantics.
Hi-Lited Source-Code:This File's Source Code:
- View Here: javax/json/JsonNumber.java
- Open New Browser-Tab: javax/json/JsonNumber.java
File Size: 8,101 Bytes Line Count: 213 '\n' Characters Found
Glass Fish Implementation Class:
- View Here: org/glassfish/json/JsonNumberImpl.java
- Open New Browser-Tab: org/glassfish/json/JsonNumberImpl.java
File Size: 7,676 Bytes Line Count: 288 '\n' Characters Found
-
-
Nested Class Summary
-
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
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description BigDecimal
bigDecimalValue()
Returns this JSON number as aBigDecimal
object.BigInteger
bigIntegerValue()
Returns this JSON number as aBigInteger
object.BigInteger
bigIntegerValueExact()
Returns this JSON number as aBigInteger
object.double
doubleValue()
Returns this JSON number as adouble
.boolean
equals(Object obj)
Compares the specified object with thisJsonNumber
object for equality.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
.default Number
numberValue()
Returns this JSON number as aNumber
object.String
toString()
Returns a JSON text representation of the JSON number.-
Methods inherited from interface javax.json.JsonValue
asJsonArray, asJsonObject, getValueType
-
-
-
-
Method Detail
-
isIntegral
boolean isIntegral()
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:
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
- Returns:
- true if this number is a integral number, otherwise false
-
intValue
int intValue()
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.- Returns:
- an
int
representation of the JSON number - See Also:
BigDecimal.intValue()
-
intValueExact
int intValueExact()
Returns this JSON number as anint
.- Returns:
- an
int
representation of the JSON number - Throws:
java.lang.ArithmeticException
- if the number has a nonzero fractional part or if it does not fit in anint
- See Also:
BigDecimal.intValueExact()
-
longValue
long longValue()
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.- Returns:
- a
long
representation of the JSON number. - See Also:
BigDecimal.longValue()
-
longValueExact
long longValueExact()
Returns this JSON number as along
.- Returns:
- a
long
representation of the JSON number - Throws:
java.lang.ArithmeticException
- if the number has a non-zero fractional part or if it does not fit in along
- See Also:
BigDecimal.longValueExact()
-
bigIntegerValue
java.math.BigInteger bigIntegerValue()
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.- Returns:
- a
BigInteger
representation of the JSON number. - See Also:
BigDecimal.toBigInteger()
-
bigIntegerValueExact
java.math.BigInteger bigIntegerValueExact()
Returns this JSON number as aBigInteger
object. This is a convenience method forbigDecimalValue().toBigIntegerExact()
.- Returns:
- a
BigInteger
representation of the JSON number - Throws:
java.lang.ArithmeticException
- if the number has a nonzero fractional part- See Also:
BigDecimal.toBigIntegerExact()
-
doubleValue
double doubleValue()
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.- Returns:
- a
double
representation of the JSON number - See Also:
BigDecimal.doubleValue()
-
bigDecimalValue
java.math.BigDecimal bigDecimalValue()
Returns this JSON number as aBigDecimal
object.- Returns:
- a
BigDecimal
representation of the JSON number
-
numberValue
default java.lang.Number numberValue()
Returns this JSON number as aNumber
object.- Returns:
- a
Number
representation of the JSON number - Since:
- 1.1
- Code:
- Exact Method Body:
throw new UnsupportedOperationException();
-
toString
-
equals
boolean equals(java.lang.Object obj)
Compares the specified object with thisJsonNumber
object for equality. Returnstrue
if and only if the type of the specified object is alsoJsonNumber
and theirbigDecimalValue()
objects are equal- 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
-
hashCode
int hashCode()
Returns the hash code value for thisJsonNumber
object. The hash code of aJsonNumber
object is defined as the hash code of itsbigDecimalValue()
object.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- the hash code value for this
JsonNumber
object
-
-