Class SupplierDataContainer
java.lang.Object
com.djrapitops.plan.delivery.domain.container.SupplierDataContainer
- All Implemented Interfaces:
DataContainer
DataContainer implementation that stores everything in
Supplier objects.-
Constructor Summary
ConstructorsConstructorDescriptionCreate a SupplierDataContainer with a default TTL of 30 seconds.SupplierDataContainer(long timeToLive) Create a SupplierDataContainer with a custom TTL. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear the container of all data.getMap()Return a Key - Value Map of the data in the container.<T> TGet data identified by the Key, or throw an exception.<T> Optional<T> Get an Optional of the Value identified by the Key.voidputAll(DataContainer dataContainer) Place all values from given DataContainer into this container.<T> voidputCachingSupplier(Key<T> key, Supplier<T> supplier) Place a caching data supplier inside the container.<T> voidputRawData(Key<T> key, T obj) Place your data inside the container.<T> voidputSupplier(Key<T> key, Supplier<T> supplier) Place a data supplier inside the container.<T> booleanCheck if a Value with the given Key has been placed into the container.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.djrapitops.plan.delivery.domain.container.DataContainer
getFormatted, getFormattedUnsafe, handleList, handleMap, mapToNormalMap
-
Constructor Details
-
SupplierDataContainer
public SupplierDataContainer()Create a SupplierDataContainer with a default TTL of 30 seconds. -
SupplierDataContainer
public SupplierDataContainer(long timeToLive) Create a SupplierDataContainer with a custom TTL.The old value is not removed from memory until the supplier is called again.
- Parameters:
timeToLive- TTL that determines how long a CachingSupplier value is deemed valid.
-
-
Method Details
-
putRawData
Description copied from interface:DataContainerPlace your data inside the container.What the container does with the object depends on the implementation.
- Specified by:
putRawDatain interfaceDataContainer- Type Parameters:
T- Type of the object- Parameters:
key- Key of type T that identifies the data and will be used later when the data needs to be fetched.obj- object to store
-
putSupplier
Description copied from interface:DataContainerPlace a data supplier inside the container.What the container does with the supplier depends on the implementation.
- Specified by:
putSupplierin interfaceDataContainer- Type Parameters:
T- Type of the object- Parameters:
key- Key of type T that identifies the data and will be used later when the data needs to be fetched.supplier- Supplier to store
-
putCachingSupplier
Description copied from interface:DataContainerPlace a caching data supplier inside the container.If the supplier is called the value is cached according to the implementation of the container. What the container does with the supplier depends on the implementation.
- Specified by:
putCachingSupplierin interfaceDataContainer- Type Parameters:
T- Type of the object- Parameters:
key- Key of type T that identifies the data and will be used later when the data needs to be fetched.supplier- Supplier to store
-
supports
Description copied from interface:DataContainerCheck if a Value with the given Key has been placed into the container.- Specified by:
supportsin interfaceDataContainer- Type Parameters:
T- Type of the object returned by the Value if it is present.- Parameters:
key- Key that identifies the data.- Returns:
- true if found, false if not.
-
getValue
Description copied from interface:DataContainerGet an Optional of the Value identified by the Key.It is recommended to check if the Optional is present as null values will be empty.
- Specified by:
getValuein interfaceDataContainer- Type Parameters:
T- Type of the object returned by Value- Parameters:
key- Key that identifies the Value- Returns:
- Optional of the object if the key is registered and key matches the type of the object. Otherwise empty.
-
getUnsafe
Description copied from interface:DataContainerGet data identified by the Key, or throw an exception.It is recommended to use
DataContainer.supports(Key)before using this method.- Specified by:
getUnsafein interfaceDataContainer- Type Parameters:
T- Type of the object returned by Value- Parameters:
key- Key that identifies the Value- Returns:
- the value
-
putAll
Description copied from interface:DataContainerPlace all values from given DataContainer into this container.- Specified by:
putAllin interfaceDataContainer- Parameters:
dataContainer- Container with values.
-
clear
public void clear()Description copied from interface:DataContainerClear the container of all data.- Specified by:
clearin interfaceDataContainer
-
getMap
Description copied from interface:DataContainerReturn a Key - Value Map of the data in the container.This method may call blocking methods if underlying implementation uses the given Suppliers.
- Specified by:
getMapin interfaceDataContainer- Returns:
- Map: Key - Object
-