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.
限定符和类型 | 方法和说明 |
---|---|
default void |
forEach(java.util.function.BiConsumer<java.lang.Object,java.lang.Object> action)
Perform the given action for each entry in this
ContextView . |
default <T> T |
get(java.lang.Class<T> key)
Resolve a value given a type key within the
Context . |
<T> T |
get(java.lang.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(java.lang.Object key,
T defaultValue)
Resolve a value given a key within the
Context . |
default <T> java.util.Optional<T> |
getOrEmpty(java.lang.Object key)
Resolve a value given a key within the
Context . |
boolean |
hasKey(java.lang.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. |
java.util.stream.Stream<java.util.Map.Entry<java.lang.Object,java.lang.Object>> |
stream()
Stream key/value pairs from this
Context |
<T> T get(java.lang.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 contextjava.util.NoSuchElementException
- when the given key is not presentgetOrDefault(Object, Object)
,
getOrEmpty(Object)
,
hasKey(Object)
default <T> T get(java.lang.Class<T> key)
Context
.T
- an unchecked casted generic for fluent typing conveniencekey
- a type key to resolve the value within the contextjava.util.NoSuchElementException
- when the given type key is not presentgetOrDefault(Object, Object)
,
getOrEmpty(Object)
@Nullable default <T> T getOrDefault(java.lang.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> java.util.Optional<T> getOrEmpty(java.lang.Object key)
Context
.key
- a lookup key to resolve the value within the contextOptional
of the value for that key.boolean hasKey(java.lang.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
java.util.stream.Stream<java.util.Map.Entry<java.lang.Object,java.lang.Object>> stream()
Context
Stream
of key/value pairs held by this contextdefault void forEach(java.util.function.BiConsumer<java.lang.Object,java.lang.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 entryjava.lang.NullPointerException
- if the specified action is null