Class JSONNumber

java.lang.Object
ch.epfl.cs107.play.data.json.JSONValue
ch.epfl.cs107.play.data.json.JSONNumber

public final class JSONNumber extends JSONValue
  • Constructor Summary

    Constructors
    Constructor
    Description
    JSONNumber(double value)
     
    JSONNumber(int value)
     
    JSONNumber(long value)
     
    Creates a new JSON number from its string representation.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the value of this JSON number as an int.
    long
    Returns the value of this JSON number as an long.
    double
    Returns the value of this JSON number as a double.
    Returns the string representation of this JSON number.
    boolean
    Tests whether the value of this number can be parsed as an int.
    boolean
    Tests whether the value of this number can be parsed as an long.
    protected String
    Serializes the implementing class to a JSON-formatted string.

    Methods inherited from class JSONValue

    toString

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • JSONNumber

      public JSONNumber(String value)
      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

      protected String toJSONString()
      Description copied from class: JSONValue
      Serializes the implementing class to a JSON-formatted string.
      Specified by:
      toJSONString in class JSONValue
      Returns:
      A JSON-formatted string representation of the object.
    • getValue

      public String getValue()
      Returns the string representation of this JSON number.
      Returns:
    • 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.