Package dev.enola.common.context
Class Context
java.lang.Object
dev.enola.common.context.Context
- All Implemented Interfaces:
AutoCloseable
Contexts đŸ§¿ put things into perspective!
Contexts are "hierarchical", and child contexts "mask" keys in their parent.
This class is NOT thread safe. Might you want to use TLC instead?
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close this context.<T> TGets the instance of Class, from this or its parent context.<K extends Enum<K> & Context.Key<T>,T>
Tget(K key) Get the value for the given key, from this or its parent context.<T> Optional<T> Gets the instance of Class, from this or its parent context, if available.<T,K extends Enum<K> & Context.Key<T>>
Optional<T> optional(K key) Get the value for the given key, from this or its parent context, if available.<T> voidpush(Context.Key<T> key, T instance) <T> Context<K extends Enum<K> & Context.Key<T>,T>
Contextpush(K key, T value) Push, but not too hard…toString()
-
Constructor Details
-
Context
-
Context
public Context()
-
-
Method Details
-
push
Push, but not too hard…- Parameters:
key- Key.value- Value to associate with the key.- Returns:
- this, for chaining.
- Throws:
IllegalStateException- if this Context already has another value for the key.
-
push
-
push
-
get
Get the value for the given key, from this or its parent context.Never null, but may throw IllegalStateException if not available.
Use
optional(Enum)to check if key is available in Context. -
get
Gets the instance of Class, from this or its parent context.Never null, but may throw IllegalStateException if not available.
Use
optional(Class)to check if key is available in Context. -
optional
Gets the instance of Class, from this or its parent context, if available.Use
get(Class)if key must be available in Context. -
optional
Get the value for the given key, from this or its parent context, if available.Use
get(Enum)if key must be available in Context. -
toString
-
close
Close this context. Don't use it anymore!- Specified by:
closein interfaceAutoCloseable
-