Class FloatNode

All Implemented Interfaces:
Serializable, Iterable<JsonNode>, tools.jackson.core.TreeNode, JacksonSerializable

public class FloatNode extends NumericNode
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)
    • asToken

      public tools.jackson.core.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 tools.jackson.core.TreeNode
      Specified by:
      asToken in class ValueNode
    • numberType

      public tools.jackson.core.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 tools.jackson.core.TreeNode
      Specified by:
      numberType in class NumericNode
    • isFloatingPointNumber

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

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

      public 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 it (that is, its value fits within 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 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 it (that is, its value fits within 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 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 losslessly converted 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 can not 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.
    • 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
    • shortValue

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

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

      public 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 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 Java long.
      Specified by:
      longValue in class NumericNode
      Parameters:
      defaultValue - Value to return if this node cannot be converted to Java long
      Returns:
      Java long value this node represents, if possible to accurately represent; defaultValue otherwise
    • longValueOpt

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

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

      public double doubleValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as a Java 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 Java double.
      Specified by:
      doubleValue in class NumericNode
      Parameters:
      defaultValue - Value to return if this node cannot be converted to Java double
      Returns:
      Java 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
    • 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
    • asString

      public String asString()
      Description copied from class: JsonNode
      Method that will return a valid String representation of the contained value, if the node is a value node (method JsonNode.isValueNode() returns true), otherwise empty String.

      NOTE: this is NOT same as JsonNode.toString() in that result is

      NOT VALID ENCODED JSON

      for all nodes (but is for some, like NumberNodes and BooleanNodes).
      Specified by:
      asString in class NumericNode
    • 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
    • serialize

      public final void serialize(tools.jackson.core.JsonGenerator g, SerializationContext provider) throws tools.jackson.core.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:
      tools.jackson.core.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