Package org.apache.groovy.json.internal
Class NumberValue
java.lang.Object
java.lang.Number
org.apache.groovy.json.internal.NumberValue
- All Implemented Interfaces:
Serializable,Value
Overlay-backed numeric
Value that parses JSON numbers on demand.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an uninitialized numeric wrapper with no preset token type.NumberValue(boolean chop, Type type, int startIndex, int endIndex, char[] buffer) Creates a numeric overlay over a character buffer slice.NumberValue(Type type) Creates an uninitialized numeric wrapper for the supplied token type. -
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.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.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.<T extends Enum>
TConverts this token to an enum constant.static <T extends Enum>
TResolves an enum constant from its ordinal.toString()Returns the current numeric slice as text.final ObjecttoValue()Materializes this token as a regular Java value.
-
Constructor Details
-
NumberValue
Creates an uninitialized numeric wrapper for the supplied token type.- Parameters:
type- numeric token type
-
NumberValue
public NumberValue()Creates an uninitialized numeric wrapper with no preset token type. -
NumberValue
Creates a numeric overlay over a character buffer slice.- Parameters:
chop- whether to copy the slice immediatelytype- numeric token typestartIndex- slice startendIndex- slice endbuffer- backing buffer
-
-
Method Details
-
toString
Returns the current numeric slice as text. -
toValue
Materializes this token as a regular Java value. -
toEnum
Converts this token to an 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. -
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- Overrides:
shortValuein classNumber- Returns:
- the short representation
-
doubleValue
public double doubleValue()Converts this token to a double value.- Specified by:
doubleValuein interfaceValue- Specified by:
doubleValuein classNumber- 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- Specified by:
floatValuein classNumber- 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.
-