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)`
  Creates a value view over a character buffer slice.

- ## 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

    public CharSequenceValue(boolean chop, Type type, int startIndex, int endIndex, char[] buffer, boolean encoded, boolean checkDate)
    Creates a value view over a character buffer slice.
    Parameters:
      `chop` - whether to copy the slice immediately
      `type` - token type
      `startIndex` - slice start
      `endIndex` - slice end
      `buffer` - backing buffer
      `encoded` - whether string decoding should be applied
      `checkDate` - whether string values should be probed for date conversion

- ## 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