Class DynamicOps<T>
- Type Parameters:
T- the serialized value type used by the format
Implementations define how primitive values, lists, and maps are represented
in a particular serialization format such as JSON, YAML, NBT, or binary data.
This abstraction allows Codec implementations to operate independently
of the underlying serialized representation.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanIndicates whether this format prefers compressed map representations.<R> RconvertTo(DynamicOps<R> outOps, T input) Converts a serialized value from this format into another format.abstract TCreates a deep copy of the specified serialized value.abstract TcreateBoolean(boolean value) Creates a serialized boolean value.abstract TcreateByte(byte value) Creates a serialized byte value.abstract TcreateDouble(double value) Creates a serialized double value.abstract TcreateFloat(float value) Creates a serialized float value.abstract TcreateInt(int value) Creates a serialized integer value.abstract TcreateList(List<T> elements) Creates a serialized list.abstract TcreateLong(long value) Creates a serialized long value.abstract TCreates a serialized map.abstract TcreateShort(short value) Creates a serialized short value.abstract TcreateString(String value) Creates a serialized string value.Applies a transformation to the value located at the specified path.Applies a transformation to the value located at the specified path.abstract Tempty()Returns the format-specific representation of an empty value.Creates an empty list value.emptyMap()Creates an empty map value.booleanDetermines whether a value exists at the specified path.booleanDetermines whether a value exists at the specified path.getBooleanValue(T input) Attempts to read a boolean value.getDoubleValue(T input) Attempts to read a double value.getFloatValue(T input) Attempts to read a float value.getIntValue(T input) Attempts to read an integer value.Returns the string keys contained in a map value.Attempts to read a list value.getLongValue(T input) Attempts to read a long value.Attempts to read a map value.getNumberValue(T input) Attempts to read a numeric value.getStringValue(T input) Attempts to read a string value.mergeToList(T list, T value) Appends a value to a serialized list.mergeToMap(T map, T key, T value) Inserts or replaces an entry in a serialized map.Retrieves a nested value using a compiled path.Retrieves a nested value using a path expression.Removes the value located at the specified path.Removes the value located at the specified path.Sets a value at the specified path, creating intermediate containers as needed.Sets a value at the specified path, creating intermediate containers as needed.abstract OptionalIntReturns the number of elements contained in a list or map value.
-
Constructor Details
-
DynamicOps
public DynamicOps()
-
-
Method Details
-
compressMaps
public boolean compressMaps()Indicates whether this format prefers compressed map representations.- Returns:
trueif compressed map encoding should be used, otherwisefalse
-
empty
Returns the format-specific representation of an empty value.- Returns:
- the empty value representation
-
emptyMap
-
emptyList
-
createString
-
createByte
Creates a serialized byte value.- Parameters:
value- the byte to serialize- Returns:
- the serialized byte
-
createShort
Creates a serialized short value.- Parameters:
value- the short to serialize- Returns:
- the serialized short
-
createInt
Creates a serialized integer value.- Parameters:
value- the integer to serialize- Returns:
- the serialized integer
-
createLong
Creates a serialized long value.- Parameters:
value- the long to serialize- Returns:
- the serialized long
-
createFloat
Creates a serialized float value.- Parameters:
value- the float to serialize- Returns:
- the serialized float
-
createDouble
Creates a serialized double value.- Parameters:
value- the double to serialize- Returns:
- the serialized double
-
createBoolean
Creates a serialized boolean value.- Parameters:
value- the boolean to serialize- Returns:
- the serialized boolean
-
createList
-
createMap
-
getStringValue
-
getNumberValue
-
getIntValue
-
getLongValue
-
getFloatValue
-
getDoubleValue
-
getBooleanValue
-
getList
-
getMap
-
getKeys
-
size
Returns the number of elements contained in a list or map value.- Parameters:
input- the serialized value- Returns:
- the collection size, if applicable
-
copy
-
mergeToList
-
mergeToMap
Inserts or replaces an entry in a serialized map.If the supplied value is not already a map, a new map containing only the provided key-value pair is created.
- Parameters:
map- the target map valuekey- the entry keyvalue- the entry value- Returns:
- the resulting map
-
exists
-
exists
-
query
-
query
-
set
-
set
-
edit
Applies a transformation to the value located at the specified path.Missing intermediate containers are created as needed. The operation follows copy-on-write semantics and returns a new root value containing the modification.
- Parameters:
input- the root valuepath- the path expressioneditor- the function used to transform the target value- Returns:
- the updated root value
-
edit
Applies a transformation to the value located at the specified path.Missing intermediate containers are created as needed. The operation follows copy-on-write semantics and returns a new root value containing the modification.
- Parameters:
input- the root valuepath- the compiled patheditor- the function used to transform the target value- Returns:
- the updated root value
-
remove
-
remove
-
convertTo
Converts a serialized value from this format into another format.Primitive values, lists, and maps are recursively translated using the target
DynamicOpsimplementation.- Type Parameters:
R- the target serialized value type- Parameters:
outOps- the target operations implementationinput- the value to convert- Returns:
- the converted value
-