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:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description MutableThreadContextStack()Constructs an empty MutableThreadContextStack.MutableThreadContextStack(List<String> list)Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(String s)booleanaddAll(Collection<? extends String> strings)List<String>asList()Returns all the elements in the stack in a List.voidclear()booleancontains(Object o)booleancontainsAll(Collection<?> objects)ThreadContextStackcopy()Returns a copy of the ContextStack.booleanequals(Object obj)voidformatTo(StringBuilder buffer)Writes a text representation of this object into the specifiedStringBuilder, ideally without allocating temporary objects.voidfreeze()"Freezes" this context stack so it becomes immutable: all mutator methods will throw an exception from now on.intgetDepth()Returns the number of elements in the stack.ThreadContext.ContextStackgetImmutableStackOrNull()Returns a ContextStack with the same contents as this ContextStack ornull.inthashCode()booleanisEmpty()booleanisFrozen()Returns whether this context stack is frozen.Iterator<String>iterator()Stringpeek()Returns the element at the top of the stack without removing it or null if the stack is empty.Stringpop()Returns the element at the top of the stack.voidpush(String message)Pushes an element onto the stack.booleanremove(Object o)booleanremoveAll(Collection<?> objects)booleanretainAll(Collection<?> objects)intsize()Object[]toArray()<T> T[]toArray(T[] ts)StringtoString()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, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray
-
-
-
-
Method Detail
-
pop
public String 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.
-
peek
public String 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.
-
push
public void push(String message)
Description copied from interface:ThreadContext.ContextStackPushes an element onto the stack.- Specified by:
pushin interfaceThreadContext.ContextStack- Parameters:
message- The element to add.
-
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.
-
asList
public List<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.
-
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.
-
copy
public ThreadContextStack copy()
Description copied from interface:ThreadContext.ContextStackReturns a copy of the ContextStack.- Specified by:
copyin interfaceThreadContext.ContextStack- Returns:
- a copy of the ContextStack.
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<String>
-
size
public int size()
- Specified by:
sizein interfaceCollection<String>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<String>
-
contains
public boolean contains(Object o)
- Specified by:
containsin interfaceCollection<String>
-
toArray
public Object[] toArray()
- Specified by:
toArrayin interfaceCollection<String>
-
toArray
public <T> T[] toArray(T[] ts)
- Specified by:
toArrayin interfaceCollection<String>
-
add
public boolean add(String s)
- Specified by:
addin interfaceCollection<String>
-
remove
public boolean remove(Object o)
- Specified by:
removein interfaceCollection<String>
-
containsAll
public boolean containsAll(Collection<?> objects)
- Specified by:
containsAllin interfaceCollection<String>
-
addAll
public boolean addAll(Collection<? extends String> strings)
- Specified by:
addAllin interfaceCollection<String>
-
removeAll
public boolean removeAll(Collection<?> objects)
- Specified by:
removeAllin interfaceCollection<String>
-
retainAll
public boolean retainAll(Collection<?> objects)
- Specified by:
retainAllin interfaceCollection<String>
-
formatTo
public void formatTo(StringBuilder buffer)
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
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceCollection<String>- Overrides:
hashCodein classObject
-
equals
public boolean equals(Object obj)
- Specified by:
equalsin interfaceCollection<String>- Overrides:
equalsin classObject
-
getImmutableStackOrNull
public ThreadContext.ContextStack 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.
-
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.
-
-