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
Creates an empty map value.- Returns:
- an empty serialized map
-
emptyList
Creates an empty list value.- Returns:
- an empty serialized list
-
createString
Creates a serialized string value.- Parameters:
value- the string to serialize- Returns:
- the serialized string
-
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
Creates a serialized list.- Parameters:
elements- the serialized list elements- Returns:
- the serialized list
-
createMap
Creates a serialized map.- Parameters:
map- the serialized key-value pairs- Returns:
- the serialized map
-
getStringValue
Attempts to read a string value.- Parameters:
input- the serialized value- Returns:
- the decoded string, if present
-
getNumberValue
Attempts to read a numeric value.- Parameters:
input- the serialized value- Returns:
- the decoded number, if present
-
getIntValue
Attempts to read an integer value.- Parameters:
input- the serialized value- Returns:
- the decoded integer, if present
-
getLongValue
Attempts to read a long value.- Parameters:
input- the serialized value- Returns:
- the decoded long, if present
-
getFloatValue
Attempts to read a float value.- Parameters:
input- the serialized value- Returns:
- the decoded float, if present
-
getDoubleValue
Attempts to read a double value.- Parameters:
input- the serialized value- Returns:
- the decoded double, if present
-
getBooleanValue
Attempts to read a boolean value.- Parameters:
input- the serialized value- Returns:
- the decoded boolean, if present
-
getList
Attempts to read a list value.- Parameters:
input- the serialized value- Returns:
- the decoded list, if the value is a list
-
getMap
Attempts to read a map value.- Parameters:
input- the serialized value- Returns:
- the decoded map, if the value is a map
-
getKeys
Returns the string keys contained in a map value.- Parameters:
input- the serialized value- Returns:
- the map keys, if the value is a map
-
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
Creates a deep copy of the specified serialized value.- Parameters:
input- the value to copy- Returns:
- a copy that is independent of the original
-
mergeToList
Appends a value to a serialized list.If the supplied value is not already a list, a new list containing both the original value and the appended value is created.
- Parameters:
list- the target list valuevalue- the value to append- Returns:
- the resulting list
-
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
Determines whether a value exists at the specified path.- Parameters:
input- the root valuepath- the path to check- Returns:
trueif a value exists at the path
-
exists
Determines whether a value exists at the specified path.- Parameters:
input- the root valuepath- the compiled path to check- Returns:
trueif a value exists at the path
-
query
Retrieves a nested value using a path expression.- Parameters:
input- the root valuepath- the path expression- Returns:
- the value at the path, if present
-
query
Retrieves a nested value using a compiled path.- Parameters:
input- the root valuepath- the compiled path- Returns:
- the value at the path, if present
-
set
Sets a value at the specified path, creating intermediate containers as needed.- Parameters:
input- the root valuepath- the path expressionvalue- the value to store- Returns:
- the updated root value
-
set
Sets a value at the specified path, creating intermediate containers as needed.- Parameters:
input- the root valuepath- the compiled pathvalue- the value to store- 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 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
Removes the value located at the specified path.- Parameters:
input- the root valuepath- the path expression- Returns:
- the updated root value
-
remove
Removes the value located at the specified path.- Parameters:
input- the root valuepath- the compiled path- Returns:
- the updated root value
-
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
-