Class ContextDataHolder
java.lang.Object
io.github.somesourcecode.someguiapi.scene.data.ContextDataHolder
A container for context data. It is used to register, store and retrieve context data.
The data is represented by
ContextData objects and can be accessed by their id.- Since:
- 2.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionContextData<?>Returns the context data with the given id.<T> ContextData<T>Returns the context data with the given id and an unchecked data type.Optional<ContextData<?>>Returns the context data with the given id as an optional.register(ContextData<?> data) Registers the given context data.Registers a new context data with the given id, class and data.Registers a new context data with the given id, class and data.unregister(String id) Unregisters the context data with the given id.Unregisters all context data.
-
Constructor Details
-
ContextDataHolder
public ContextDataHolder()
-
-
Method Details
-
register
Registers the given context data.If the id is already registered, this method will fail silently.
- Parameters:
data- the data to register- Returns:
- the holder for method chaining
- Since:
- 2.0.0
-
register
Registers a new context data with the given id, class and data. This method is a shorthand forregister(ContextData).If the id is already registered, this method will fail silently.
- Type Parameters:
T- the type of data- Parameters:
id- the id of the datatype- the type of the data- Returns:
- the holder for method chaining
- Since:
- 2.0.0
-
register
Registers a new context data with the given id, class and data. This method is a shorthand forregister(ContextData).If the id is already registered, this method will fail silently.
- Type Parameters:
T- the type of the data- Parameters:
id- the id of the datatype- the type of the datadata- the initial data- Returns:
- the holder for method chaining
- Since:
- 2.0.0
-
getData
Returns the context data with the given id.- Parameters:
id- the id of the data- Returns:
- the data with the given id, or null if no data with the given id is registered
- Since:
- 2.0.0
-
getDataUnchecked
Returns the context data with the given id and an unchecked data type. This is useful if the type of the data is known.- Type Parameters:
T- the type the data is cast to- Parameters:
id- the id of the data- Returns:
- the data with the given id
- Throws:
ClassCastException- if the data is not of the correct type- Since:
- 2.0.0
-
getOptionalData
Returns the context data with the given id as an optional.- Parameters:
id- the id of the data- Returns:
- the data with the given id as an optional
- Since:
- 2.0.0
-
unregister
Unregisters the context data with the given id.- Parameters:
id- the id of the data- Returns:
- the holder for method chaining
- Since:
- 2.0.0
-
unregisterAll
Unregisters all context data.- Returns:
- the holder for method chaining
- Since:
- 2.0.0
-