Class FloatNode

All Implemented Interfaces:
Serializable, Iterable<JsonNode>, TreeNode, JacksonSerializable

public class FloatNode extends NumericFPNode
JsonNode implementation for efficiently containing 32-bit `float` values.
See Also:
  • Field Details

    • _value

      protected final float _value
  • Constructor Details

    • FloatNode

      public FloatNode(float v)
  • Method Details

    • valueOf

      public static FloatNode valueOf(float v)
    • numberType

      public JsonParser.NumberType numberType()
      Description copied from class: BaseJsonNode
      Returns code that identifies type of underlying numeric value, if (and only if) node is a number node.
      Specified by:
      numberType in interface TreeNode
      Specified by:
      numberType in class NumericNode
    • isFloat

      public boolean isFloat()
      Overrides:
      isFloat in class JsonNode
    • isNaN

      public 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
    • _asString

      protected String _asString()
      Description copied from class: BaseJsonNode
      Method sub-classes should override if they can produce String values via BaseJsonNode.asString() -- if not, return null (in which case appropriate error will be thrown or default value returned).
      Specified by:
      _asString in class NumericNode
      Returns:
      Coerced value if possible; otherwise null to indicate this node cannot be coerced.
    • numberValue

      public Number numberValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as Number that accurately represents its value, if (and only if) this is a number node (returns true for JsonNode.isNumber()). If this node is NOT a number node, a JsonNodeException will be thrown.
      Specified by:
      numberValue in class NumericNode
      Returns:
      Number value this node contains, if numeric node
    • 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
    • _asShortValueUnchecked

      protected short _asShortValueUnchecked()
      Description copied from class: NumericFPNode
      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
      Specified by:
      _asShortValueUnchecked in class NumericFPNode
    • _asIntValueUnchecked

      protected int _asIntValueUnchecked()
      Description copied from class: NumericFPNode
      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
      Specified by:
      _asIntValueUnchecked in class NumericFPNode
    • _asLongValueUnchecked

      protected long _asLongValueUnchecked()
      Description copied from class: NumericFPNode
      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
      Specified by:
      _asLongValueUnchecked in class NumericFPNode
    • _asBigIntegerValueUnchecked

      protected BigInteger _asBigIntegerValueUnchecked()
      Description copied from class: NumericFPNode
      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
      Specified by:
      _asBigIntegerValueUnchecked in class NumericFPNode
    • _asDecimalValueUnchecked

      protected BigDecimal _asDecimalValueUnchecked()
      Description copied from class: NumericFPNode
      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
      Specified by:
      _asDecimalValueUnchecked in class NumericFPNode
    • _hasFractionalPart

      protected boolean _hasFractionalPart()
      Specified by:
      _hasFractionalPart in class NumericFPNode
    • _inShortRange

      protected boolean _inShortRange()
      Specified by:
      _inShortRange in class NumericFPNode
    • _inIntRange

      protected boolean _inIntRange()
      Specified by:
      _inIntRange in class NumericFPNode
    • _inLongRange

      protected boolean _inLongRange()
      Specified by:
      _inLongRange in class NumericFPNode
    • serialize

      public final void serialize(JsonGenerator g, SerializationContext provider) throws JacksonException
      Description copied from class: BaseJsonNode
      Method called to serialize node instances using given generator.
      Specified by:
      serialize in interface JacksonSerializable
      Specified by:
      serialize in class BaseJsonNode
      Throws:
      JacksonException
    • equals

      public boolean equals(Object o)
      Description copied from class: JsonNode
      Equality for node objects is defined as full (deep) value equality. This means that it is possible to compare complete JSON trees for equality by comparing equality of root nodes.

      Note: marked as abstract to ensure all implementation classes define it properly and not rely on definition from Object.

      Specified by:
      equals in class JsonNode
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in class BaseJsonNode