Class ValueContainer

java.lang.Object
org.apache.groovy.json.internal.ValueContainer
All Implemented Interfaces:
CharSequence, Value

public class ValueContainer extends Object implements CharSequence, Value
Simple Value wrapper for literals and already-hydrated JSON containers.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    boolean
    Indicates whether string values should decode escape sequences when materialized.
    static final Value
    Shared wrapper for the JSON literal false.
    static final Value
    Shared wrapper for the JSON literal null.
    static final Value
    Shared wrapper for the JSON literal true.
    Token type represented by this wrapper.
    Cached hydrated value, when one already exists.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ValueContainer(Object value, Type type, boolean decodeStrings)
    Creates a wrapper around an already known value and type.
    Creates a wrapper for a parsed array container.
    Creates a wrapper for a parsed object container.
    Creates a wrapper for a scalar token that can be materialized later.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns null because this wrapper is not numeric.
    Returns null because this wrapper is not numeric.
    boolean
    Converts this token to a boolean value.
    byte
    Returns 0 because this wrapper is not numeric.
    char
    charAt(int index)
    Returns the placeholder character '0' because no character data is available.
    char
    Returns 0 because this wrapper is not backed by character data.
    void
    No-op because this wrapper does not retain a shared parser buffer.
    Returns null because this wrapper does not provide date conversion here.
    double
    Returns 0 because this wrapper is not numeric.
    float
    Returns 0 because this wrapper is not numeric.
    int
    Unsupported for these literal and container wrappers.
    boolean
    Indicates whether this value wraps a map or a collection.
    int
    Returns 0 because this wrapper does not expose a character sequence.
    long
    Unsupported for these literal and container wrappers.
    short
    Returns 0 because this wrapper is not numeric.
    Returns the string form using the value's configured decoding policy.
    Returns the fully decoded string form.
    subSequence(int start, int end)
    Returns an empty character sequence because this wrapper has no character backing.
    <T extends Enum>
    T
    toEnum(Class<T> cls)
    Returns the cached enum instance stored in this wrapper.
    Returns the token name for this wrapper.
    Materializes this token as a regular Java value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.CharSequence

    chars, codePoints, isEmpty
  • Field Details

    • TRUE

      public static final Value TRUE
      Shared wrapper for the JSON literal true.
    • FALSE

      public static final Value FALSE
      Shared wrapper for the JSON literal false.
    • NULL

      public static final Value NULL
      Shared wrapper for the JSON literal null.
    • value

      public Object value
      Cached hydrated value, when one already exists.
    • type

      public Type type
      Token type represented by this wrapper.
    • decodeStrings

      public boolean decodeStrings
      Indicates whether string values should decode escape sequences when materialized.
  • Constructor Details

    • ValueContainer

      public ValueContainer(Object value, Type type, boolean decodeStrings)
      Creates a wrapper around an already known value and type.
      Parameters:
      value - cached value
      type - token type
      decodeStrings - whether string decoding should be applied
    • ValueContainer

      public ValueContainer(Type type)
      Creates a wrapper for a scalar token that can be materialized later.
      Parameters:
      type - token type
    • ValueContainer

      public ValueContainer(Map<String,Object> map)
      Creates a wrapper for a parsed object container.
      Parameters:
      map - hydrated object value
    • ValueContainer

      public ValueContainer(List<Object> list)
      Creates a wrapper for a parsed array container.
      Parameters:
      list - hydrated array value
  • Method Details

    • intValue

      public int intValue()
      Unsupported for these literal and container wrappers.
      Specified by:
      intValue in interface Value
      Returns:
      never returns normally
    • longValue

      public long longValue()
      Unsupported for these literal and container wrappers.
      Specified by:
      longValue in interface Value
      Returns:
      never returns normally
    • booleanValue

      public boolean booleanValue()
      Converts this token to a boolean value.
      Specified by:
      booleanValue in interface Value
      Returns:
      the boolean 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
    • toString

      public String toString()
      Returns the token name for this wrapper.
      Specified by:
      toString in interface CharSequence
      Overrides:
      toString in class Object
      Returns:
      the type name
    • toValue

      public 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)
      Returns the cached enum instance stored in this wrapper.
      Specified by:
      toEnum in interface Value
      Type Parameters:
      T - enum type
      Parameters:
      cls - enum type
      Returns:
      the cached enum value
    • 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
    • chop

      public void chop()
      No-op because this wrapper does not retain a shared parser buffer.
      Specified by:
      chop in interface Value
    • charValue

      public char charValue()
      Returns 0 because this wrapper is not backed by character data.
      Specified by:
      charValue in interface Value
      Returns:
      0
    • length

      public int length()
      Returns 0 because this wrapper does not expose a character sequence.
      Specified by:
      length in interface CharSequence
      Returns:
      0
    • charAt

      public char charAt(int index)
      Returns the placeholder character '0' because no character data is available.
      Specified by:
      charAt in interface CharSequence
      Parameters:
      index - ignored
      Returns:
      '0'
    • subSequence

      public CharSequence subSequence(int start, int end)
      Returns an empty character sequence because this wrapper has no character backing.
      Specified by:
      subSequence in interface CharSequence
      Parameters:
      start - ignored
      end - ignored
      Returns:
      an empty sequence
    • dateValue

      public Date dateValue()
      Returns null because this wrapper does not provide date conversion here.
      Specified by:
      dateValue in interface Value
      Returns:
      null
    • byteValue

      public byte byteValue()
      Returns 0 because this wrapper is not numeric.
      Specified by:
      byteValue in interface Value
      Returns:
      0
    • shortValue

      public short shortValue()
      Returns 0 because this wrapper is not numeric.
      Specified by:
      shortValue in interface Value
      Returns:
      0
    • bigDecimalValue

      public BigDecimal bigDecimalValue()
      Returns null because this wrapper is not numeric.
      Specified by:
      bigDecimalValue in interface Value
      Returns:
      null
    • bigIntegerValue

      public BigInteger bigIntegerValue()
      Returns null because this wrapper is not numeric.
      Specified by:
      bigIntegerValue in interface Value
      Returns:
      null
    • doubleValue

      public double doubleValue()
      Returns 0 because this wrapper is not numeric.
      Specified by:
      doubleValue in interface Value
      Returns:
      0
    • floatValue

      public float floatValue()
      Returns 0 because this wrapper is not numeric.
      Specified by:
      floatValue in interface Value
      Returns:
      0