Class JSONNumber
java.lang.Object
ch.epfl.cs107.play.data.json.JSONValue
ch.epfl.cs107.play.data.json.JSONNumber
-
Constructor Summary
ConstructorsConstructorDescriptionJSONNumber(double value) JSONNumber(int value) JSONNumber(long value) JSONNumber(String value) Creates a new JSON number from its string representation. -
Method Summary
Modifier and TypeMethodDescriptionintgetAsInt()Returns the value of this JSON number as an int.longReturns the value of this JSON number as an long.doubleReturns the value of this JSON number as a double.getValue()Returns the string representation of this JSON number.booleanisInt()Tests whether the value of this number can be parsed as an int.booleanisLong()Tests whether the value of this number can be parsed as an long.protected StringSerializes the implementing class to a JSON-formatted string.
-
Constructor Details
-
JSONNumber
Creates a new JSON number from its string representation.- Throws:
NumberFormatException- if the value is not a valid JSON number string.
-
JSONNumber
public JSONNumber(int value) -
JSONNumber
public JSONNumber(long value) -
JSONNumber
public JSONNumber(double value)
-
-
Method Details
-
toJSONString
Description copied from class:JSONValueSerializes the implementing class to a JSON-formatted string.- Specified by:
toJSONStringin classJSONValue- Returns:
- A JSON-formatted string representation of the object.
-
getValue
-
isInt
public boolean isInt()Tests whether the value of this number can be parsed as an int.- Returns:
- true if it can, false otherwise
-
getAsInt
public int getAsInt()Returns the value of this JSON number as an int.- Throws:
NumberFormatException- if it cannot be parsed as an int
-
isLong
public boolean isLong()Tests whether the value of this number can be parsed as an long.- Returns:
- true if it can, false otherwise
-
getAsLong
public long getAsLong()Returns the value of this JSON number as an long.- Throws:
NumberFormatException- if it cannot be parsed as an long
-
getDouble
public double getDouble()Returns the value of this JSON number as a double. This operation always succeeds.
-