Interface Value
-
- All Known Subinterfaces:
ArrayValue,BinaryValue,BooleanValue,ExtensionValue,FloatValue,ImmutableArrayValue,ImmutableBinaryValue,ImmutableBooleanValue,ImmutableExtensionValue,ImmutableFloatValue,ImmutableIntegerValue,ImmutableMapValue,ImmutableNilValue,ImmutableNumberValue,ImmutableRawValue,ImmutableStringValue,ImmutableValue,IntegerValue,MapValue,NilValue,NumberValue,RawValue,StringValue
- All Known Implementing Classes:
AbstractImmutableRawValue,ImmutableArrayValueImpl,ImmutableBigIntegerValueImpl,ImmutableBinaryValueImpl,ImmutableBooleanValueImpl,ImmutableDoubleValueImpl,ImmutableExtensionValueImpl,ImmutableLongValueImpl,ImmutableMapValueImpl,ImmutableNilValueImpl,ImmutableStringValueImpl,Variable
public interface ValueValue stores a value and its type in MessagePack type system.Type conversion
You can check type first using isXxx() methods or
getValueType()method, then convert the value to a subtype using asXxx() methods. You can also call asXxx() methods directly and catchMessageTypeCastException.MessagePack type Check method Convert method Value type Nil isNilValue()asNumberValue()NilValueBoolean isBooleanValue()asBooleanValue()BooleanValueInteger or Float isNumberValue()asNumberValue()NumberValueInteger isIntegerValue()asIntegerValue()IntegerValueFloat isFloatValue()asFloatValue()FloatValueString or Binary isRawValue()asRawValue()RawValueString isStringValue()asStringValue()StringValueBinary isBinaryValue()asBinaryValue()BinaryValueArray isArrayValue()asArrayValue()ArrayValueMap isMapValue()asMapValue()MapValueExtension isExtensionValue()asExtensionValue()ExtensionValueImmutable interface
Value interface is the base interface of all Value interfaces. Immutable subtypes are useful so that you can declare that a (final) field or elements of a container object are immutable. Method arguments should be a regular Value interface generally.
You can use
immutableValue()method to get immutable subtypes.MessagePack type Subtype method Immutable value type any types Value.immutableValue()ImmutableValueNil NilValue.immutableValue()ImmutableNilValueBoolean BooleanValue.immutableValue()ImmutableBooleanValueInteger IntegerValue.immutableValue()ImmutableIntegerValueFloat FloatValue.immutableValue()ImmutableFloatValueInteger or Float NumberValue.immutableValue()ImmutableNumberValueString or Binary RawValue.immutableValue()ImmutableRawValueString StringValue.immutableValue()ImmutableStringValueBinary BinaryValue.immutableValue()ImmutableBinaryValueArray ArrayValue.immutableValue()ImmutableArrayValueMap MapValue.immutableValue()ImmutableMapValueExtension ExtensionValue.immutableValue()ImmutableExtensionValueConverting to JSON
toJson()method returns JSON representation of a Value. See its documents for details.toString() also returns a string representation of a Value that is similar to JSON. However, unlike toJson() method, toString() may return a special format that is not be compatible with JSON when JSON doesn't support the type such as ExtensionValue.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ArrayValueasArrayValue()Returns the value asArrayValue.BinaryValueasBinaryValue()Returns the value asBinaryValue.BooleanValueasBooleanValue()Returns the value asBooleanValue.ExtensionValueasExtensionValue()Returns the value asExtensionValue.FloatValueasFloatValue()Returns the value asFloatValue.IntegerValueasIntegerValue()Returns the value asIntegerValue.MapValueasMapValue()Returns the value asMapValue.NilValueasNilValue()Returns the value asNilValue.NumberValueasNumberValue()Returns the value asNumberValue.RawValueasRawValue()Returns the value asRawValue.StringValueasStringValue()Returns the value asStringValue.booleanequals(java.lang.Object obj)Compares this value to the specified object.ValueTypegetValueType()Returns type of this value.ImmutableValueimmutableValue()Returns immutable copy of this value.booleanisArrayValue()Returns true if type of this value is Array.booleanisBinaryValue()Returns true if type of this value is Binary.booleanisBooleanValue()Returns true if type of this value is Boolean.booleanisExtensionValue()Returns true if type of this an Extension.booleanisFloatValue()Returns true if type of this value is Float.booleanisIntegerValue()Returns true if type of this value is Integer.booleanisMapValue()Returns true if type of this value is Map.booleanisNilValue()Returns true if type of this value is Nil.booleanisNumberValue()Returns true if type of this value is Integer or Float.booleanisRawValue()Returns true if type of this value is String or Binary.booleanisStringValue()Returns true if type of this value is String.java.lang.StringtoJson()Returns json representation of this Value.voidwriteTo(MessagePacker pk)Serializes the value using the specifiedMessagePacker
-
-
-
Method Detail
-
getValueType
ValueType getValueType()
Returns type of this value.Note that you can't use
instanceofto check type of a value because type of a mutable value is variable.
-
immutableValue
ImmutableValue immutableValue()
Returns immutable copy of this value.This method simply returns
thiswithout copying the value if this value is already immutable.
-
isNilValue
boolean isNilValue()
Returns true if type of this value is Nil.If this method returns true,
asNilValuenever throws exceptions. Note that you can't useinstanceofor cast((NilValue) thisValue)to check type of a value because type of a mutable value is variable.
-
isBooleanValue
boolean isBooleanValue()
Returns true if type of this value is Boolean.If this method returns true,
asBooleanValuenever throws exceptions. Note that you can't useinstanceofor cast((BooleanValue) thisValue)to check type of a value because type of a mutable value is variable.
-
isNumberValue
boolean isNumberValue()
Returns true if type of this value is Integer or Float.If this method returns true,
asNumberValuenever throws exceptions. Note that you can't useinstanceofor cast((NumberValue) thisValue)to check type of a value because type of a mutable value is variable.
-
isIntegerValue
boolean isIntegerValue()
Returns true if type of this value is Integer.If this method returns true,
asIntegerValuenever throws exceptions. Note that you can't useinstanceofor cast((IntegerValue) thisValue)to check type of a value because type of a mutable value is variable.
-
isFloatValue
boolean isFloatValue()
Returns true if type of this value is Float.If this method returns true,
asFloatValuenever throws exceptions. Note that you can't useinstanceofor cast((FloatValue) thisValue)to check type of a value because type of a mutable value is variable.
-
isRawValue
boolean isRawValue()
Returns true if type of this value is String or Binary.If this method returns true,
asRawValuenever throws exceptions. Note that you can't useinstanceofor cast((RawValue) thisValue)to check type of a value because type of a mutable value is variable.
-
isBinaryValue
boolean isBinaryValue()
Returns true if type of this value is Binary.If this method returns true,
asBinaryValuenever throws exceptions. Note that you can't useinstanceofor cast((BinaryValue) thisValue)to check type of a value because type of a mutable value is variable.
-
isStringValue
boolean isStringValue()
Returns true if type of this value is String.If this method returns true,
asStringValuenever throws exceptions. Note that you can't useinstanceofor cast((StringValue) thisValue)to check type of a value because type of a mutable value is variable.
-
isArrayValue
boolean isArrayValue()
Returns true if type of this value is Array.If this method returns true,
asArrayValuenever throws exceptions. Note that you can't useinstanceofor cast((ArrayValue) thisValue)to check type of a value because type of a mutable value is variable.
-
isMapValue
boolean isMapValue()
Returns true if type of this value is Map.If this method returns true,
asMapValuenever throws exceptions. Note that you can't useinstanceofor cast((MapValue) thisValue)to check type of a value because type of a mutable value is variable.
-
isExtensionValue
boolean isExtensionValue()
Returns true if type of this an Extension.If this method returns true,
asExtensionValuenever throws exceptions. Note that you can't useinstanceofor cast((ExtensionValue) thisValue)to check type of a value because type of a mutable value is variable.
-
asNilValue
NilValue asNilValue()
Returns the value asNilValue. Otherwise throwsMessageTypeCastException.Note that you can't use
instanceofor cast((NilValue) thisValue)to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException- If type of this value is not Nil.
-
asBooleanValue
BooleanValue asBooleanValue()
Returns the value asBooleanValue. Otherwise throwsMessageTypeCastException.Note that you can't use
instanceofor cast((BooleanValue) thisValue)to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException- If type of this value is not Boolean.
-
asNumberValue
NumberValue asNumberValue()
Returns the value asNumberValue. Otherwise throwsMessageTypeCastException.Note that you can't use
instanceofor cast((NumberValue) thisValue)to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException- If type of this value is not Integer or Float.
-
asIntegerValue
IntegerValue asIntegerValue()
Returns the value asIntegerValue. Otherwise throwsMessageTypeCastException.Note that you can't use
instanceofor cast((IntegerValue) thisValue)to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException- If type of this value is not Integer.
-
asFloatValue
FloatValue asFloatValue()
Returns the value asFloatValue. Otherwise throwsMessageTypeCastException.Note that you can't use
instanceofor cast((FloatValue) thisValue)to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException- If type of this value is not Float.
-
asRawValue
RawValue asRawValue()
Returns the value asRawValue. Otherwise throwsMessageTypeCastException.Note that you can't use
instanceofor cast((RawValue) thisValue)to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException- If type of this value is not Binary or String.
-
asBinaryValue
BinaryValue asBinaryValue()
Returns the value asBinaryValue. Otherwise throwsMessageTypeCastException.Note that you can't use
instanceofor cast((BinaryValue) thisValue)to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException- If type of this value is not Binary.
-
asStringValue
StringValue asStringValue()
Returns the value asStringValue. Otherwise throwsMessageTypeCastException.Note that you can't use
instanceofor cast((StringValue) thisValue)to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException- If type of this value is not String.
-
asArrayValue
ArrayValue asArrayValue()
Returns the value asArrayValue. Otherwise throwsMessageTypeCastException.Note that you can't use
instanceofor cast((ArrayValue) thisValue)to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException- If type of this value is not Array.
-
asMapValue
MapValue asMapValue()
Returns the value asMapValue. Otherwise throwsMessageTypeCastException.Note that you can't use
instanceofor cast((MapValue) thisValue)to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException- If type of this value is not Map.
-
asExtensionValue
ExtensionValue asExtensionValue()
Returns the value asExtensionValue. Otherwise throwsMessageTypeCastException.Note that you can't use
instanceofor cast((ExtensionValue) thisValue)to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException- If type of this value is not an Extension.
-
writeTo
void writeTo(MessagePacker pk) throws java.io.IOException
Serializes the value using the specifiedMessagePacker- Throws:
java.io.IOException- See Also:
MessagePacker
-
equals
boolean equals(java.lang.Object obj)
Compares this value to the specified object.This method returns
trueif type and value are equivalent. If this value isMapValueorArrayValue, this method check equivalence of elements recursively.- Overrides:
equalsin classjava.lang.Object
-
toJson
java.lang.String toJson()
Returns json representation of this Value.Following behavior is not configurable at this release and they might be changed at future releases:
- if a key of MapValue is not string, the key is converted to a string using toString method.
- NaN and Infinity of DoubleValue are converted to null.
- ExtensionValue is converted to a 2-element array where first element is a number and second element is the data encoded in hex.
- BinaryValue is converted to a string using UTF-8 encoding. Invalid byte sequence is replaced with
U+FFFD replacement character. - Invalid UTF-8 byte sequences in StringValue is replaced with
U+FFFD replacement character
-
-