Record Class Dynamic<T>

java.lang.Object
java.lang.Record
com.github.darksoulq.abyssallib.common.serialization.Dynamic<T>
Type Parameters:
T - the serialized value type

public record Dynamic<T>(DynamicOps<T> ops, T value) extends Record
A wrapper around a serialized value and its associated DynamicOps implementation.

This class provides a fluent API for querying, modifying, and converting dynamic data structures without repeatedly passing the operations instance.

  • Constructor Details

    • Dynamic

      public Dynamic(DynamicOps<T> ops, T value)
      Creates a new dynamic wrapper.
      Parameters:
      ops - the operations implementation associated with the value
      value - the wrapped serialized value
  • Method Details

    • ops

      public DynamicOps<T> ops()
      Returns the operations implementation associated with this value.
      Returns:
      the operations implementation
    • value

      public T value()
      Returns the wrapped serialized value.
      Returns:
      the wrapped value
    • get

      public Optional<Dynamic<T>> get(String path)
      Retrieves a nested value using a path expression.
      Parameters:
      path - the path expression to resolve
      Returns:
      the nested value wrapped as a Dynamic, if present
    • get

      public Optional<Dynamic<T>> get(DataPath path)
      Retrieves a nested value using a compiled path.
      Parameters:
      path - the compiled path to resolve
      Returns:
      the nested value wrapped as a Dynamic, if present
    • set

      public Dynamic<T> set(String path, T value)
      Sets a value at the specified path.
      Parameters:
      path - the destination path
      value - the value to store
      Returns:
      a new dynamic instance containing the updated structure
    • set

      public Dynamic<T> set(String path, Dynamic<T> dynamic)
      Sets a value at the specified path using another dynamic wrapper.
      Parameters:
      path - the destination path
      dynamic - the dynamic containing the value to store
      Returns:
      a new dynamic instance containing the updated structure
    • edit

      public Dynamic<T> edit(String path, Function<T,T> editor)
      Applies a transformation to the value located at the specified path.
      Parameters:
      path - the target path
      editor - the function used to transform the value
      Returns:
      a new dynamic instance containing the updated structure
    • remove

      public Dynamic<T> remove(String path)
      Removes the value located at the specified path.
      Parameters:
      path - the path of the value to remove
      Returns:
      a new dynamic instance containing the updated structure
    • convert

      public <R> Dynamic<R> convert(DynamicOps<R> outOps)
      Converts the wrapped value to a different serialized format.
      Type Parameters:
      R - the target serialized value type
      Parameters:
      outOps - the target operations implementation
      Returns:
      a dynamic wrapper containing the converted value
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.