Package org.apache.groovy.json.internal
Class CharSequenceValue
java.lang.Object
org.apache.groovy.json.internal.CharSequenceValue
- All Implemented Interfaces:
CharSequence,Value
Overlay-backed
Value that keeps a character slice until conversion is required.-
Constructor Summary
ConstructorsConstructorDescriptionCharSequenceValue(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 TypeMethodDescriptionConverts this token to aBigDecimal.Converts this token to aBigInteger.booleanConverts this token to a boolean value.byteConverts this token to a byte value.final charcharAt(int index) Returns the character at the supplied backing-buffer index.charConverts this token to a single character.final voidchop()Copies any shared backing buffer into a dedicated slice.Converts this token to aDate.doubleConverts this token to a double value.booleanCompares the overlay state and cached value.floatConverts this token to a float value.inthashCode()Returns a hash code for the overlay state and cached value.intintValue()Converts this token to an int value.booleanIndicates whether this value wraps a map or a collection.final intlength()Returns the length of the current backing buffer.longConverts this token to a long value.shortConverts this token to a short value.Returns the string form using the value's configured decoding policy.Returns the fully decoded string form.final CharSequencesubSequence(int start, int end) Creates another overlay view over the same backing buffer.<T extends Enum>
TConverts this token to an enum constant.static <T extends Enum>
TResolves an enum constant from its ordinal.static <T extends Enum>
TResolves an enum constant from the decoded token text.toString()Returns the current character slice without additional decoding.final ObjecttoValue()Materializes this token as a regular Java value.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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 immediatelytype- token typestartIndex- slice startendIndex- slice endbuffer- backing bufferencoded- whether string decoding should be appliedcheckDate- whether string values should be probed for date conversion
-
-
Method Details
-
toString
Returns the current character slice without additional decoding.- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject- Returns:
- the raw slice text
-
toValue
Materializes this token as a regular Java value. -
toEnum
Converts this token to an enum constant. -
toEnum
Resolves an enum constant from the decoded token text.- Type Parameters:
T- enum type- Parameters:
cls- enum typevalue- decoded token text- Returns:
- the matching enum constant
-
toEnum
Resolves an enum constant from its ordinal.- Type Parameters:
T- enum type- Parameters:
cls- enum typevalue- ordinal value- Returns:
- the matching enum constant
-
isContainer
public boolean isContainer()Indicates whether this value wraps a map or a collection.- Specified by:
isContainerin interfaceValue- Returns:
truefor container values
-
equals
Compares the overlay state and cached value. -
hashCode
public int hashCode()Returns a hash code for the overlay state and cached value. -
length
public final int length()Returns the length of the current backing buffer.- Specified by:
lengthin interfaceCharSequence- Returns:
- backing buffer length
-
charAt
public final char charAt(int index) Returns the character at the supplied backing-buffer index.- Specified by:
charAtin interfaceCharSequence- Parameters:
index- backing-buffer index- Returns:
- the character at
index
-
subSequence
Creates another overlay view over the same backing buffer.- Specified by:
subSequencein interfaceCharSequence- Parameters:
start- subsequence start in the backing bufferend- subsequence end in the backing buffer- Returns:
- a new overlay view
-
bigDecimalValue
Converts this token to aBigDecimal.- Specified by:
bigDecimalValuein interfaceValue- Returns:
- the decimal representation
-
bigIntegerValue
Converts this token to aBigInteger.- Specified by:
bigIntegerValuein interfaceValue- Returns:
- the integer representation
-
stringValue
Returns the string form using the value's configured decoding policy.- Specified by:
stringValuein interfaceValue- Returns:
- the string representation
-
stringValueEncoded
Returns the fully decoded string form.- Specified by:
stringValueEncodedin interfaceValue- Returns:
- the decoded string representation
-
dateValue
Converts this token to aDate. -
intValue
public int intValue()Converts this token to an int value. -
longValue
public long longValue()Converts this token to a long value. -
byteValue
public byte byteValue()Converts this token to a byte value. -
shortValue
public short shortValue()Converts this token to a short value.- Specified by:
shortValuein interfaceValue- Returns:
- the short representation
-
doubleValue
public double doubleValue()Converts this token to a double value.- Specified by:
doubleValuein interfaceValue- Returns:
- the double representation
-
booleanValue
public boolean booleanValue()Converts this token to a boolean value.- Specified by:
booleanValuein interfaceValue- Returns:
- the boolean representation
-
floatValue
public float floatValue()Converts this token to a float value.- Specified by:
floatValuein interfaceValue- Returns:
- the float representation
-
chop
public final void chop()Copies any shared backing buffer into a dedicated slice. -
charValue
public char charValue()Converts this token to a single character.
-