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 Object implements JsonNumber
JsonNumber impl. Subclasses provide optimized implementations when backed by int, long, BigDecimal
  • Constructor Details

    • JsonNumberImpl

      JsonNumberImpl()
  • Method Details

    • getJsonNumber

      static JsonNumber getJsonNumber(int num)
    • getJsonNumber

      static JsonNumber getJsonNumber(long num)
    • getJsonNumber

      static JsonNumber getJsonNumber(BigInteger value)
    • getJsonNumber

      static JsonNumber getJsonNumber(double value)
    • getJsonNumber

      static JsonNumber getJsonNumber(BigDecimal value)
    • isIntegral

      public boolean isIntegral()
      Description copied from interface: JsonNumber
      Returns true if this JSON number is a integral number. This method semantics are defined using bigDecimalValue().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:
      isIntegral in interface JsonNumber
      Returns:
      true if this number is a integral number, otherwise false
    • intValue

      public int intValue()
      Description copied from interface: JsonNumber
      Returns this JSON number as an int. 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:
      intValue in interface JsonNumber
      Returns:
      an int representation of the JSON number
      See Also:
    • intValueExact

      public int intValueExact()
      Description copied from interface: JsonNumber
      Returns this JSON number as an int.
      Specified by:
      intValueExact in interface JsonNumber
      Returns:
      an int representation of the JSON number
      See Also:
    • longValue

      public long longValue()
      Description copied from interface: JsonNumber
      Returns this JSON number as a long. 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:
      longValue in interface JsonNumber
      Returns:
      a long representation of the JSON number.
      See Also:
    • longValueExact

      public long longValueExact()
      Description copied from interface: JsonNumber
      Returns this JSON number as a long.
      Specified by:
      longValueExact in interface JsonNumber
      Returns:
      a long representation of the JSON number
      See Also:
    • doubleValue

      public double doubleValue()
      Description copied from interface: JsonNumber
      Returns this JSON number as a double. This is a a convenience method for bigDecimalValue().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:
      doubleValue in interface JsonNumber
      Returns:
      a double representation of the JSON number
      See Also:
    • bigIntegerValue

      public BigInteger bigIntegerValue()
      Description copied from interface: JsonNumber
      Returns this JSON number as a BigInteger object. This is a a convenience method for bigDecimalValue().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:
      bigIntegerValue in interface JsonNumber
      Returns:
      a BigInteger representation of the JSON number.
      See Also:
    • bigIntegerValueExact

      public BigInteger bigIntegerValueExact()
      Description copied from interface: JsonNumber
      Returns this JSON number as a BigDecimal object. This is a convenience method for bigDecimalValue().toBigIntegerExact().
      Specified by:
      bigIntegerValueExact in interface JsonNumber
      Returns:
      a BigInteger representation of the JSON number
      See Also:
    • getValueType

      public JsonValue.ValueType getValueType()
      Description copied from interface: JsonValue
      Returns the value type of this JSON value.
      Specified by:
      getValueType in interface JsonValue
      Returns:
      JSON value type
    • hashCode

      public int hashCode()
      Description copied from interface: JsonNumber
      Returns the hash code value for this JsonNumber object. The hash code of a JsonNumber object is defined as the hash code of its JsonNumber.bigDecimalValue() object.
      Specified by:
      hashCode in interface JsonNumber
      Overrides:
      hashCode in class Object
      Returns:
      the hash code value for this JsonNumber object
    • equals

      public boolean equals(Object obj)
      Description copied from interface: JsonNumber
      Compares the specified object with this JsonNumber object for equality. Returns true if and only if the type of the specified object is also JsonNumber and their JsonNumber.bigDecimalValue() objects are equal
      Specified by:
      equals in interface JsonNumber
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to be compared for equality with this JsonNumber
      Returns:
      true if the specified object is equal to this JsonNumber
    • toString

      public String toString()
      Description copied from interface: JsonNumber
      Returns a JSON text representation of the JSON number. The representation is equivalent to BigDecimal.toString().
      Specified by:
      toString in interface JsonNumber
      Specified by:
      toString in interface JsonValue
      Overrides:
      toString in class Object
      Returns:
      JSON text representation of the number