public class DefaultThreadContextMap extends Object implements ThreadContextMap, ReadOnlyStringMap
| Modifier and Type | Field and Description |
|---|---|
static String |
INHERITABLE_MAP
Property name ("isThreadContextMapInheritable" ) for selecting
InheritableThreadLocal (value "true") or plain
ThreadLocal (value is not "true") in the implementation. |
| Constructor and Description |
|---|
DefaultThreadContextMap() |
DefaultThreadContextMap(boolean useMap) |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clears the context.
|
boolean |
containsKey(String key)
Determines if the key is in the context.
|
boolean |
equals(Object obj) |
<V> void |
forEach(BiConsumer<String,? super V> action)
Performs the given action for each key-value pair in this data structure
until all entries have been processed or the action throws an exception.
|
<V,S> void |
forEach(TriConsumer<String,? super V,S> action,
S state)
Performs the given action for each key-value pair in this data structure
until all entries have been processed or the action throws an exception.
|
String |
get(String key)
Gets the context identified by the
key parameter. |
Map<String,String> |
getCopy()
Gets a non-
null mutable copy of current thread's context Map. |
Map<String,String> |
getImmutableMapOrNull()
Returns an immutable view on the context Map or
null if the context map is empty. |
<V> V |
getValue(String key)
Returns the value for the specified key, or
null if the specified key does not exist in this collection. |
int |
hashCode() |
boolean |
isEmpty()
Returns true if the Map is empty.
|
void |
put(String key,
String value)
Puts a context value (the
o parameter) as identified
with the key parameter into the current thread's
context map. |
void |
putAll(Map<String,String> m) |
void |
remove(String key)
Removes the the context identified by the
key
parameter. |
void |
removeAll(Iterable<String> keys) |
int |
size()
Returns the number of key-value pairs in this collection.
|
Map<String,String> |
toMap()
Returns a non-
null mutable Map<String, String> containing a snapshot of this data structure. |
String |
toString() |
public static final String INHERITABLE_MAP
InheritableThreadLocal (value "true") or plain
ThreadLocal (value is not "true") in the implementation.public DefaultThreadContextMap()
public DefaultThreadContextMap(boolean useMap)
public void put(String key, String value)
ThreadContextMapo parameter) as identified
with the key parameter into the current thread's
context map.
If the current thread does not have a context map it is created as a side effect.
put in interface ThreadContextMapkey - The key name.value - The key value.public String get(String key)
ThreadContextMapkey parameter.
This method has no side effects.
get in interface ThreadContextMapkey - The key to locate.public void remove(String key)
ThreadContextMapkey
parameter.remove in interface ThreadContextMapkey - The key to remove.public void clear()
ThreadContextMapclear in interface ThreadContextMappublic Map<String,String> toMap()
ReadOnlyStringMapnull mutable Map<String, String> containing a snapshot of this data structure.toMap in interface ReadOnlyStringMapMap<String, String> form.public boolean containsKey(String key)
ThreadContextMapcontainsKey in interface ThreadContextMapcontainsKey in interface ReadOnlyStringMapkey - The key to locate.public <V> void forEach(BiConsumer<String,? super V> action)
ReadOnlyStringMap
Some implementations may not support structural modifications (adding new elements or removing elements) while
iterating over the contents. In such implementations, attempts to add or remove elements from the
BiConsumer's BiConsumer.accept(Object, Object) accept} method may cause a
ConcurrentModificationException to be thrown.
forEach in interface ReadOnlyStringMapV - type of the value.action - The action to be performed for each key-value pair in this collection.public <V,S> void forEach(TriConsumer<String,? super V,S> action, S state)
ReadOnlyStringMapThe third parameter lets callers pass in a stateful object to be modified with the key-value pairs, so the TriConsumer implementation itself can be stateless and potentially reusable.
Some implementations may not support structural modifications (adding new elements or removing elements) while
iterating over the contents. In such implementations, attempts to add or remove elements from the
TriConsumer's accept method may cause a
ConcurrentModificationException to be thrown.
forEach in interface ReadOnlyStringMapV - type of the value.S - type of the third parameter.action - The action to be performed for each key-value pair in this collection.state - the object to be passed as the third parameter to each invocation on the specified
triconsumer.public <V> V getValue(String key)
ReadOnlyStringMapnull if the specified key does not exist in this collection.getValue in interface ReadOnlyStringMapkey - the key whose value to return.null.public Map<String,String> getCopy()
ThreadContextMapnull mutable copy of current thread's context Map.getCopy in interface ThreadContextMappublic Map<String,String> getImmutableMapOrNull()
ThreadContextMapnull if the context map is empty.getImmutableMapOrNull in interface ThreadContextMapnull.public boolean isEmpty()
ThreadContextMapisEmpty in interface ThreadContextMapisEmpty in interface ReadOnlyStringMappublic int size()
ReadOnlyStringMapsize in interface ReadOnlyStringMapCopyright © 1999-2019 The Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.