Class JsonNumberImpl.JsonIntNumber

    • Field Detail

      • num

        private final int num
      • bigDecimal

        private java.math.BigDecimal bigDecimal
    • Constructor Detail

      • JsonIntNumber

        JsonIntNumber​(int num)
    • Method Detail

      • 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
        Overrides:
        isIntegral in class JsonNumberImpl
        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
        Overrides:
        intValue in class JsonNumberImpl
        Returns:
        an int representation of the JSON number
        See Also:
        BigDecimal.intValue()
      • intValueExact

        public int intValueExact()
        Description copied from interface: JsonNumber
        Returns this JSON number as an int.
        Specified by:
        intValueExact in interface JsonNumber
        Overrides:
        intValueExact in class JsonNumberImpl
        Returns:
        an int representation of the JSON number
        See Also:
        BigDecimal.intValueExact()
      • 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
        Overrides:
        longValue in class JsonNumberImpl
        Returns:
        a long representation of the JSON number.
        See Also:
        BigDecimal.longValue()
      • longValueExact

        public long longValueExact()
        Description copied from interface: JsonNumber
        Returns this JSON number as a long.
        Specified by:
        longValueExact in interface JsonNumber
        Overrides:
        longValueExact in class JsonNumberImpl
        Returns:
        a long representation of the JSON number
        See Also:
        BigDecimal.longValueExact()
      • 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
        Overrides:
        doubleValue in class JsonNumberImpl
        Returns:
        a double representation of the JSON number
        See Also:
        BigDecimal.doubleValue()
      • bigDecimalValue

        public java.math.BigDecimal bigDecimalValue()
        Description copied from interface: JsonNumber
        Returns this JSON number as a BigDecimal object.
        Returns:
        a BigDecimal representation of the JSON number
      • toString

        public java.lang.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 JsonNumberImpl
        Returns:
        JSON text representation of the number