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 oforg.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:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DefaultThreadContextStack(boolean useStack)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(String s)
boolean
addAll(Collection<? extends String> strings)
List<String>
asList()
Returns all the elements in the stack in a List.void
clear()
boolean
contains(Object o)
boolean
containsAll(Collection<?> objects)
ThreadContextStack
copy()
Returns a copy of the ContextStack.boolean
equals(Object obj)
void
formatTo(StringBuilder buffer)
Writes a text representation of this object into the specifiedStringBuilder
, ideally without allocating temporary objects.int
getDepth()
Returns the number of elements in the stack.ThreadContext.ContextStack
getImmutableStackOrNull()
Returns a ContextStack with the same contents as this ContextStack ornull
.int
hashCode()
boolean
isEmpty()
Iterator<String>
iterator()
String
peek()
Returns the element at the top of the stack without removing it or null if the stack is empty.String
pop()
Returns the element at the top of the stack.void
push(String message)
Pushes an element onto the stack.boolean
remove(Object o)
boolean
removeAll(Collection<?> objects)
boolean
retainAll(Collection<?> objects)
int
size()
Object[]
toArray()
<T> T[]
toArray(T[] ts)
String
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, toArray
-
-
-
-
Method Detail
-
add
public boolean add(String s)
- Specified by:
add
in interfaceCollection<String>
-
addAll
public boolean addAll(Collection<? extends String> strings)
- Specified by:
addAll
in interfaceCollection<String>
-
asList
public List<String> 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.
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<String>
-
contains
public boolean contains(Object o)
- Specified by:
contains
in interfaceCollection<String>
-
containsAll
public boolean containsAll(Collection<?> objects)
- Specified by:
containsAll
in interfaceCollection<String>
-
copy
public ThreadContextStack 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.
-
equals
public boolean equals(Object obj)
- Specified by:
equals
in interfaceCollection<String>
- Overrides:
equals
in classObject
-
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.
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfaceCollection<String>
- Overrides:
hashCode
in classObject
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection<String>
-
peek
public String 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.
-
pop
public String 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.
-
push
public void push(String message)
Description copied from interface:ThreadContext.ContextStack
Pushes an element onto the stack.- Specified by:
push
in interfaceThreadContext.ContextStack
- Parameters:
message
- The element to add.
-
remove
public boolean remove(Object o)
- Specified by:
remove
in interfaceCollection<String>
-
removeAll
public boolean removeAll(Collection<?> objects)
- Specified by:
removeAll
in interfaceCollection<String>
-
retainAll
public boolean retainAll(Collection<?> objects)
- Specified by:
retainAll
in interfaceCollection<String>
-
size
public int size()
- Specified by:
size
in interfaceCollection<String>
-
toArray
public Object[] toArray()
- Specified by:
toArray
in interfaceCollection<String>
-
toArray
public <T> T[] toArray(T[] ts)
- Specified by:
toArray
in interfaceCollection<String>
-
formatTo
public void formatTo(StringBuilder buffer)
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
-
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.
-
getImmutableStackOrNull
public ThreadContext.ContextStack 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
.
-
-