T
- The type of the serialization form.public class Dynamic<T> extends DynamicLike<T>
Object
parameters, and enforces the existence of a DynamicOps
instance for the particular serialized form. Dynamic
also provides an interface similar to
DynamicOps
for deserializing the contained value.DynamicOps
ops
Constructor and Description |
---|
Dynamic(DynamicOps<T> ops)
Constructs a new
Dynamic containing the empty value of the given serialized form. |
Dynamic(DynamicOps<T> ops,
T value)
Constructs a new
Dynamic containing the given value of the serialized form. |
Modifier and Type | Method and Description |
---|---|
DataResult<ByteBuffer> |
asByteBufferOpt()
Coerces and returns the wrapped value as a
ByteBuffer in a DataResult . |
DataResult<IntStream> |
asIntStreamOpt()
Coerces and returns the wrapped value as a stream of int values in a
DataResult . |
DataResult<LongStream> |
asLongStreamOpt()
Coerces and returns the wrapped value as a stream of long values in a
DataResult . |
DataResult<Stream<(Dynamic<T>,Dynamic<T>)>> |
asMapOpt()
Coerces and returns the wrapped value as a map of entries in a
DataResult . |
DataResult<Number> |
asNumber()
Coerces and returns the wrapped value as a number in a
DataResult . |
DataResult<Stream<Dynamic<T>>> |
asStreamOpt()
Coerces and returns the wrapped value as a stream of values in a
DataResult . |
DataResult<String> |
asString()
Coerces and returns the wrapped value as a string in a
DataResult . |
<U> U |
cast(DynamicOps<U> ops)
Safely casts this
Dynamic to a more specific type, and returns the contained value. |
<U> Dynamic<U> |
castTyped(DynamicOps<U> ops)
Safely casts this
Dynamic to a more specific type. |
<R> Dynamic<R> |
convert(DynamicOps<R> outOps)
Converts this
Dynamic to an equivalent object of another serialized form. |
static <S,T> T |
convert(DynamicOps<S> inOps,
DynamicOps<T> outOps,
S input)
Converts a raw serialized value from one form to another.
|
<A> DataResult<(A,T)> |
decode(Decoder<? extends A> decoder)
Decodes an object using the given
Decoder , and returns a DataResult containing a pair
of the decoded object and the remaining serialized value. |
boolean |
equals(Object o) |
OptionalDynamic<T> |
get(String key)
If the given key is present in the wrapped value, returns the value associated with it, else returns empty.
|
DataResult<T> |
getElement(String key)
If the given key is present in the wrapped value, returns the value associated with it, else returns empty.
|
DataResult<T> |
getElementGeneric(T key)
If the key represented by the given serialized value is present in the wrapped value, returns the value
associated with it, else returns empty.
|
DataResult<T> |
getGeneric(T key)
If the key represented by the given serialized value is present in the wrapped value, returns the value
associated with it, else returns empty.
|
DataResult<Map<Dynamic<T>,Dynamic<T>>> |
getMapValues()
Partially deserializes the contained value as a map of serialized entries.
|
T |
getValue()
Returns the contained serialized value.
|
int |
hashCode() |
<V> V |
into((? super Dynamic<T>) -> ? extends V action)
Applies the given action to this value and returns a result.
|
Dynamic<T> |
map((? super T) -> ? extends T function)
Transforms the wrapped serialized value using the given mapping function.
|
OptionalDynamic<T> |
merge(Dynamic<?> value)
If this object contains a list, appends the given value to it, otherwise returns an empty
OptionalDynamic . |
OptionalDynamic<T> |
merge(Dynamic<?> key,
Dynamic<?> value)
If this object contains a map, appends the given key-value pair to it, otherwise returns an empty
OptionalDynamic . |
Dynamic<T> |
remove(String key)
Removes the entry associated with the given key in the serialized value.
|
Dynamic<T> |
set(String key,
Dynamic<?> value)
Adds the given entry to the contained serialized value.
|
String |
toString() |
Dynamic<T> |
update(String key,
(Dynamic<?>) -> Dynamic<?> function)
Updates an existing entry in the contained serialized value using the given function.
|
Dynamic<T> |
updateGeneric(T key,
(T) -> T function)
Updates an existing entry in the contained serialized value using the given function.
|
Dynamic<T> |
updateMapValues(((Dynamic<?>,Dynamic<?>)) -> (Dynamic<?>,Dynamic<?>) updater)
Updates every map entry contained within the serialized value using the given updating function.
|
asBoolean, asByte, asByteBuffer, asDouble, asFloat, asInt, asIntStream, asList, asListOpt, asLong, asLongStream, asMap, asMapOpt, asNumber, asShort, asStream, asString, createBoolean, createByte, createByteList, createDouble, createFloat, createInt, createIntList, createList, createLong, createLongList, createMap, createNumeric, createShort, createString, emptyList, emptyMap, getElement, getElementGeneric, getOps, read, readList, readList, readMap, readMap, readMap
public Dynamic(DynamicOps<T> ops)
Dynamic
containing the empty value of the given serialized form.ops
- The DynamicOps
instance for the serialized form.public Dynamic(DynamicOps<T> ops, @Nullable T value)
Dynamic
containing the given value of the serialized form.ops
- The DynamicOps
instance for the serialized form.value
- The value this object should contain. If null, this object will contain the empty value.public T getValue()
public Dynamic<T> map((? super T) -> ? extends T function)
function
- The function to use to transform the value.Dynamic
containing the new value.public <U> Dynamic<U> castTyped(DynamicOps<U> ops)
Dynamic
to a more specific type. This is typically used to
downcast a Dynamic<?>
to a concrete serialized type.U
- The type of the serialized form.ops
- The DynamicOps
instance for the serialized form.Dynamic
, casted to use the serialized form of the argument.IllegalStateException
- If the given DynamicOps
does not equal
the actual DynamicOps
instance used in this object.public <U> U cast(DynamicOps<U> ops)
Dynamic
to a more specific type, and returns the contained value. This method is
equivalent to castTyped(ops).getValue()
.U
- The type of the serialized form.ops
- The DynamicOps
instance for the serialized form.IllegalStateException
- If the given DynamicOps
does not equal
the actual DynamicOps
instance used in this object.castTyped(DynamicOps)
public OptionalDynamic<T> merge(Dynamic<?> value)
OptionalDynamic
.value
- The value to append to the list contained in this object.OptionalDynamic
containing the merged list, or an empty OptionalDynamic
if this value
is not a list.IllegalStateException
- If value
does not use the same serialization form as this object.DynamicOps.mergeToList(Object, Object)
public OptionalDynamic<T> merge(Dynamic<?> key, Dynamic<?> value)
OptionalDynamic
.key
- The key to merge into the map.value
- The value to merge into the map.OptionalDynamic
containing the merged map, or an empty OptionalDynamic
if this
value is not a map.IllegalStateException
- If either key
or value
do not use the same serialization form as this
object.DynamicOps.mergeToMap(Object, Object, Object)
public DataResult<Map<Dynamic<T>,Dynamic<T>>> getMapValues()
DataResult
containing the deserialized map, or an error result if the contained serialized
value is not a map.DynamicOps.getMapValues(Object)
public Dynamic<T> updateMapValues(((Dynamic<?>,Dynamic<?>)) -> (Dynamic<?>,Dynamic<?>) updater)
updater
- A function to transform the existing key-value pair to a new key-value pair.Dynamic
containing the transformed value. If the contained serialized value is not a map,
it is returned unchanged and updater
is not called.public DataResult<Number> asNumber()
DynamicLike
DataResult
.asNumber
in class DynamicLike<T>
DynamicOps.getNumberValue(Object)
public DataResult<String> asString()
DynamicLike
DataResult
.asString
in class DynamicLike<T>
DynamicOps.getStringValue(Object)
public DataResult<Stream<Dynamic<T>>> asStreamOpt()
DynamicLike
DataResult
.asStreamOpt
in class DynamicLike<T>
DynamicOps.getStream(Object)
public DataResult<Stream<(Dynamic<T>,Dynamic<T>)>> asMapOpt()
DynamicLike
DataResult
.asMapOpt
in class DynamicLike<T>
DynamicOps.getMapValues(Object)
public DataResult<ByteBuffer> asByteBufferOpt()
DynamicLike
ByteBuffer
in a DataResult
.asByteBufferOpt
in class DynamicLike<T>
DynamicOps.getByteBuffer(Object)
public DataResult<IntStream> asIntStreamOpt()
DynamicLike
DataResult
.asIntStreamOpt
in class DynamicLike<T>
DynamicOps.getIntStream(Object)
public DataResult<LongStream> asLongStreamOpt()
DynamicLike
DataResult
.asLongStreamOpt
in class DynamicLike<T>
DynamicOps.getLongStream(Object)
public OptionalDynamic<T> get(String key)
DynamicLike
get
in class DynamicLike<T>
key
- The key to search for.OptionalDynamic
.public DataResult<T> getGeneric(T key)
DynamicLike
getGeneric
in class DynamicLike<T>
key
- The key to search for.DataResult
.public Dynamic<T> remove(String key)
key
- The key to remove from the map.Dynamic
containing the transformed serialized value. If the contained serialized value is
not a map, then it is returned unchanged.DynamicOps.remove(Object, String)
public Dynamic<T> set(String key, Dynamic<?> value)
key
- The key to add.value
- The value to add, wrapped in a Dynamic
.Dynamic
containing the transformed serialized value. If the contained serialized value is
not a map, then it is returned unchanged.DynamicOps.set(Object, String, Object)
public Dynamic<T> update(String key, (Dynamic<?>) -> Dynamic<?> function)
key
- The key of the entry to update.function
- A function to produce a new value from the existing value.Dynamic
containing the transformed serialized value. If the contained serialized value is
not a map, then it is returned unchanged.DynamicOps.update(Object, String, Function)
public Dynamic<T> updateGeneric(T key, (T) -> T function)
update(String, Function)
, expect that it operates on raw serialized values rather than wrapped
serialized values.key
- The serialized form of the key of the entry to update.function
- A function to produce a new value from the existing value.Dynamic
containing the transformed serialized value. If the contained serialized value is
not a map, then it is returned unchanged.update(String, Function)
,
DynamicOps.updateGeneric(Object, Object, Function)
public DataResult<T> getElement(String key)
DynamicLike
getElement
in class DynamicLike<T>
key
- The key to search for.DataResult
.DynamicLike.get(String)
public DataResult<T> getElementGeneric(T key)
DynamicLike
getElementGeneric
in class DynamicLike<T>
key
- The key to search for.DataResult
.DynamicLike.getGeneric(Object)
public <R> Dynamic<R> convert(DynamicOps<R> outOps)
Dynamic
to an equivalent object of another serialized form.R
- The type of the new serialized form.outOps
- The DynamicOps
instance representing the new serialized form.Dynamic
containing an equivalent value of the new serialized form.DynamicOps.convertTo(DynamicOps, Object)
public <V> V into((? super Dynamic<T>) -> ? extends V action)
this
.Dynamic
into another type.V
- The result type.action
- The action to perform on this dynamic value.action
.public <A> DataResult<(A,T)> decode(Decoder<? extends A> decoder)
DynamicLike
Decoder
, and returns a DataResult
containing a pair
of the decoded object and the remaining serialized value.decode
in class DynamicLike<T>
A
- The type of the decoded object.decoder
- The decoder to use.DataResult
containing the decoded object and the remaining serialized value.public static <S,T> T convert(DynamicOps<S> inOps, DynamicOps<T> outOps, S input)
Dynamic
value, see convert(DynamicOps)
.S
- The type of the serialized form.T
- The type of the new serialized form.inOps
- The DynamicOps
instance for the existing serialized value.outOps
- The DynamicOps
instance for the new serialized form.input
- The serialized value.input
of the new serialized form.convert(DynamicOps)
,
DynamicOps.convertTo(DynamicOps, Object)