Class NumberValue

java.lang.Object
java.lang.Number
org.apache.groovy.json.internal.NumberValue
All Implemented Interfaces:
Serializable, Value

public class NumberValue extends Number implements Value
Overlay-backed numeric Value that parses JSON numbers on demand.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an uninitialized numeric wrapper with no preset token type.
    NumberValue(boolean chop, Type type, int startIndex, int endIndex, char[] buffer)
    Creates a numeric overlay over a character buffer slice.
    Creates an uninitialized numeric wrapper for the supplied token type.
  • Method Summary

    Modifier and Type
    Method
    Description
    Converts this token to a BigDecimal.
    Converts this token to a BigInteger.
    boolean
    Converts this token to a boolean value.
    byte
    Converts this token to a byte value.
    char
    Converts this token to a single character.
    final void
    Copies any shared backing buffer into a dedicated slice.
    Converts this token to a Date.
    double
    Converts this token to a double value.
    boolean
    Compares the overlay state and cached value.
    float
    Converts this token to a float value.
    int
    Returns a hash code for the overlay state and cached value.
    int
    Converts this token to an int value.
    boolean
    Indicates whether this value wraps a map or a collection.
    long
    Converts this token to a long value.
    short
    Converts this token to a short value.
    Returns the string form using the value's configured decoding policy.
    Returns the fully decoded string form.
    <T extends Enum>
    T
    toEnum(Class<T> cls)
    Converts this token to an enum constant.
    static <T extends Enum>
    T
    toEnum(Class<T> cls, int value)
    Resolves an enum constant from its ordinal.
    Returns the current numeric slice as text.
    final Object
    Materializes this token as a regular Java value.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • NumberValue

      public NumberValue(Type type)
      Creates an uninitialized numeric wrapper for the supplied token type.
      Parameters:
      type - numeric token type
    • NumberValue

      public NumberValue()
      Creates an uninitialized numeric wrapper with no preset token type.
    • NumberValue

      public NumberValue(boolean chop, Type type, int startIndex, int endIndex, char[] buffer)
      Creates a numeric overlay over a character buffer slice.
      Parameters:
      chop - whether to copy the slice immediately
      type - numeric token type
      startIndex - slice start
      endIndex - slice end
      buffer - backing buffer
  • Method Details

    • toString

      public String toString()
      Returns the current numeric slice as text.
      Overrides:
      toString in class Object
      Returns:
      the raw numeric token text
    • toValue

      public final Object toValue()
      Materializes this token as a regular Java value.
      Specified by:
      toValue in interface Value
      Returns:
      the hydrated value
    • toEnum

      public <T extends Enum> T toEnum(Class<T> cls)
      Converts this token to an enum constant.
      Specified by:
      toEnum in interface Value
      Type Parameters:
      T - enum type
      Parameters:
      cls - enum type to resolve
      Returns:
      the resolved enum constant
    • toEnum

      public static <T extends Enum> T toEnum(Class<T> cls, int value)
      Resolves an enum constant from its ordinal.
      Type Parameters:
      T - enum type
      Parameters:
      cls - enum type
      value - ordinal value
      Returns:
      the matching enum constant
    • isContainer

      public boolean isContainer()
      Indicates whether this value wraps a map or a collection.
      Specified by:
      isContainer in interface Value
      Returns:
      true for container values
    • equals

      public boolean equals(Object o)
      Compares the overlay state and cached value.
      Overrides:
      equals in class Object
      Parameters:
      o - other object
      Returns:
      true when the overlays match
    • hashCode

      public int hashCode()
      Returns a hash code for the overlay state and cached value.
      Overrides:
      hashCode in class Object
      Returns:
      hash code for this numeric overlay
    • bigDecimalValue

      public BigDecimal bigDecimalValue()
      Converts this token to a BigDecimal.
      Specified by:
      bigDecimalValue in interface Value
      Returns:
      the decimal representation
    • bigIntegerValue

      public BigInteger bigIntegerValue()
      Converts this token to a BigInteger.
      Specified by:
      bigIntegerValue in interface Value
      Returns:
      the integer representation
    • stringValue

      public String stringValue()
      Returns the string form using the value's configured decoding policy.
      Specified by:
      stringValue in interface Value
      Returns:
      the string representation
    • stringValueEncoded

      public String stringValueEncoded()
      Returns the fully decoded string form.
      Specified by:
      stringValueEncoded in interface Value
      Returns:
      the decoded string representation
    • dateValue

      public Date dateValue()
      Converts this token to a Date.
      Specified by:
      dateValue in interface Value
      Returns:
      the date representation
    • intValue

      public int intValue()
      Converts this token to an int value.
      Specified by:
      intValue in interface Value
      Specified by:
      intValue in class Number
      Returns:
      the int representation
    • longValue

      public long longValue()
      Converts this token to a long value.
      Specified by:
      longValue in interface Value
      Specified by:
      longValue in class Number
      Returns:
      the long representation
    • byteValue

      public byte byteValue()
      Converts this token to a byte value.
      Specified by:
      byteValue in interface Value
      Overrides:
      byteValue in class Number
      Returns:
      the byte representation
    • shortValue

      public short shortValue()
      Converts this token to a short value.
      Specified by:
      shortValue in interface Value
      Overrides:
      shortValue in class Number
      Returns:
      the short representation
    • doubleValue

      public double doubleValue()
      Converts this token to a double value.
      Specified by:
      doubleValue in interface Value
      Specified by:
      doubleValue in class Number
      Returns:
      the double representation
    • booleanValue

      public boolean booleanValue()
      Converts this token to a boolean value.
      Specified by:
      booleanValue in interface Value
      Returns:
      the boolean representation
    • floatValue

      public float floatValue()
      Converts this token to a float value.
      Specified by:
      floatValue in interface Value
      Specified by:
      floatValue in class Number
      Returns:
      the float representation
    • chop

      public final void chop()
      Copies any shared backing buffer into a dedicated slice.
      Specified by:
      chop in interface Value
    • charValue

      public char charValue()
      Converts this token to a single character.
      Specified by:
      charValue in interface Value
      Returns:
      the leading character representation