Class DataTree.Mut

java.lang.Object
space.arim.dazzleconf.backend.DataTree
space.arim.dazzleconf.backend.DataTree.Mut
Enclosing class:
DataTree

public static final class DataTree.Mut extends DataTree
A data tree which can be modified.

Note that although the tree itself is mutable, DataTrees and DataLists contained within its entries may or may not be. Thus, the type itself does not guarantee that its values are mutable.

That said, callers are encouraged to maintain the deep mutability of this Mut. They should avoid storing DataTree.Immut or DataList.Immut in it without good reason.

  • Constructor Details

    • Mut

      public Mut()
      Creates
  • Method Details

    • get

      public @Nullable DataEntry get(@NonNull Object key)
      Description copied from class: DataTree
      Gets the entry at the specified key, or null if unset.

      If accessing keys based on method names, it is strongly recommended to use the KeyMapper to map method names to keys. The key mapper is available during both deserialization and serialization.

      Specified by:
      get in class DataTree
      Parameters:
      key - the key
      Returns:
      the entry
    • forEach

      public void forEach(BiConsumer<? super @NonNull Object,? super @NonNull DataEntry> action)
      Description copied from class: DataTree
      Runs an action for each key/value pair.

      Iteration maintains the order with which this data tree was created.

      Specified by:
      forEach in class DataTree
      Parameters:
      action - the action
    • intoImmut

      public @NonNull DataTree.Immut intoImmut()
      Description copied from class: DataTree
      Gets this data tree as an immutable one.

      The data contained within this DataTree is moved to an immutable instance. The old instance may still be used, but the implementation of this method may be optimized for the case that it is not.

      If this instance is already DataTree.Immut, then it may be returned without changes.

      Specified by:
      intoImmut in class DataTree
      Returns:
      an immutable data tree
    • intoMut

      public @NonNull DataTree.Mut intoMut()
      Description copied from class: DataTree
      Gets this data tree as a mutable one.

      If not mutable, the data is copied to a new tree, which will be made deeply mutable. That is, this function will also be called on any DataTrees encountered in this tree's entries, and DataList.intoMut() on any data lists likewise.

      If this instance is already DataTree.Mut, then it may be returned without changes.

      Specified by:
      intoMut in class DataTree
      Returns:
      this tree if mutable, or a mutable copy if needed
    • put

      public @Nullable DataEntry put(@NonNull Object key, @NonNull DataEntry entry)
      Sets the entry at the specified key. Replaces any existing entry at the key
      Parameters:
      key - the key
      entry - the entry
      Returns:
      the previous entry at the key, or null if there is none
      Throws:
      IllegalArgumentException - if the provided key is not a valid canonical type
    • remove

      public void remove(@NonNull Object key)
      Clears any entry at the specified key
      Parameters:
      key - the key
      Throws:
      IllegalArgumentException - if the provided key is not a valid canonical type
    • clear

      public void clear()
      Clears all data
    • copyFrom

      public void copyFrom(@NonNull DataTree source)
      Merges all data in the specified data tree into this one, merging nested sections.

      If existing key/value pairs are shared between this tree and source, they will be overwritten and copied from source. Key/value pairs that are unique to this tree will be retained.

      Merging nested trees and lists

      If this function encounters a key/value pair that is shared between this tree and source, and both values are DataTrees, this function will act recursively and merge the two data trees. An UnsupportedOperationException will be thrown if this is impossible due to the presence of DataTree.Immut.

      Lists are treated differently. If this function encounters a key/value pair that is shared, and both values are lists, this function will overwrite the whole list.

      Parameters:
      source - the tree whose entries to copy into this one
      Throws:
      UnsupportedOperationException - if this tree contains a DataTree.Immut that cannot be mutated