javax.json

## Interface JsonNumber

- All Superinterfaces:
    JsonValue

      public interface JsonNumber
      extends JsonValue

  An immutable JSON number value.

  Implementations may use a `BigDecimal` object to store the numeric value internally. The `BigDecimal` object can be constructed from the following types: ``int``, ``long``, ``BigInteger``, ``double``, and ``String``. Some of the method semantics in this class are defined using the `BigDecimal` semantics.

  Author:
    Jitendra Kotamraju

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface javax.json.JsonValue

      `JsonValue.ValueType`

  - ### Field Summary

    - ### Fields inherited from interface javax.json.JsonValue

      `FALSE, NULL, TRUE`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `BigDecimal` | `bigDecimalValue()` Returns this JSON number as a `BigDecimal` object.
    `BigInteger` | `bigIntegerValue()` Returns this JSON number as a `BigInteger` object.
    `BigInteger` | `bigIntegerValueExact()` Returns this JSON number as a `BigDecimal` object.
    `double` | `doubleValue()` Returns this JSON number as a `double`.
    `boolean` | `equals(Object obj)` Compares the specified object with this `JsonNumber` object for equality.
    `int` | `hashCode()` Returns the hash code value for this `JsonNumber` object.
    `int` | `intValue()` Returns this JSON number as an `int`.
    `int` | `intValueExact()` Returns this JSON number as an `int`.
    `boolean` | `isIntegral()` Returns true if this JSON number is a integral number.
    `long` | `longValue()` Returns this JSON number as a `long`.
    `long` | `longValueExact()` Returns this JSON number as a `long`.
    `String` | `toString()` Returns a JSON text representation of the JSON number.

    - ### Methods inherited from interface javax.json.JsonValue

      `getValueType`

- - ### Method Detail

    - #### isIntegral

          boolean isIntegral()

      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
           }

      Returns:
        true if this number is a integral number, otherwise false

    - #### intValue

          int intValue()

      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.
      Returns:
        an `int` representation of the JSON number
      See Also:
        `BigDecimal.intValue()`

    - #### intValueExact

          int intValueExact()

      Returns this JSON number as an `int`.
      Returns:
        an `int` representation of the JSON number
      Throws:
        `ArithmeticException` - if the number has a nonzero fractional part or if it does not fit in an `int`
      See Also:
        `BigDecimal.intValueExact()`

    - #### longValue

          long longValue()

      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.
      Returns:
        a `long` representation of the JSON number.
      See Also:
        `BigDecimal.longValue()`

    - #### longValueExact

          long longValueExact()

      Returns this JSON number as a `long`.
      Returns:
        a `long` representation of the JSON number
      Throws:
        `ArithmeticException` - if the number has a non-zero fractional part or if it does not fit in a `long`
      See Also:
        `BigDecimal.longValueExact()`

    - #### bigIntegerValue

          BigInteger bigIntegerValue()

      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.
      Returns:
        a `BigInteger` representation of the JSON number.
      See Also:
        `BigDecimal.toBigInteger()`

    - #### bigIntegerValueExact

          BigInteger bigIntegerValueExact()

      Returns this JSON number as a `BigDecimal` object. This is a convenience method for `bigDecimalValue().toBigIntegerExact()`.
      Returns:
        a `BigInteger` representation of the JSON number
      Throws:
        `ArithmeticException` - if the number has a nonzero fractional part
      See Also:
        `BigDecimal.toBigIntegerExact()`

    - #### doubleValue

          double doubleValue()

      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.
      Returns:
        a `double` representation of the JSON number
      See Also:
        `BigDecimal.doubleValue()`

    - #### bigDecimalValue

          BigDecimal bigDecimalValue()

      Returns this JSON number as a `BigDecimal` object.
      Returns:
        a `BigDecimal` representation of the JSON number

    - #### toString

          String toString()

      Returns a JSON text representation of the JSON number. The representation is equivalent to `BigDecimal.toString()`.
      Specified by:
        `toString` in interface `JsonValue`
      Overrides:
        `toString` in class `Object`
      Returns:
        JSON text representation of the number

    - #### equals

          boolean equals(Object obj)

      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 `bigDecimalValue()` objects are equal
      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`

    - #### hashCode

          int hashCode()

      Returns the hash code value for this `JsonNumber` object. The hash code of a `JsonNumber` object is defined as the hash code of its `bigDecimalValue()` object.
      Overrides:
        `hashCode` in class `Object`
      Returns:
        the hash code value for this `JsonNumber` object

Copyright © 1996-2013, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.