public interface ContextView
Context
is an immutable variant of the same key/value pairs structure which exposes
a write API that returns new instances on each write.
Modifier and Type | Method and Description |
---|---|
default void |
forEach(BiConsumer<Object,Object> action)
Perform the given action for each entry in this
ContextView . |
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 that exists within the
Context , or throw
a NoSuchElementException if the key is not present. |
default <T> T |
getOrDefault(Object key,
T defaultValue)
Resolve a value given a key within the
Context . |
default <T> Optional<T> |
getOrEmpty(Object key)
Resolve a value given a key within the
Context . |
boolean |
hasKey(Object key)
Return true if a particular key resolves to a value within the
Context . |
default boolean |
isEmpty()
Return true if the
Context is empty. |
int |
size()
Return the size of this
Context , the number of immutable key/value pairs stored inside it. |
Stream<Map.Entry<Object,Object>> |
stream()
Stream key/value pairs from this
Context |
<T> T get(Object key)
Context
, or throw
a NoSuchElementException
if the key is not present.T
- an unchecked casted generic for fluent typing conveniencekey
- a lookup key to resolve the value within the contextNoSuchElementException
- when the given key is not presentgetOrDefault(Object, Object)
,
getOrEmpty(Object)
,
hasKey(Object)
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 contextNoSuchElementException
- when the given type key is not presentgetOrDefault(Object, Object)
,
getOrEmpty(Object)
@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 <T> Optional<T> getOrEmpty(Object key)
Context
.key
- a lookup key to resolve the value within the contextOptional
of the value for that key.boolean hasKey(Object key)
Context
.key
- a lookup key to test fordefault boolean isEmpty()
Context
is empty.Context
is empty.int size()
Context
, the number of immutable key/value pairs stored inside it.Context
Stream<Map.Entry<Object,Object>> stream()
Context
Stream
of key/value pairs held by this contextdefault void forEach(BiConsumer<Object,Object> action)
ContextView
. If the action throws an
exception, it is immediately propagated to the caller and the remaining items
will not be processed.action
- The action to be performed for each entryNullPointerException
- if the specified action is null