Class NumericFPNode

All Implemented Interfaces:
Serializable, Iterable<JsonNode>, TreeNode, JacksonSerializable
Direct Known Subclasses:
DecimalNode, DoubleNode, FloatNode

public abstract class NumericFPNode extends NumericNode
Intermediate node class used for numeric nodes that contain floating-point values: provides partial implementation of common methods.
See Also:
  • Constructor Details

    • NumericFPNode

      public NumericFPNode()
  • Method Details

    • asToken

      public final JsonToken asToken()
      Description copied from class: BaseJsonNode
      Method that can be used for efficient type detection when using stream abstraction for traversing nodes. Will return the first JsonToken that equivalent stream event would produce (for most nodes there is just one token but for structured/container types multiple)
      Specified by:
      asToken in interface TreeNode
      Specified by:
      asToken in class ValueNode
    • isFloatingPointNumber

      public final boolean isFloatingPointNumber()
      Overrides:
      isFloatingPointNumber in class JsonNode
      Returns:
      True if this node represents a non-integral numeric JSON value
    • canConvertToShort

      public final boolean canConvertToShort()
      Description copied from class: JsonNode
      Method that can be used to check whether this node is a numeric node (JsonNode.isNumber() would return true) AND can be converted without loss to short (that is, its value fits in Java's 16-bit signed integer type, short and if it is a floating-point number, it does not have fractional part).

      NOTE: this method does not consider possible value type conversion from non-number types like JSON String into Number; so even if this method returns false, it is possible that JsonNode.asShort() could still succeed.

      Specified by:
      canConvertToShort in class NumericNode
    • canConvertToInt

      public final boolean canConvertToInt()
      Description copied from class: JsonNode
      Method that can be used to check whether this node is a numeric node (JsonNode.isNumber() would return true) AND can be converted without loss to int (that is, its value fits in Java's 32-bit signed integer type, int and if it is a floating-point number, it does not have fractional part).

      NOTE: this method does not consider possible value type conversion from non-number types like JSON String into Number; so even if this method returns false, it is possible that JsonNode.asInt() could still succeed.

      Specified by:
      canConvertToInt in class NumericNode
    • canConvertToLong

      public final boolean canConvertToLong()
      Description copied from class: JsonNode
      Method that can be used to check whether this node is a numeric node (JsonNode.isNumber() would return true) AND can be converted without loss to long (that is, its value fits in Java's 64-bit signed integer type, long and if it is a floating-point number, it does not have fractional part).

      NOTE: this method does not consider possible value type conversion from non-number types like JSON String into Number; so even if this method returns false, it is possible that JsonNode.asLong() could still succeed.

      Specified by:
      canConvertToLong in class NumericNode
    • canConvertToExactIntegral

      public final boolean canConvertToExactIntegral()
      Description copied from class: JsonNode
      Method that can be used to check whether contained value is numeric (returns true for JsonNode.isNumber()) and can be converted without loss to integral number (specifically, BigInteger but potentially others, see JsonNode.canConvertToInt() and JsonNode.canConvertToInt()). Latter part allows floating-point numbers (for which JsonNode.isFloatingPointNumber() returns true) that do not have fractional part. Note that "not-a-number" values of double and float will return false as they cannot be converted to matching integral representations.
      Overrides:
      canConvertToExactIntegral in class JsonNode
      Returns:
      True if the value is an actual number with no fractional part; false for non-numeric types, NaN representations of floating-point numbers, and floating-point numbers with fractional part.
    • shortValue

      public final short shortValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as 16-bit signed integer value (Java short): but if node value cannot be expressed exactly as a short, a JsonNodeException will be thrown. Access works for following cases:
      • JSON Integer values that fit in Java 16-bit signed short range
      • JSON Floating-point values that fit in Java 16-bit signed short range AND do not have fractional part.

      Specified by:
      shortValue in class NumericNode
      Returns:
      Short value this node represents, if possible to accurately represent
    • shortValue

      public final short shortValue(short defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.shortValue(), but that will return specified defaultValue if this node cannot be converted to Java short.
      Specified by:
      shortValue in class NumericNode
      Parameters:
      defaultValue - Value to return if this node cannot be converted to Java short
      Returns:
      Java short value this node represents, if possible to accurately represent; defaultValue otherwise
    • shortValueOpt

      public final Optional<Short> shortValueOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.shortValue(), but that will return empty Optional<Short> (Optional.empty()) if this node cannot be converted to Java short.
      Specified by:
      shortValueOpt in class NumericNode
      Returns:
      Java short value this node represents, as Optional<Short>, if possible to accurately represent; Optional.empty() otherwise
    • asShort

      public short asShort()
      Description copied from class: JsonNode
      Method similar to JsonNode.shortValue() but in addition to coercing Number values (same as JsonNode.shortValue()), will also try to coerce a couple of additional types (or cases):
      • JSON Floating-point numbers with fractions (ones without fractions are ok for JsonNode.shortValue()) will be truncated to short (if (and only if) they fit in short range).
      • JSON Strings that represent JSON Numbers ("stringified" numbers)
      • JSON Null (converted to 0))
      • POJO nodes that contain Number values
      Specified by:
      asShort in class NumericNode
      Returns:
      short value this node represents, if possible to accurately represent
    • asShort

      public short asShort(short defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.shortValue(), but that will return specified defaultValue if this node cannot be converted to short.
      Specified by:
      asShort in class NumericNode
      Parameters:
      defaultValue - Value to return if this node cannot be converted to short
      Returns:
      short value this node represents, if possible to accurately represent; defaultValue otherwise
    • asShortOpt

      public Optional<Short> asShortOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.asShort(), but that will return (Optional.empty()) if this node cannot be coerced to short.
      Specified by:
      asShortOpt in class NumericNode
      Returns:
      Optional<Short> value this node represents, if possible to accurately represent; Optional.empty() otherwise
    • intValue

      public final int intValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as a Java int: but if node value cannot be expressed exactly as an int, a JsonNodeException will be thrown. Access works for following cases:
      • JSON Integer values that fit in Java 32-bit signed int range
      • JSON Floating-point values that fit in Java 32-bit signed int range AND do not have fractional part.

      NOTE: for more lenient conversions, use JsonNode.asInt()

      Specified by:
      intValue in class NumericNode
      Returns:
      Int value this node represents, if possible to accurately represent
    • intValue

      public final int intValue(int defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.intValue(), but that will return specified defaultValue if this node cannot be converted to Java int.
      Specified by:
      intValue in class NumericNode
      Parameters:
      defaultValue - Value to return if this node cannot be converted to Java int
      Returns:
      Java int value this node represents, if possible to accurately represent; defaultValue otherwise
    • intValueOpt

      public final OptionalInt intValueOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.intValue(), but that will return empty OptionalInt (OptionalInt.empty()) if this node cannot be converted to Java int.
      Specified by:
      intValueOpt in class NumericNode
      Returns:
      Java int value this node represents, as OptionalInt, if possible to accurately represent; OptionalInt.empty() otherwise
    • asInt

      public int asInt()
      Description copied from class: JsonNode
      Method similar to JsonNode.intValue() but in addition to coercing Number values (same as JsonNode.intValue()), will also try to coerce a couple of additional types (or cases):
      • JSON Floating-point numbers with fractions (ones without fractions are ok for JsonNode.intValue()) will be truncated to int (if (and only if) they fit in int range).
      • JSON Strings that represent JSON Numbers ("stringified" numbers)
      • JSON Null (converted to 0))
      • POJO nodes that contain Number values
      Specified by:
      asInt in class NumericNode
      Returns:
      int value this node represents, if possible to accurately represent
    • asInt

      public int asInt(int defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.intValue(), but that will return specified defaultValue if this node cannot be converted to int.
      Specified by:
      asInt in class NumericNode
      Parameters:
      defaultValue - Value to return if this node cannot be converted to int
      Returns:
      int value this node represents, if possible to accurately represent; defaultValue otherwise
    • asIntOpt

      public OptionalInt asIntOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.asInt(), but that will return (OptionalInt.empty()) if this node cannot be coerced to int.
      Specified by:
      asIntOpt in class NumericNode
      Returns:
      OptionalInt value this node represents, if possible to accurately represent; OptionalInt.empty() otherwise
    • longValue

      public final long longValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as a Java long: but if node value cannot be expressed exactly as a long, a JsonNodeException will be thrown. Access works for following cases:
      • JSON Integer values that fit in Java 64-bit signed long range
      • JSON Floating-point values that fit in Java 64-bit signed long range AND do not have fractional part.

      NOTE: for more lenient conversions, use JsonNode.asLong()

      Specified by:
      longValue in class NumericNode
      Returns:
      Long value this node represents, if possible to accurately represent
    • longValue

      public final long longValue(long defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.longValue(), but that will return specified defaultValue if this node cannot be converted to long.
      Specified by:
      longValue in class NumericNode
      Parameters:
      defaultValue - Value to return if this node cannot be converted to long
      Returns:
      long value this node represents, if possible to accurately represent; defaultValue otherwise
    • longValueOpt

      public final OptionalLong longValueOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.longValue(), but that will return empty OptionalLong (OptionalLong.empty()) if this node cannot be converted to Java long.
      Specified by:
      longValueOpt in class NumericNode
      Returns:
      Java long value this node represents, as OptionalLong, if possible to accurately represent; OptionalLong.empty() otherwise
    • asLong

      public final long asLong()
      Description copied from class: JsonNode
      Method similar to JsonNode.longValue() but in addition to coercing Number values (same as JsonNode.longValue()), will also try to coerce a couple of additional types (or cases):
      • JSON Floating-point numbers with fractions (ones without fractions are ok for JsonNode.longValue()) will be truncated to long (if (and only if) they fit in long range).
      • JSON Strings that represent JSON Numbers ("stringified" numbers)
      • JSON Null (converted to 0))
      • POJO nodes that contain Number values
      Specified by:
      asLong in class NumericNode
      Returns:
      long value this node represents, if possible to accurately represent
    • asLong

      public final long asLong(long defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.asLong(), but that will return specified defaultValue if this node cannot be coerced to long (instead of throwing an exception).
      Specified by:
      asLong in class NumericNode
      Parameters:
      defaultValue - Value to return if this node cannot be coerced to long
      Returns:
      long value this node represents, if possible to accurately represent; defaultValue otherwise
    • asLongOpt

      public final OptionalLong asLongOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.asLong(), but that will return (OptionalLong.empty()) if this node cannot be coerced to long.
      Specified by:
      asLongOpt in class NumericNode
      Returns:
      OptionalLong value this node represents (or can be coerced to), OptionalLong.empty() otherwise
    • bigIntegerValue

      public final BigInteger bigIntegerValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as a BigInteger, but if node value cannot be expressed exactly as a BigInteger, a JsonNodeException will be thrown. Access works for following cases:
      • JSON Integer values
      • JSON Floating-point values that do not have fractional part.

      Specified by:
      bigIntegerValue in class NumericNode
      Returns:
      BigInteger value this node represents, if possible to accurately represent
    • bigIntegerValue

      public final BigInteger bigIntegerValue(BigInteger defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.bigIntegerValue(), but that will return specified defaultValue if this node cannot be converted to Java BigInteger.
      Specified by:
      bigIntegerValue in class NumericNode
      Parameters:
      defaultValue - Value to return if this node cannot be converted to Java BigInteger
      Returns:
      Java BigInteger value this node represents, if possible to accurately represent; defaultValue otherwise
    • bigIntegerValueOpt

      public final Optional<BigInteger> bigIntegerValueOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.bigIntegerValue(), but that will return empty (Optional.empty()) if this node cannot be converted to Java BigInteger.
      Specified by:
      bigIntegerValueOpt in class NumericNode
      Returns:
      Java BigInteger value this node represents, as Optional<BigInteger>, if possible to accurately represent; Optional.empty() otherwise
    • asBigInteger

      public final BigInteger asBigInteger()
      Description copied from class: JsonNode
      Method similar to JsonNode.bigIntegerValue() but in addition to coercing Number values (same as JsonNode.bigIntegerValue()), will also try to coerce a couple of additional types (or cases):
      • JSON Floating-point numbers with fractions (ones without fractions are ok for JsonNode.bigIntegerValue()) will be truncated to integer value (like with BigDecimal.toBigInteger()))
      • JSON Strings that represent JSON Numbers ("stringified" numbers)
      • JSON Null (converted to 0))
      • POJO nodes that contain Number values
      Specified by:
      asBigInteger in class NumericNode
      Returns:
      BigInteger value this node represents, if possible to accurately convert; defaultValue otherwise
    • asBigInteger

      public final BigInteger asBigInteger(BigInteger defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.asBigInteger(), but that will return specified defaultValue if this node cannot be converted to BigInteger.
      Specified by:
      asBigInteger in class NumericNode
      Parameters:
      defaultValue - Value to return if this node cannot be converted to BigInteger
      Returns:
      BigInteger value this node represents, if possible to accurately convert; defaultValue otherwise
    • asBigIntegerOpt

      public final Optional<BigInteger> asBigIntegerOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.bigIntegerValue(), but that will return empty (Optional.empty()) if this node cannot be converted to Java BigInteger.
      Specified by:
      asBigIntegerOpt in class NumericNode
      Returns:
      BigInteger value this node represents, as Optional<BigInteger>, if possible to accurately represent; Optional.empty() otherwise.
    • decimalValue

      public BigDecimal decimalValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as a Java BigDecimal: but if node value cannot be expressed exactly as a BigDecimal, a JsonNodeException will be thrown. Access works for following cases:
      • All JSON Number values

      NOTE: for more lenient conversions, use JsonNode.asDecimal()

      Specified by:
      decimalValue in class NumericNode
      Returns:
      BigDecimal value this node represents, if possible to accurately represent
    • decimalValue

      public BigDecimal decimalValue(BigDecimal defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.decimalValue(), but that will return defaultValue if this node cannot be coerced to Java BigDecimal.
      Specified by:
      decimalValue in class NumericNode
      Returns:
      BigDecimal value this node represents, if possible to accurately represent; defaultValue otherwise
    • decimalValueOpt

      public Optional<BigDecimal> decimalValueOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.decimalValue(), but that will return empty Optional (Optional.empty()) if this node cannot be coerced to BigDecimal.
      Specified by:
      decimalValueOpt in class NumericNode
      Returns:
      Java BigDecimal value this node represents, as Optional<BigDecimal>, if possible to accurately represent; Optional.empty() otherwise
    • asDecimal

      public BigDecimal asDecimal()
      Description copied from class: JsonNode
      Method that will try to access value of this node as a BigDecimal: but if node value cannot be expressed exactly as a BigDecimal, a JsonNodeException will be thrown. Access works for following cases:
      • JSON Floating-point values (but not "NaN" or "Infinity")
      • JSON Integer values
      • JSON String that represents JSON Numbers ("stringified" numbers)
      • JSON Null (converted to BigDecimal.ZERO))
      • POJO nodes that contain Number values

      Specified by:
      asDecimal in class NumericNode
      Returns:
      BigDecimal value this node represents, if possible to accurately represent
    • asDecimal

      public BigDecimal asDecimal(BigDecimal defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.asDecimal(), but that will return defaultValue if this node cannot be coerced to Java BigDecimal.
      Specified by:
      asDecimal in class NumericNode
      Returns:
      BigDecimal value this node represents, if possible to accurately represent; defaultValue otherwise
    • asDecimalOpt

      public Optional<BigDecimal> asDecimalOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.asDecimal(), but that will return empty Optional (Optional.empty()) if this node cannot be coerced to BigDecimal.
      Specified by:
      asDecimalOpt in class NumericNode
      Returns:
      Java BigDecimal value this node represents, as Optional<BigDecimal>, if possible to accurately represent; Optional.empty() otherwise
    • _asShortValueUnchecked

      protected abstract short _asShortValueUnchecked()
      Method for sub-classes to implement; returns the underlying value as a short without any checks (wrt NaN or value range), so caller must ensure validity prior to calling
    • _asIntValueUnchecked

      protected abstract int _asIntValueUnchecked()
      Method for sub-classes to implement; returns the underlying value as a int without any checks (wrt NaN or value range), so caller must ensure validity prior to calling
    • _asLongValueUnchecked

      protected abstract long _asLongValueUnchecked()
      Method for sub-classes to implement; returns the underlying value as a long without any checks (wrt NaN or value range), so caller must ensure validity prior to calling
    • _asBigIntegerValueUnchecked

      protected abstract BigInteger _asBigIntegerValueUnchecked()
      Method for sub-classes to implement; returns the underlying value as a BigInteger without any checks (wrt NaN), so caller must ensure validity prior to calling
    • _asDecimalValueUnchecked

      protected abstract BigDecimal _asDecimalValueUnchecked()
      Method for sub-classes to implement; returns the underlying value as a BigDecimal without any checks (wrt NaN), so caller must ensure validity prior to calling
    • _hasFractionalPart

      protected abstract boolean _hasFractionalPart()
    • _inShortRange

      protected abstract boolean _inShortRange()
    • _inIntRange

      protected abstract boolean _inIntRange()
    • _inLongRange

      protected abstract boolean _inLongRange()