Class DefaultContextMap
java.lang.Object
io.servicetalk.concurrent.internal.DefaultContextMap
- All Implemented Interfaces:
ContextMap
Default implementation of
ContextMap.
Note: it's not thread-safe!
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.servicetalk.context.api.ContextMap
ContextMap.Key<T> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear the contents of thisContextMap.<T> TcomputeIfAbsent(ContextMap.Key<T> key, Function<ContextMap.Key<T>, T> computeFunction) Computes a new entry for thisContextMapif this map does not already contain thiskeyor is mapped tonull.booleancontainsKey(ContextMap.Key<?> key) Determine if thisContextMapcontains an entry corresponding to thekey.booleancontainsValue(Object value) Determine if thisContextMapcontains an entry with the specifiedvalue.copy()Create an isolated copy of the current map.booleanDetermines if the specified object is equal to thisContextMap.forEach(BiPredicate<ContextMap.Key<?>, Object> consumer) Iterate over the entries contained in thisContextMap.<T> Tget(ContextMap.Key<T> key) Get the value associated with thekey, ornullif no value is associated.<T> TgetOrDefault(ContextMap.Key<T> key, T defaultValue) Get the value associated with thekey, ordefaultValueif no value is associated.inthashCode()Returns the hash code value for thisContextMap.booleanisEmpty()Determine if there are no entries in thisContextMap.<T> Tput(ContextMap.Key<T> key, T value) Put a new entry into thisContextMap.voidputAll(ContextMap map) Put all the entries into thisContextMap.voidputAll(Map<ContextMap.Key<?>, Object> map) Put all the entries into thisContextMap.<T> TputIfAbsent(ContextMap.Key<T> key, T value) Put a new entry into thisContextMapif this map does not already contain thiskeyor is mapped tonull.<T> Tremove(ContextMap.Key<T> key) Remove an entry from thisContextMap, and get the previous value (if one exists).intsize()Determine the number ofContextMap.Key-value pairs in thisContextMap.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface io.servicetalk.context.api.ContextMap
contains, removeAll
-
Constructor Details
-
DefaultContextMap
public DefaultContextMap()Creates a new instance.
-
-
Method Details
-
size
public int size()Description copied from interface:ContextMapDetermine the number ofContextMap.Key-value pairs in thisContextMap.- Specified by:
sizein interfaceContextMap- Returns:
- the number of
ContextMap.Key-value pairs in thisContextMap.
-
isEmpty
public boolean isEmpty()Description copied from interface:ContextMapDetermine if there are no entries in thisContextMap.- Specified by:
isEmptyin interfaceContextMap- Returns:
trueif there are no entries in thisContextMap.
-
containsKey
Description copied from interface:ContextMapDetermine if thisContextMapcontains an entry corresponding to thekey.- Specified by:
containsKeyin interfaceContextMap- Parameters:
key- TheContextMap.Keyto lookup.- Returns:
trueif thisContextMapcontains an entry corresponding to thekey,falseotherwise.
-
containsValue
Description copied from interface:ContextMapDetermine if thisContextMapcontains an entry with the specifiedvalue.- Specified by:
containsValuein interfaceContextMap- Parameters:
value- Thevalueto lookup.- Returns:
trueif thisContextMapcontains one or more entries with the specifiedvalue,falseotherwise.
-
get
Description copied from interface:ContextMapGet the value associated with thekey, ornullif no value is associated.- Specified by:
getin interfaceContextMap- Type Parameters:
T- The anticipated type of object associated with thekey.- Parameters:
key- TheContextMap.Keyto lookup.- Returns:
- The value associated with the
key, ornullif no value is associated.nullcan also indicate the value associated with thekeyisnull(ifnullvalues are supported by the implementation).
-
getOrDefault
Description copied from interface:ContextMapGet the value associated with thekey, ordefaultValueif no value is associated.- Specified by:
getOrDefaultin interfaceContextMap- Type Parameters:
T- The anticipated type of object associated with thekey.- Parameters:
key- TheContextMap.Keyto lookup.defaultValue- The value to return if no value is associated with thekey.- Returns:
- The value associated with the
key(can returnnullifnullvalues are supported by the implementation), ordefaultValueif no value is associated.
-
put
Description copied from interface:ContextMapPut a new entry into thisContextMap.- Specified by:
putin interfaceContextMap- Type Parameters:
T- The type of object associated with thekey.- Parameters:
key- TheContextMap.Keyused to index thevalue.value- The value to put.- Returns:
- The previous value associated with the
key, ornullif there was none.nullcan also indicate the value associated with thekeywasnull(ifnullvalues are supported by the implementation).
-
putIfAbsent
Description copied from interface:ContextMapPut a new entry into thisContextMapif this map does not already contain thiskeyor is mapped tonull.- Specified by:
putIfAbsentin interfaceContextMap- Type Parameters:
T- The type of object associated with thekey.- Parameters:
key- TheContextMap.Keyused to index thevalue.value- The value to put.- Returns:
- The previous value associated with the
key, ornullif there was none.nullcan also indicate the value associated with thekeywasnull(ifnullvalues are supported by the implementation).
-
computeIfAbsent
@Nullable public <T> T computeIfAbsent(ContextMap.Key<T> key, Function<ContextMap.Key<T>, T> computeFunction) Description copied from interface:ContextMapComputes a new entry for thisContextMapif this map does not already contain thiskeyor is mapped tonull.- Specified by:
computeIfAbsentin interfaceContextMap- Type Parameters:
T- The type of object associated with thekey.- Parameters:
key- TheContextMap.Keyused to index a new value.computeFunction- The function to compute a new value. Implementation may invoke this function multiple times if concurrent threads attempt modifying this context map, result is expected to be idempotent.- Returns:
- The current (existing or computed) value associated with the
key, ornullif the computed value isnull.
-
putAll
Description copied from interface:ContextMapPut all the entries into thisContextMap.- Specified by:
putAllin interfaceContextMap- Parameters:
map- The entries to insert into thisContextMap.
-
putAll
Description copied from interface:ContextMapPut all the entries into thisContextMap.- Specified by:
putAllin interfaceContextMap- Parameters:
map- The entries to insert into thisContextMap.
-
remove
Description copied from interface:ContextMapRemove an entry from thisContextMap, and get the previous value (if one exists).- Specified by:
removein interfaceContextMap- Type Parameters:
T- The type of object associated with thekey.- Parameters:
key- TheContextMap.Keywhich identifies an entry for removal.- Returns:
- The previous value associated with the
key, ornullif there was none.nullcan also indicate the value associated with thekeywasnull(ifnullvalues are supported by the implementation). If theContextMapimplementation is immutable this may be a new object.
-
clear
public void clear()Description copied from interface:ContextMapClear the contents of thisContextMap.- Specified by:
clearin interfaceContextMap
-
forEach
Description copied from interface:ContextMapIterate over the entries contained in thisContextMap.- Specified by:
forEachin interfaceContextMap- Parameters:
consumer- Each entry will be passed as key and value arguments to thisBiPredicate. A consumer predicate should returntrueif it wants to keep iterating orfalseto stop iteration at the current entry.- Returns:
nullifconsumeriterated through all entries or theContextMap.Keyat which the iteration stopped.
-
copy
Description copied from interface:ContextMapCreate an isolated copy of the current map. The return value contents are the same as thisContextMapbut modifications to thisContextMapare not visible in the return value, and visa-versa.- Specified by:
copyin interfaceContextMap- Returns:
- an isolated copy of the current map. The contents are the same as this
ContextMapbut modifications to thisContextMapare not visible in the return value, and visa-versa.
-
hashCode
public int hashCode()Description copied from interface:ContextMapReturns the hash code value for thisContextMap.- Specified by:
hashCodein interfaceContextMap- Overrides:
hashCodein classObject- Returns:
- the hash code value for this
ContextMap, taking into account the hash codes of each key-value mapping entries thisContextMapcontains. - See Also:
-
equals
Description copied from interface:ContextMapDetermines if the specified object is equal to thisContextMap.- Specified by:
equalsin interfaceContextMap- Overrides:
equalsin classObject- Parameters:
o- object to be compared for equality with thisContextMap.- Returns:
trueif the passed object is aContextMapand has the same key-value mapping entries.- See Also:
-
toString
-