Class JsonNumberImpl.JsonIntNumber
java.lang.Object
org.glassfish.json.JsonNumberImpl
org.glassfish.json.JsonNumberImpl.JsonIntNumber
- All Implemented Interfaces:
JsonNumber, JsonValue
- Enclosing class:
JsonNumberImpl
-
Nested Class Summary
Nested classes/interfaces inherited from interface JsonValue
JsonValue.ValueType -
Field Summary
FieldsFields 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 aBigDecimalobject.doubleReturns this JSON number as adouble.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.Returns this JSON number as aNumberobject.toString()Returns a JSON text representation of the JSON number.Methods inherited from class JsonNumberImpl
bigIntegerValue, bigIntegerValueExact, equals, getJsonNumber, getJsonNumber, getJsonNumber, getJsonNumber, getJsonNumber, getValueType, hashCodeMethods inherited from interface JsonValue
asJsonArray, asJsonObject
-
Field Details
-
num
private final int num -
bigDecimal
-
-
Constructor Details
-
JsonIntNumber
JsonIntNumber(int num)
-
-
Method Details
-
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- Overrides:
isIntegralin classJsonNumberImpl- 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- Overrides:
intValuein classJsonNumberImpl- 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- Overrides:
intValueExactin classJsonNumberImpl- 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- Overrides:
longValuein classJsonNumberImpl- 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- Overrides:
longValueExactin classJsonNumberImpl- 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- Overrides:
doubleValuein classJsonNumberImpl- Returns:
- a
doublerepresentation of the JSON number - See Also:
-
bigDecimalValue
Description copied from interface:JsonNumberReturns this JSON number as aBigDecimalobject.- Returns:
- a
BigDecimalrepresentation of the JSON number
-
numberValue
Description copied from interface:JsonNumberReturns this JSON number as aNumberobject.- Returns:
- a
Numberrepresentation of the JSON number
-
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 classJsonNumberImpl- Returns:
- JSON text representation of the number
-