Package org.apache.groovy.json.internal

# 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`
  `decodeStrings`
  Indicates whether string values should decode escape sequences when materialized.
  `static final Value`
  `FALSE`
  Shared wrapper for the JSON literal `false`.
  `static final Value`
  `NULL`
  Shared wrapper for the JSON literal `null`.
  `static final Value`
  `TRUE`
  Shared wrapper for the JSON literal `true`.
  `Type`
  `type`
  Token type represented by this wrapper.
  `Object`
  `value`
  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.
  `ValueContainer(List<Object> list)`
  Creates a wrapper for a parsed array container.
  `ValueContainer(Map<String,Object> map)`
  Creates a wrapper for a parsed object container.
  `ValueContainer(Type type)`
  Creates a wrapper for a scalar token that can be materialized later.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `BigDecimal`
  `bigDecimalValue()`
  Returns `null` because this wrapper is not numeric.
  `BigInteger`
  `bigIntegerValue()`
  Returns `null` because this wrapper is not numeric.
  `boolean`
  `booleanValue()`
  Converts this token to a boolean value.
  `byte`
  `byteValue()`
  Returns `0` because this wrapper is not numeric.
  `char`
  `charAt(int index)`
  Returns the placeholder character `'0'` because no character data is available.
  `char`
  `charValue()`
  Returns `0` because this wrapper is not backed by character data.
  `void`
  `chop()`
  No-op because this wrapper does not retain a shared parser buffer.
  `Date`
  `dateValue()`
  Returns `null` because this wrapper does not provide date conversion here.
  `double`
  `doubleValue()`
  Returns `0` because this wrapper is not numeric.
  `float`
  `floatValue()`
  Returns `0` because this wrapper is not numeric.
  `int`
  `intValue()`
  Unsupported for these literal and container wrappers.
  `boolean`
  `isContainer()`
  Indicates whether this value wraps a map or a collection.
  `int`
  `length()`
  Returns `0` because this wrapper does not expose a character sequence.
  `long`
  `longValue()`
  Unsupported for these literal and container wrappers.
  `short`
  `shortValue()`
  Returns `0` because this wrapper is not numeric.
  `String`
  `stringValue()`
  Returns the string form using the value's configured decoding policy.
  `String`
  `stringValueEncoded()`
  Returns the fully decoded string form.
  `CharSequence`
  `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.
  `String`
  `toString()`
  Returns the token name for this wrapper.
  `Object`
  `toValue()`
  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`