- java.lang.Object
-
- org.apache.logging.log4j.spi.NoOpThreadContextMap
-
- All Implemented Interfaces:
ThreadContextMap
public class NoOpThreadContextMap extends Object implements ThreadContextMap
ThreadContextMap
implementation used when either of system properties or istrue
. This implementation does nothing.- Since:
- 2.7
-
-
Constructor Summary
Constructors Constructor Description NoOpThreadContextMap()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears the context.boolean
containsKey(String key)
Determines if the key is in the context.String
get(String key)
Gets the context identified by thekey
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 ornull
if the context map is empty.<V> V
getValue(String key)
Returns the Object value for the specified key, ornull
if the specified key does not exist in this collection.boolean
isEmpty()
Returns true if the Map is empty.void
put(String key, String value)
Puts a context value (theo
parameter) as identified with thekey
parameter into the current thread's context map.void
putAll(Map<String,String> map)
Puts all given context map entries into the current thread's context map.<V> void
putAllValues(Map<String,V> values)
Puts all given key-value pairs into the collection.<V> void
putValue(String key, V value)
Puts the specified key-value pair into the collection.void
remove(String key)
Removes the context identified by thekey
parameter.void
removeAll(Iterable<String> keys)
Removes all given context map keys from the current thread's context map.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.logging.log4j.spi.ThreadContextMap
getReadOnlyContextData
-
-
-
-
Method Detail
-
clear
public void clear()
Description copied from interface:ThreadContextMap
Clears the context.- Specified by:
clear
in interfaceThreadContextMap
-
containsKey
public boolean containsKey(String key)
Description copied from interface:ThreadContextMap
Determines if the key is in the context.- Specified by:
containsKey
in interfaceThreadContextMap
- Parameters:
key
- The key to locate.- Returns:
- True if the key is in the context, false otherwise.
-
get
public String get(String key)
Description copied from interface:ThreadContextMap
Gets the context identified by thekey
parameter.This method has no side effects.
- Specified by:
get
in interfaceThreadContextMap
- Parameters:
key
- The key to locate.- Returns:
- The value associated with the key or null.
-
getCopy
public Map<String,String> getCopy()
Description copied from interface:ThreadContextMap
Gets a non-null
mutable copy of current thread's context Map.- Specified by:
getCopy
in interfaceThreadContextMap
- Returns:
- a mutable copy of the context.
-
getImmutableMapOrNull
public Map<String,String> getImmutableMapOrNull()
Description copied from interface:ThreadContextMap
Returns an immutable view on the context Map ornull
if the context map is empty.- Specified by:
getImmutableMapOrNull
in interfaceThreadContextMap
- Returns:
- an immutable context Map or
null
.
-
isEmpty
public boolean isEmpty()
Description copied from interface:ThreadContextMap
Returns true if the Map is empty.- Specified by:
isEmpty
in interfaceThreadContextMap
- Returns:
- true if the Map is empty, false otherwise.
-
put
public void put(String key, String value)
Description copied from interface:ThreadContextMap
Puts a context value (theo
parameter) as identified with thekey
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.
- Specified by:
put
in interfaceThreadContextMap
- Parameters:
key
- The key name.value
- The key value.
-
remove
public void remove(String key)
Description copied from interface:ThreadContextMap
Removes the context identified by thekey
parameter.- Specified by:
remove
in interfaceThreadContextMap
- Parameters:
key
- The key to remove.
-
putAll
public void putAll(Map<String,String> map)
Description copied from interface:ThreadContextMap
Puts all given context map entries into the current thread's context map.If the current thread does not have a context map it is created as a side effect.
- Specified by:
putAll
in interfaceThreadContextMap
- Parameters:
map
- The map.
-
removeAll
public void removeAll(Iterable<String> keys)
Description copied from interface:ThreadContextMap
Removes all given context map keys from the current thread's context map.If the current thread does not have a context map it is created as a side effect.
- Specified by:
removeAll
in interfaceThreadContextMap
- Parameters:
keys
- The keys.
-
getValue
public <V> V getValue(String key)
Description copied from interface:ThreadContextMap
Returns the Object value for the specified key, ornull
if the specified key does not exist in this collection.- Specified by:
getValue
in interfaceThreadContextMap
- Type Parameters:
V
- The type of the returned value.- Parameters:
key
- the key whose value to return- Returns:
- the value for the specified key or
null
-
putValue
public <V> void putValue(String key, V value)
Description copied from interface:ThreadContextMap
Puts the specified key-value pair into the collection.- Specified by:
putValue
in interfaceThreadContextMap
- Type Parameters:
V
- The type of the stored and returned value.- Parameters:
key
- the key to add or remove. Keys may benull
.value
- the value to add. Values may benull
.
-
putAllValues
public <V> void putAllValues(Map<String,V> values)
Description copied from interface:ThreadContextMap
Puts all given key-value pairs into the collection.- Specified by:
putAllValues
in interfaceThreadContextMap
- Type Parameters:
V
- The type of the value being added.- Parameters:
values
- the map of key-value pairs to add
-
-