Class Storage<T>

java.lang.Object
de.florianmichael.rclasses.pattern.storage.Storage<T>
Type Parameters:
T - The type of the storage.
Direct Known Subclasses:
NamedStorage

public abstract class Storage<T> extends Object
Implementation of a storage. A storage is a list of objects. It can be used to store objects of a specific type. The storage can be initialized, and it can be added and removed objects. It also supports consumers for adding and removing objects. The storage is thread-safe. The storage is abstract and must be implemented. The storage can be initialized by calling the init() method. The storage can be added and removed objects by calling the add(Object...) and remove(Object...) methods.
  • Constructor Details

    • Storage

      public Storage()
      Creates a new storage with a CopyOnWriteArrayList.
    • Storage

      public Storage(Supplier<List<T>> list)
      Creates a new storage with the given list.
      Parameters:
      list - The list.
  • Method Details

    • init

      public abstract void init()
      Initializes the storage.
    • add

      @SafeVarargs public final void add(T... t)
      Adds objects to the storage.
      Parameters:
      t - The objects.
    • remove

      @SafeVarargs public final void remove(T... t)
      Removes objects from the storage.
      Parameters:
      t - The objects.
    • addBy

      public void addBy(T t, int index)
      Adds an object to the storage by the given index.
      Parameters:
      t - The object.
      index - The index.
    • insert

      public void insert(T t, int index)
      Inserts an object to the storage by the given index.
      Parameters:
      t - The object.
      index - The index.
    • removeBy

      public void removeBy(int index)
      Removes an object from the storage by the given index.
      Parameters:
      index - The index.
    • getByClass

      public <V extends T> V getByClass(Class<V> clazz)
      Gets an object from the storage by the given class type.
      Type Parameters:
      V - The type of the object.
      Parameters:
      clazz - The class.
      Returns:
      The object.
    • getList

      public List<T> getList()
    • setAddConsumer

      public void setAddConsumer(Consumer<T> addConsumer)
    • setRemoveConsumer

      public void setRemoveConsumer(Consumer<T> removeConsumer)