Interface AnyValue<T>
- Type Parameters:
T- the type. SeegetValue()for description of types.
public interface AnyValue<T>
AnyValue mirrors the proto AnyValue
message type, and is used to model any type.
It can be used to represent:
- Primitive values via
of(long),of(String),of(boolean),of(double). - String-keyed maps (i.e. associative arrays, dictionaries) via
of(KeyAnyValue...),of(Map). Note, because map values are typeAnyValue, maps can be nested within other maps. - Arrays (heterogeneous or homogenous) via
of(AnyValue[]). Note, because array values are typeAnyValue, arrays can contain primitives, complex types like maps or arrays, or any combination. - Raw bytes via
of(byte[])
-
Method Summary
Modifier and TypeMethodDescriptionasString()Return a string encoding of thisAnyValue.getType()Returns the type of thisAnyValue.getValue()Returns the value for thisAnyValue.of(boolean value) Returns anAnyValuefor thebooleanvalue.static AnyValue<ByteBuffer>of(byte[] value) Returns anAnyValuefor thebyte[]value.of(double value) Returns anAnyValuefor thedoublevalue.of(long value) Returns anAnyValuefor thelongvalue.static AnyValue<List<KeyAnyValue>>of(KeyAnyValue... value) Returns anAnyValuefor the array ofKeyAnyValuevalues.static AnyValue<List<KeyAnyValue>>
-
Method Details
-
of
-
of
Returns anAnyValuefor thebooleanvalue. -
of
Returns anAnyValuefor thelongvalue. -
of
Returns anAnyValuefor thedoublevalue. -
of
Returns anAnyValuefor thebyte[]value. -
of
-
of
Returns anAnyValuefor the array ofKeyAnyValuevalues.KeyAnyValue.getKey()values should not repeat - duplicates may be dropped. -
of
-
getType
AnyValueType getType()Returns the type of thisAnyValue. Useful for building switch statements. -
getValue
T getValue()Returns the value for thisAnyValue.The return type varies by
getType()as described below:AnyValueType.STRINGreturnsStringAnyValueType.BOOLEANreturnsbooleanAnyValueType.LONGreturnslongAnyValueType.DOUBLEreturnsdoubleAnyValueType.ARRAYreturnsListofAnyValueAnyValueType.KEY_VALUE_LISTreturnsListofKeyAnyValueAnyValueType.BYTESreturns read onlyByteBuffer. SeeByteBuffer.asReadOnlyBuffer().
-
asString
String asString()Return a string encoding of thisAnyValue. This is intended to be a fallback serialized representation in case there is no suitable encoding that can utilizegetType()/getValue()to serialize specific types.
-