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 classJsonNumberImpl.JsonBigDecimalNumberprivate static classJsonNumberImpl.JsonIntNumberprivate static classJsonNumberImpl.JsonLongNumber-
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 Constructor Description JsonNumberImpl()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.math.BigIntegerbigIntegerValue()Returns this JSON number as aBigIntegerobject.java.math.BigIntegerbigIntegerValueExact()Returns this JSON number as aBigIntegerobject.doubledoubleValue()Returns this JSON number as adouble.booleanequals(java.lang.Object obj)Compares the specified object with thisJsonNumberobject for equality.(package private) static JsonNumbergetJsonNumber(double value)(package private) static JsonNumbergetJsonNumber(int num)(package private) static JsonNumbergetJsonNumber(long num)(package private) static JsonNumbergetJsonNumber(java.math.BigDecimal value)(package private) static JsonNumbergetJsonNumber(java.math.BigInteger value)JsonValue.ValueTypegetValueType()Returns the value type of this JSON value.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.java.lang.StringtoString()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
-
-
-
-
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:JsonNumberReturns 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:
isIntegralin interfaceJsonNumber- Returns:
- true if this number is a integral number, otherwise false
-
intValue
public int intValue()
Description copied from interface:JsonNumberReturns 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:
intValuein interfaceJsonNumber- Returns:
- an
intrepresentation of the JSON number - See Also:
BigDecimal.intValue()
-
intValueExact
public int intValueExact()
Description copied from interface:JsonNumberReturns this JSON number as anint.- Specified by:
intValueExactin interfaceJsonNumber- Returns:
- an
intrepresentation of the JSON number - See Also:
BigDecimal.intValueExact()
-
longValue
public long longValue()
Description copied from interface:JsonNumberReturns 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:
longValuein interfaceJsonNumber- Returns:
- a
longrepresentation of the JSON number. - See Also:
BigDecimal.longValue()
-
longValueExact
public long longValueExact()
Description copied from interface:JsonNumberReturns this JSON number as along.- Specified by:
longValueExactin interfaceJsonNumber- Returns:
- a
longrepresentation of the JSON number - See Also:
BigDecimal.longValueExact()
-
doubleValue
public double doubleValue()
Description copied from interface:JsonNumberReturns 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:
doubleValuein interfaceJsonNumber- Returns:
- a
doublerepresentation of the JSON number - See Also:
BigDecimal.doubleValue()
-
bigIntegerValue
public java.math.BigInteger bigIntegerValue()
Description copied from interface:JsonNumberReturns 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.- Specified by:
bigIntegerValuein interfaceJsonNumber- Returns:
- a
BigIntegerrepresentation of the JSON number. - See Also:
BigDecimal.toBigInteger()
-
bigIntegerValueExact
public java.math.BigInteger bigIntegerValueExact()
Description copied from interface:JsonNumberReturns this JSON number as aBigIntegerobject. This is a convenience method forbigDecimalValue().toBigIntegerExact().- Specified by:
bigIntegerValueExactin interfaceJsonNumber- Returns:
- a
BigIntegerrepresentation of the JSON number - See Also:
BigDecimal.toBigIntegerExact()
-
getValueType
public JsonValue.ValueType getValueType()
Description copied from interface:JsonValueReturns the value type of this JSON value.- Specified by:
getValueTypein interfaceJsonValue- Returns:
- JSON value type
-
hashCode
public int hashCode()
Description copied from interface:JsonNumberReturns the hash code value for thisJsonNumberobject. The hash code of aJsonNumberobject is defined as the hash code of itsJsonNumber.bigDecimalValue()object.- Specified by:
hashCodein interfaceJsonNumber- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code value for this
JsonNumberobject
-
equals
public boolean equals(java.lang.Object obj)
Description copied from interface:JsonNumberCompares the specified object with thisJsonNumberobject for equality. Returnstrueif and only if the type of the specified object is alsoJsonNumberand theirJsonNumber.bigDecimalValue()objects are equal- Specified by:
equalsin interfaceJsonNumber- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object to be compared for equality with thisJsonNumber- Returns:
trueif the specified object is equal to thisJsonNumber
-
toString
public java.lang.String toString()
Description copied from interface:JsonNumberReturns a JSON text representation of the JSON number. The representation is equivalent toBigDecimal.toString().- Specified by:
toStringin interfaceJsonNumber- Specified by:
toStringin interfaceJsonValue- Overrides:
toStringin classjava.lang.Object- Returns:
- JSON text representation of the number
-
-