public interface Context
Context implementations are thread-safe put(Object, Object) will
usually return a safe new Context object.
Note that contexts are optimized for single key/value storage, and a user might want
to represent his own context instead of using more costly put(java.lang.Object, java.lang.Object).
Past one user key/value pair, the context will use a copy-on-write Context
backed by
a new Map on each put(java.lang.Object, java.lang.Object).
| Modifier and Type | Method and Description |
|---|---|
static Context |
empty()
Return an empty
Context |
default <T> T |
get(Class<T> key)
Resolve a value given a type key within the
Context. |
<T> T |
get(Object key)
Resolve a value given a key within the
Context. |
default <T> T |
getOrDefault(Object key,
T defaultValue)
Resolve a value given a key within the
Context. |
default boolean |
isEmpty()
Return true if
Context is empty. |
Context |
put(Object key,
Object value)
Inject a key/value pair in a new
Context inheriting current state. |
Stream<Map.Entry<Object,Object>> |
stream()
Stream key/value pairs from this
Context |
@Nullable <T> T get(Object key)
Context.T - an unchecked casted generic for fluent typing conveniencekey - a lookup key to resolve the value within the context@Nullable default <T> T get(Class<T> key)
Context.T - an unchecked casted generic for fluent typing conveniencekey - a type key to resolve the value within the context@Nullable default <T> T getOrDefault(Object key, @Nullable T defaultValue)
Context. If unresolved return the
passed default value.key - a lookup key to resolve the value within the contextdefaultValue - a fallback value if key doesn't resolvedefault boolean isEmpty()
Context is empty.Context is empty.