Class JsonNumberImpl
java.lang.Object
org.glassfish.json.JsonNumberImpl
- All Implemented Interfaces:
JsonNumber, JsonValue
- Direct Known Subclasses:
JsonNumberImpl.JsonBigDecimalNumber, JsonNumberImpl.JsonIntNumber, JsonNumberImpl.JsonLongNumber
JsonNumber impl. Subclasses provide optimized implementations
when backed by int, long, BigDecimal
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classprivate static final classprivate static final classNested classes/interfaces inherited from interface JsonValue
JsonValue.ValueType -
Field Summary
Fields inherited from interface JsonValue
EMPTY_JSON_ARRAY, EMPTY_JSON_OBJECT, FALSE, NULL, TRUE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns this JSON number as aBigIntegerobject.Returns this JSON number as aBigIntegerobject.doubleReturns this JSON number as adouble.booleanCompares 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(BigDecimal value) (package private) static JsonNumbergetJsonNumber(BigInteger value) Returns the value type of this JSON value.inthashCode()Returns the hash code value for thisJsonNumberobject.intintValue()Returns this JSON number as anint.intReturns this JSON number as anint.booleanReturns true if this JSON number is a integral number.longReturns this JSON number as along.longReturns this JSON number as along.toString()Returns a JSON text representation of the JSON number.Methods inherited from interface JsonNumber
bigDecimalValue, numberValueMethods inherited from interface JsonValue
asJsonArray, asJsonObject
-
Constructor Details
-
JsonNumberImpl
JsonNumberImpl()
-
-
Method Details
-
getJsonNumber
-
getJsonNumber
-
getJsonNumber
-
getJsonNumber
-
getJsonNumber
-
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:
-
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:
-
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:
-
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:
-
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:
-
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:
-
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:
-
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 classObject- Returns:
- the hash code value for this
JsonNumberobject
-
equals
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 classObject- Parameters:
obj- the object to be compared for equality with thisJsonNumber- Returns:
trueif the specified object is equal to thisJsonNumber
-
toString
Description copied from interface:JsonNumberReturns a JSON text representation of the JSON number. The representation is equivalent toBigDecimal.toString().
-