Package org.apache.logging.log4j.spi
Class MutableThreadContextStack
java.lang.Object
org.apache.logging.log4j.spi.MutableThreadContextStack
- All Implemented Interfaces:
Serializable
,Iterable<String>
,Collection<String>
,ThreadContextStack
,ThreadContext.ContextStack
,StringBuilderFormattable
public class MutableThreadContextStack
extends Object
implements ThreadContextStack, StringBuilderFormattable
TODO
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty MutableThreadContextStack.MutableThreadContextStack
(List<String> list) Constructs a new instance. -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends String> strings) asList()
Returns all the elements in the stack in a List.void
clear()
boolean
boolean
containsAll
(Collection<?> objects) copy()
Returns a copy of the ContextStack.boolean
void
formatTo
(StringBuilder buffer) Writes a text representation of this object into the specifiedStringBuilder
, ideally without allocating temporary objects.void
freeze()
"Freezes" this context stack so it becomes immutable: all mutator methods will throw an exception from now on.int
getDepth()
Returns the number of elements in the stack.Returns a ContextStack with the same contents as this ContextStack ornull
.int
hashCode()
boolean
isEmpty()
boolean
isFrozen()
Returns whether this context stack is frozen.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.void
Pushes an element onto the stack.boolean
boolean
removeAll
(Collection<?> objects) boolean
retainAll
(Collection<?> objects) int
size()
Object[]
toArray()
<T> T[]
toArray
(T[] ts) toString()
void
trim
(int depth) Trims elements from the end of the stack.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream
-
Constructor Details
-
MutableThreadContextStack
public MutableThreadContextStack()Constructs an empty MutableThreadContextStack. -
MutableThreadContextStack
Constructs a new instance.- Parameters:
list
- Initial elements to be stored in this stack implementation.
-
-
Method Details
-
pop
Description copied from interface:ThreadContext.ContextStack
Returns the element at the top of the stack.- Specified by:
pop
in interfaceThreadContext.ContextStack
- Returns:
- The element at the top of the stack.
-
peek
Description copied from interface:ThreadContext.ContextStack
Returns the element at the top of the stack without removing it or null if the stack is empty.- Specified by:
peek
in interfaceThreadContext.ContextStack
- Returns:
- the element at the top of the stack or null if the stack is empty.
-
push
Description copied from interface:ThreadContext.ContextStack
Pushes an element onto the stack.- Specified by:
push
in interfaceThreadContext.ContextStack
- Parameters:
message
- The element to add.
-
getDepth
public int getDepth()Description copied from interface:ThreadContext.ContextStack
Returns the number of elements in the stack.- Specified by:
getDepth
in interfaceThreadContext.ContextStack
- Returns:
- the number of elements in the stack.
-
asList
Description copied from interface:ThreadContext.ContextStack
Returns all the elements in the stack in a List.- Specified by:
asList
in interfaceThreadContext.ContextStack
- Returns:
- all the elements in the stack in a List.
-
trim
public void trim(int depth) Description copied from interface:ThreadContext.ContextStack
Trims elements from the end of the stack.- Specified by:
trim
in interfaceThreadContext.ContextStack
- Parameters:
depth
- The maximum number of items in the stack to keep.
-
copy
Description copied from interface:ThreadContext.ContextStack
Returns a copy of the ContextStack.- Specified by:
copy
in interfaceThreadContext.ContextStack
- Returns:
- a copy of the ContextStack.
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<String>
-
size
public int size()- Specified by:
size
in interfaceCollection<String>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<String>
-
contains
- Specified by:
contains
in interfaceCollection<String>
-
iterator
-
toArray
- Specified by:
toArray
in interfaceCollection<String>
-
toArray
public <T> T[] toArray(T[] ts) - Specified by:
toArray
in interfaceCollection<String>
-
add
- Specified by:
add
in interfaceCollection<String>
-
remove
- Specified by:
remove
in interfaceCollection<String>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<String>
-
addAll
- Specified by:
addAll
in interfaceCollection<String>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<String>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<String>
-
toString
-
formatTo
Description copied from interface:StringBuilderFormattable
Writes a text representation of this object into the specifiedStringBuilder
, ideally without allocating temporary objects.- Specified by:
formatTo
in interfaceStringBuilderFormattable
- Parameters:
buffer
- the StringBuilder to write into
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<String>
- Overrides:
hashCode
in classObject
-
equals
- Specified by:
equals
in interfaceCollection<String>
- Overrides:
equals
in classObject
-
getImmutableStackOrNull
Description copied from interface:ThreadContext.ContextStack
Returns 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:
getImmutableStackOrNull
in interfaceThreadContext.ContextStack
- Returns:
- a ContextStack with the same contents as this ContextStack or
null
.
-
freeze
public void freeze()"Freezes" this context stack so it becomes immutable: all mutator methods will throw an exception from now on. -
isFrozen
public boolean isFrozen()Returns whether this context stack is frozen.- Returns:
- whether this context stack is frozen.
-