Class DataList.Mut

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

public static final class DataList.Mut extends DataList
A data list which can be modified.

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

  • Nested Class Summary

    Nested classes/interfaces inherited from class space.arim.dazzleconf.backend.DataList

    DataList.Immut, DataList.Mut
  • Constructor Summary

    Constructors
    Constructor
    Description
    Mut()
    Creates
    Mut(int initialCapacity)
    Creates with a capacity hint
    Mut(@NonNull Collection<@NonNull DataEntry> entries)
    Creates from the given elements.
    Mut(@NonNull DataEntry @NonNull ... entries)
    Creates from the given elements.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(@NonNull DataEntry entry)
    Adds the given entry, expanding this list to accommodate
    void
    Clears all data
    void
    forEach(Consumer<? super @NonNull DataEntry> action)
    Runs an action for each element.
    @NonNull DataEntry
    get(int idx)
    Gets the entry at the specified index.
    Gets this data tree as an immutable one.
    @NonNull DataList.Mut
    Gets this data list as a mutable one.
    boolean
    Whether this data list is devoid of elements
    void
    set(int idx, @NonNull DataEntry entry)
    Replaces the element at the given index
    int
    The number of elements in this data tree indicates its size

    Methods inherited from class space.arim.dazzleconf.backend.DataList

    equals, hashCode, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Mut

      public Mut()
      Creates
    • Mut

      public Mut(int initialCapacity)
      Creates with a capacity hint
      Parameters:
      initialCapacity - how many elements are expected to be held
    • Mut

      public Mut(@NonNull DataEntry @NonNull ... entries)
      Creates from the given elements.

      The array is copied to ensure immutability, and each entry is checked that it is not null.

      Parameters:
      entries - the elements, none of which can be null
    • Mut

      public Mut(@NonNull Collection<@NonNull DataEntry> entries)
      Creates from the given elements.

      The collection is copied to ensure immutability, and each entry is checked that it is not null. The encounter order of the collection becomes the order of this list.

      Parameters:
      entries - the elements, none of which can be null
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Description copied from class: DataList
      Whether this data list is devoid of elements
      Specified by:
      isEmpty in class DataList
      Returns:
      true if empty
    • size

      public int size()
      Description copied from class: DataList
      The number of elements in this data tree indicates its size
      Specified by:
      size in class DataList
      Returns:
      the size of this data tree
    • intoImmut

      public @NonNull DataList.Immut intoImmut()
      Description copied from class: DataList
      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 DataList.Immut, then it may be returned without changes.

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

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

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

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

      Specified by:
      intoMut in class DataList
      Returns:
      this list if mutable, or a mutable copy if needed
    • get

      public @NonNull DataEntry get(int idx)
      Description copied from class: DataList
      Gets the entry at the specified index.
      Specified by:
      get in class DataList
      Parameters:
      idx - the index
      Returns:
      the entry
    • forEach

      public void forEach(Consumer<? super @NonNull DataEntry> action)
      Description copied from class: DataList
      Runs an action for each element.
      Specified by:
      forEach in class DataList
      Parameters:
      action - the action
    • add

      public void add(@NonNull DataEntry entry)
      Adds the given entry, expanding this list to accommodate
      Parameters:
      entry - the entry
    • set

      public void set(int idx, @NonNull DataEntry entry)
      Replaces the element at the given index
      Parameters:
      idx - the index
      entry - the entry to place there
      Throws:
      IndexOutOfBoundsException - if the index is out of bounds
    • clear

      public void clear()
      Clears all data