Package org.apache.logging.log4j.spi
Class DefaultThreadContextStack
java.lang.Object
org.apache.logging.log4j.spi.DefaultThreadContextStack
- All Implemented Interfaces:
Serializable,Iterable<String>,Collection<String>,ThreadContextStack,ThreadContext.ContextStack,StringBuilderFormattable
public class DefaultThreadContextStack
extends Object
implements ThreadContextStack, StringBuilderFormattable
A copy-on-write thread-safe variant of
org.apache.logging.log4j.spi.ThreadContextStack in which all mutative
operations (add, pop, and so on) are implemented by making a fresh copy of the underlying list.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultThreadContextStack(boolean useStack) Deprecated.since 2.24.0 without a replacement. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection<? extends String> strings) asList()Returns all the elements in the stack in a List.voidclear()booleanbooleancontainsAll(Collection<?> objects) copy()Returns a copy of the ContextStack.booleanvoidformatTo(StringBuilder buffer) Writes a text representation of this object into the specifiedStringBuilder, ideally without allocating temporary objects.intgetDepth()Returns the number of elements in the stack.Returns a ContextStack with the same contents as this ContextStack ornull.inthashCode()booleanisEmpty()iterator()peek()Returns the element at the top of the stack without removing it or null if the stack is empty.pop()Returns the element at the top of the stack.voidPushes an element onto the stack.booleanbooleanremoveAll(Collection<?> objects) booleanretainAll(Collection<?> objects) intsize()Object[]toArray()<T> T[]toArray(T[] ts) toString()voidtrim(int depth) Trims elements from the end of the stack.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream
-
Constructor Details
-
DefaultThreadContextStack
public DefaultThreadContextStack() -
DefaultThreadContextStack
Deprecated.since 2.24.0 without a replacement.
-
-
Method Details
-
add
- Specified by:
addin interfaceCollection<String>
-
addAll
- Specified by:
addAllin interfaceCollection<String>
-
asList
Description copied from interface:ThreadContext.ContextStackReturns all the elements in the stack in a List.- Specified by:
asListin interfaceThreadContext.ContextStack- Returns:
- all the elements in the stack in a List.
-
clear
public void clear()- Specified by:
clearin interfaceCollection<String>
-
contains
- Specified by:
containsin interfaceCollection<String>
-
containsAll
- Specified by:
containsAllin interfaceCollection<String>
-
copy
Description copied from interface:ThreadContext.ContextStackReturns a copy of the ContextStack.- Specified by:
copyin interfaceThreadContext.ContextStack- Returns:
- a copy of the ContextStack.
-
equals
- Specified by:
equalsin interfaceCollection<String>- Overrides:
equalsin classObject
-
getDepth
public int getDepth()Description copied from interface:ThreadContext.ContextStackReturns the number of elements in the stack.- Specified by:
getDepthin interfaceThreadContext.ContextStack- Returns:
- the number of elements in the stack.
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<String>- Overrides:
hashCodein classObject
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<String>
-
iterator
-
peek
Description copied from interface:ThreadContext.ContextStackReturns the element at the top of the stack without removing it or null if the stack is empty.- Specified by:
peekin interfaceThreadContext.ContextStack- Returns:
- the element at the top of the stack or null if the stack is empty.
-
pop
Description copied from interface:ThreadContext.ContextStackReturns the element at the top of the stack.- Specified by:
popin interfaceThreadContext.ContextStack- Returns:
- The element at the top of the stack.
-
push
Description copied from interface:ThreadContext.ContextStackPushes an element onto the stack.- Specified by:
pushin interfaceThreadContext.ContextStack- Parameters:
message- The element to add.
-
remove
- Specified by:
removein interfaceCollection<String>
-
removeAll
- Specified by:
removeAllin interfaceCollection<String>
-
retainAll
- Specified by:
retainAllin interfaceCollection<String>
-
size
public int size()- Specified by:
sizein interfaceCollection<String>
-
toArray
- Specified by:
toArrayin interfaceCollection<String>
-
toArray
public <T> T[] toArray(T[] ts) - Specified by:
toArrayin interfaceCollection<String>
-
toString
-
formatTo
Description copied from interface:StringBuilderFormattableWrites a text representation of this object into the specifiedStringBuilder, ideally without allocating temporary objects.- Specified by:
formatToin interfaceStringBuilderFormattable- Parameters:
buffer- the StringBuilder to write into
-
trim
public void trim(int depth) Description copied from interface:ThreadContext.ContextStackTrims elements from the end of the stack.- Specified by:
trimin interfaceThreadContext.ContextStack- Parameters:
depth- The maximum number of items in the stack to keep.
-
getImmutableStackOrNull
Description copied from interface:ThreadContext.ContextStackReturns a ContextStack with the same contents as this ContextStack ornull. Attempts to modify the returned stack may or may not throw an exception, but will not affect the contents of this ContextStack.- Specified by:
getImmutableStackOrNullin interfaceThreadContext.ContextStack- Returns:
- a ContextStack with the same contents as this ContextStack or
null.
-