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
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAdds objects to the storage.voidAdds an object to the storage by the given index.<V extends T>
VgetByClass(Class<V> clazz) Gets an object from the storage by the given class type.getList()abstract voidinit()Initializes the storage.voidInserts an object to the storage by the given index.final voidRemoves objects from the storage.voidremoveBy(int index) Removes an object from the storage by the given index.voidsetAddConsumer(Consumer<T> addConsumer) voidsetRemoveConsumer(Consumer<T> removeConsumer)
-
Constructor Details
-
Storage
public Storage()Creates a new storage with aCopyOnWriteArrayList. -
Storage
Creates a new storage with the given list.- Parameters:
list- The list.
-
-
Method Details
-
init
public abstract void init()Initializes the storage. -
add
Adds objects to the storage.- Parameters:
t- The objects.
-
remove
Removes objects from the storage.- Parameters:
t- The objects.
-
addBy
Adds an object to the storage by the given index.- Parameters:
t- The object.index- The index.
-
insert
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
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
-
setAddConsumer
-
setRemoveConsumer
-