public interface DataContainer
Key
objects.
Implementations should mainly be concerned on how the data given to it is stored. Retrieval has some details that should be followed.
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear the container of all data.
|
default <T> java.lang.String |
getFormatted(Key<T> key,
Formatter<java.util.Optional<T>> formatter)
Get formatted Value identified by the Key.
|
default <T> java.lang.String |
getFormattedUnsafe(Key<T> key,
Formatter<T> formatter)
Get formatted Value identified by the Key, or throw an exception.
|
java.util.Map<Key,java.lang.Object> |
getMap()
Return a Key - Value Map of the data in the container.
|
<T> T |
getUnsafe(Key<T> key)
Get data identified by the Key, or throw an exception.
|
<T> java.util.Optional<T> |
getValue(Key<T> key)
Get an Optional of the Value identified by the Key.
|
default java.util.List<?> |
handleList(java.util.List<?> list) |
default java.util.Map<?,?> |
handleMap(java.util.Map<?,?> map) |
default java.util.Map<java.lang.String,java.lang.Object> |
mapToNormalMap() |
void |
putAll(DataContainer dataContainer)
Place all values from given DataContainer into this container.
|
<T> void |
putCachingSupplier(Key<T> key,
java.util.function.Supplier<T> supplier)
Place a caching data supplier inside the container.
|
<T> void |
putRawData(Key<T> key,
T obj)
Place your data inside the container.
|
<T> void |
putSupplier(Key<T> key,
java.util.function.Supplier<T> supplier)
Place a data supplier inside the container.
|
<T> boolean |
supports(Key<T> key)
Check if a Value with the given Key has been placed into the container.
|
default java.util.Map<java.lang.String,java.lang.Object> mapToNormalMap()
default java.util.List<?> handleList(java.util.List<?> list)
default java.util.Map<?,?> handleMap(java.util.Map<?,?> map)
<T> void putRawData(Key<T> key, T obj)
What the container does with the object depends on the implementation.
T
- Type of the objectkey
- Key of type T that identifies the data and will be used later when the data needs to be fetched.obj
- object to store<T> void putSupplier(Key<T> key, java.util.function.Supplier<T> supplier)
What the container does with the supplier depends on the implementation.
T
- Type of the objectkey
- Key of type T that identifies the data and will be used later when the data needs to be fetched.supplier
- Supplier to store<T> void putCachingSupplier(Key<T> key, java.util.function.Supplier<T> supplier)
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.
T
- Type of the objectkey
- Key of type T that identifies the data and will be used later when the data needs to be fetched.supplier
- Supplier to store<T> boolean supports(Key<T> key)
T
- Type of the object returned by the Value if it is present.key
- Key that identifies the data.<T> java.util.Optional<T> getValue(Key<T> key)
It is recommended to check if the Optional is present as null values will be empty.
T
- Type of the object returned by Valuekey
- Key that identifies the Value<T> T getUnsafe(Key<T> key)
It is recommended to use supports(Key)
before using this method.
T
- Type of the object returned by Valuekey
- Key that identifies the Valuejava.lang.IllegalArgumentException
- If the key is not supported.default <T> java.lang.String getFormatted(Key<T> key, Formatter<java.util.Optional<T>> formatter)
T
- Type of the object returned by Valuekey
- Key that identifies the Valueformatter
- Formatter for the Optional returned by getValue(Key)
default <T> java.lang.String getFormattedUnsafe(Key<T> key, Formatter<T> formatter)
It is recommended to use supports(Key)
before using this method.
T
- Type of the object returned by Valuekey
- Key that identifies the Valueformatter
- Formatter for the valuejava.lang.IllegalArgumentException
- If the key is not supported.void putAll(DataContainer dataContainer)
dataContainer
- Container with values.void clear()
java.util.Map<Key,java.lang.Object> getMap()
This method may call blocking methods if underlying implementation uses the given Suppliers.