Class NumericIntNode

All Implemented Interfaces:
Serializable, Iterable<JsonNode>, TreeNode, JacksonSerializable
Direct Known Subclasses:
BigIntegerNode, IntNode, LongNode, ShortNode

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

    • NumericIntNode

      public NumericIntNode()
  • 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
    • isIntegralNumber

      public final boolean isIntegralNumber()
      Overrides:
      isIntegralNumber in class JsonNode
      Returns:
      True if this node represents an integral (integer) numeric JSON value
    • isNaN

      public final boolean isNaN()
      Description copied from class: NumericNode
      Convenience method for checking whether this node is a FloatNode or DoubleNode that contains "not-a-number" (NaN) value.
      Specified by:
      isNaN in class NumericNode
    • 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
    • bigIntegerValue

      public abstract 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 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 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 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 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 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.
    • floatValue

      public float floatValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as a Java float: but if node value cannot be expressed exactly as a float, a JsonNodeException will be thrown. Access works for following cases:
      • JSON Floating-point values that fit in Java 32-bit double range
      • JSON Integer values that fit in Java 32-bit double range

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

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

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

      public float asFloat()
      Description copied from class: JsonNode
      Method similar to JsonNode.floatValue() but in addition to coercing Number values will also try coerce couple of additional types:
      • JSON String that represents JSON Numbers ("stringified" numbers)
      • JSON Null (converted to 0.0f)
      • POJO nodes that contain Number values

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

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

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

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

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

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

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

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

      public double asDouble()
      Description copied from class: JsonNode
      Method similar to JsonNode.doubleValue() but in addition to coercing Number values will also try coerce couple of additional types:
      • JSON String that represents JSON Numbers ("stringified" numbers)
      • JSON Null (converted to 0.0d)
      • POJO nodes that contain Number values

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

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

      public OptionalDouble asDoubleOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.asDouble(), but that will return (OptionalDouble.empty()) if this node cannot be coerced to double.
      Specified by:
      asDoubleOpt in class NumericNode
      Returns:
      OptionalDouble value this node represents, if possible to accurately represent; OptionalDouble.empty() otherwise
    • 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
    • _asIntValueUnchecked

      protected abstract int _asIntValueUnchecked()
    • _asFloatValueUnchecked

      protected abstract float _asFloatValueUnchecked()
    • _asDoubleValueUnchecked

      protected abstract double _asDoubleValueUnchecked()
    • _inShortRange

      protected abstract boolean _inShortRange()
    • _inIntRange

      protected abstract boolean _inIntRange()
    • _inLongRange

      protected abstract boolean _inLongRange()