Package jakarta.json
Interface JsonNumber
-
- All Superinterfaces:
JsonValue
public interface JsonNumber extends JsonValue
An immutable JSON number value.Implementations may use a
BigDecimalobject to store the numeric value internally. TheBigDecimalobject can be constructed from the following types:intBigDecimal(int),longBigDecimal(long),BigIntegerBigDecimal(BigInteger),doubleBigDecimal.valueOf(double), andStringBigDecimal(String). Some of the method semantics in this class are defined using theBigDecimalsemantics.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jakarta.json.JsonValue
JsonValue.ValueType
-
-
Field Summary
-
Fields inherited from interface jakarta.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 BigDecimalbigDecimalValue()Returns this JSON number as aBigDecimalobject.BigIntegerbigIntegerValue()Returns this JSON number as aBigIntegerobject.BigIntegerbigIntegerValueExact()Returns this JSON number as aBigIntegerobject.doubledoubleValue()Returns this JSON number as adouble.booleanequals(Object obj)Compares the specified object with thisJsonNumberobject for equality.inthashCode()Returns the hash code value for thisJsonNumberobject.intintValue()Returns this JSON number as anint.intintValueExact()Returns this JSON number as anint.booleanisIntegral()Returns true if this JSON number is a integral number.longlongValue()Returns this JSON number as along.longlongValueExact()Returns this JSON number as along.default NumbernumberValue()Returns this JSON number as aNumberobject.StringtoString()Returns a JSON text representation of the JSON number.-
Methods inherited from interface jakarta.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: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
intrepresentation of the JSON number - See Also:
BigDecimal.intValue()
-
intValueExact
int intValueExact()
Returns this JSON number as anint.- Returns:
- an
intrepresentation of the JSON number - Throws:
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
longrepresentation of the JSON number. - See Also:
BigDecimal.longValue()
-
longValueExact
long longValueExact()
Returns this JSON number as along.- Returns:
- a
longrepresentation of the JSON number - Throws:
ArithmeticException- if the number has a non-zero fractional part or if it does not fit in along- See Also:
BigDecimal.longValueExact()
-
bigIntegerValue
BigInteger bigIntegerValue()
Returns this JSON number as aBigIntegerobject. 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
BigIntegerrepresentation of the JSON number. - See Also:
BigDecimal.toBigInteger()
-
bigIntegerValueExact
BigInteger bigIntegerValueExact()
Returns this JSON number as aBigIntegerobject. This is a convenience method forbigDecimalValue().toBigIntegerExact().- Returns:
- a
BigIntegerrepresentation of the JSON number - Throws:
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
doublerepresentation of the JSON number - See Also:
BigDecimal.doubleValue()
-
bigDecimalValue
BigDecimal bigDecimalValue()
Returns this JSON number as aBigDecimalobject.- Returns:
- a
BigDecimalrepresentation of the JSON number
-
numberValue
default Number numberValue()
Returns this JSON number as aNumberobject.- Returns:
- a
Numberrepresentation of the JSON number - Since:
- 1.1
-
toString
String toString()
Returns a JSON text representation of the JSON number. The representation is equivalent toBigDecimal.toString().
-
equals
boolean equals(Object obj)
Compares the specified object with thisJsonNumberobject for equality. Returnstrueif and only if the type of the specified object is alsoJsonNumberand theirbigDecimalValue()objects are equal
-
hashCode
int hashCode()
Returns the hash code value for thisJsonNumberobject. The hash code of aJsonNumberobject is defined as the hash code of itsbigDecimalValue()object.
-
-