Package org.apache.groovy.json.internal

# Class CharSequenceValue

java.lang.Object
org.apache.groovy.json.internal.CharSequenceValue

All Implemented Interfaces:
  `CharSequence`, `Value`

public class CharSequenceValue extends Object implements Value, CharSequence
Overlay-backed `Value` that keeps a character slice until conversion is required.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CharSequenceValue(boolean chop, Type type, int startIndex, int endIndex, char[] buffer, boolean encoded, boolean checkDate)`
  Deprecated.
  use the constructor taking a `JsonDateHandling`
  `CharSequenceValue(boolean chop, Type type, int startIndex, int endIndex, char[] buffer, boolean encoded, JsonDateHandling dateHandling)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `BigDecimal`
  `bigDecimalValue()`
  Converts this token to a `BigDecimal`.
  `BigInteger`
  `bigIntegerValue()`
  Converts this token to a `BigInteger`.
  `boolean`
  `booleanValue()`
  Converts this token to a boolean value.
  `byte`
  `byteValue()`
  Converts this token to a byte value.
  `final char`
  `charAt(int index)`
  Returns the character at the supplied backing-buffer index.
  `char`
  `charValue()`
  Converts this token to a single character.
  `final void`
  `chop()`
  Copies any shared backing buffer into a dedicated slice.
  `Date`
  `dateValue()`
  Converts this token to a `Date`.
  `double`
  `doubleValue()`
  Converts this token to a double value.
  `boolean`
  `equals(Object o)`
  Compares the overlay state and cached value.
  `float`
  `floatValue()`
  Converts this token to a float value.
  `int`
  `hashCode()`
  Returns a hash code for the overlay state and cached value.
  `int`
  `intValue()`
  Converts this token to an int value.
  `boolean`
  `isContainer()`
  Indicates whether this value wraps a map or a collection.
  `final int`
  `length()`
  Returns the length of the current backing buffer.
  `long`
  `longValue()`
  Converts this token to a long value.
  `short`
  `shortValue()`
  Converts this token to a short value.
  `String`
  `stringValue()`
  Returns the string form using the value's configured decoding policy.
  `String`
  `stringValueEncoded()`
  Returns the fully decoded string form.
  `final CharSequence`
  `subSequence(int start, int end)`
  Creates another overlay view over the same backing buffer.
  `<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.
  `static <T extends Enum>
  T`
  `toEnum(Class<T> cls, String value)`
  Resolves an enum constant from the decoded token text.
  `String`
  `toString()`
  Returns the current character slice without additional decoding.
  `final Object`
  `toValue()`
  Materializes this token as a regular Java value.

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface java.lang.CharSequence

  `chars, codePoints, isEmpty`

- ## Constructor Details

  - ### CharSequenceValue

    @Deprecated public CharSequenceValue(boolean chop, Type type, int startIndex, int endIndex, char[] buffer, boolean encoded, boolean checkDate)
    Deprecated.
    use the constructor taking a `JsonDateHandling`
    Retained so that the boolean form of this constructor keeps working.
    Parameters:
      `chop` - whether to eagerly copy the slice out of the buffer
      `type` - token type
      `startIndex` - start index, inclusive
      `endIndex` - end index, exclusive
      `buffer` - buffer holding the token
      `encoded` - whether the token carries escapes
      `checkDate` - whether a date-like string should become a `Date`

  - ### CharSequenceValue

    public CharSequenceValue(boolean chop, Type type, int startIndex, int endIndex, char[] buffer, boolean encoded, JsonDateHandling dateHandling)

- ## Method Details

  - ### toString

    public String toString()
    Returns the current character slice without additional decoding.
    Specified by:
      `toString` in interface `CharSequence`
    Overrides:
      `toString` in class `Object`
    Returns:
      the raw slice 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, String value)
    Resolves an enum constant from the decoded token text.
    Type Parameters:
      `T` - enum type
    Parameters:
      `cls` - enum type
      `value` - decoded token text
    Returns:
      the matching 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 value view

  - ### length

    public final int length()
    Returns the length of the current backing buffer.
    Specified by:
      `length` in interface `CharSequence`
    Returns:
      backing buffer length

  - ### charAt

    public final char charAt(int index)
    Returns the character at the supplied backing-buffer index.
    Specified by:
      `charAt` in interface `CharSequence`
    Parameters:
      `index` - backing-buffer index
    Returns:
      the character at `index`

  - ### subSequence

    public final CharSequence subSequence(int start, int end)
    Creates another overlay view over the same backing buffer.
    Specified by:
      `subSequence` in interface `CharSequence`
    Parameters:
      `start` - subsequence start in the backing buffer
      `end` - subsequence end in the backing buffer
    Returns:
      a new overlay view

  - ### 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`
    Returns:
      the int representation

  - ### longValue

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

  - ### byteValue

    public byte byteValue()
    Converts this token to a byte value.
    Specified by:
      `byteValue` in interface `Value`
    Returns:
      the byte representation

  - ### shortValue

    public short shortValue()
    Converts this token to a short value.
    Specified by:
      `shortValue` in interface `Value`
    Returns:
      the short representation

  - ### doubleValue

    public double doubleValue()
    Converts this token to a double value.
    Specified by:
      `doubleValue` in interface `Value`
    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`
    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