Package org.apache.logging.log4j.spi
Class MutableThreadContextStack
- java.lang.Object
-
- org.apache.logging.log4j.spi.MutableThreadContextStack
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable<java.lang.String>,java.util.Collection<java.lang.String>,ThreadContextStack,ThreadContext.ContextStack,org.apache.logging.log4j.util.StringBuilderFormattable
public class MutableThreadContextStack extends java.lang.Object implements ThreadContextStack, org.apache.logging.log4j.util.StringBuilderFormattable
TODO- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description MutableThreadContextStack()Constructs an empty MutableThreadContextStack.MutableThreadContextStack(java.util.List<java.lang.String> list)Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(java.lang.String s)booleanaddAll(java.util.Collection<? extends java.lang.String> strings)java.util.List<java.lang.String>asList()Returns all the elements in the stack in a List.voidclear()booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection<?> objects)ThreadContextStackcopy()Returns a copy of the ContextStack.booleanequals(java.lang.Object obj)voidformatTo(java.lang.StringBuilder buffer)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.java.util.Iterator<java.lang.String>iterator()java.lang.Stringpeek()Returns the element at the top of the stack without removing it or null if the stack is empty.java.lang.Stringpop()Returns the element at the top of the stack.voidpush(java.lang.String message)Pushes an element onto the stack.booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> objects)booleanretainAll(java.util.Collection<?> objects)intsize()java.lang.Object[]toArray()<T> T[]toArray(T[] ts)java.lang.StringtoString()voidtrim(int depth)Trims elements from the end of the stack.
-
-
-
Method Detail
-
pop
public java.lang.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 java.lang.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(java.lang.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 java.util.List<java.lang.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 interfacejava.util.Collection<java.lang.String>
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection<java.lang.String>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Collection<java.lang.String>
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
containsin interfacejava.util.Collection<java.lang.String>
-
iterator
public java.util.Iterator<java.lang.String> iterator()
- Specified by:
iteratorin interfacejava.util.Collection<java.lang.String>- Specified by:
iteratorin interfacejava.lang.Iterable<java.lang.String>
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection<java.lang.String>
-
toArray
public <T> T[] toArray(T[] ts)
- Specified by:
toArrayin interfacejava.util.Collection<java.lang.String>
-
add
public boolean add(java.lang.String s)
- Specified by:
addin interfacejava.util.Collection<java.lang.String>
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
removein interfacejava.util.Collection<java.lang.String>
-
containsAll
public boolean containsAll(java.util.Collection<?> objects)
- Specified by:
containsAllin interfacejava.util.Collection<java.lang.String>
-
addAll
public boolean addAll(java.util.Collection<? extends java.lang.String> strings)
- Specified by:
addAllin interfacejava.util.Collection<java.lang.String>
-
removeAll
public boolean removeAll(java.util.Collection<?> objects)
- Specified by:
removeAllin interfacejava.util.Collection<java.lang.String>
-
retainAll
public boolean retainAll(java.util.Collection<?> objects)
- Specified by:
retainAllin interfacejava.util.Collection<java.lang.String>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
formatTo
public void formatTo(java.lang.StringBuilder buffer)
- Specified by:
formatToin interfaceorg.apache.logging.log4j.util.StringBuilderFormattable
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfacejava.util.Collection<java.lang.String>- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Specified by:
equalsin interfacejava.util.Collection<java.lang.String>- Overrides:
equalsin classjava.lang.Object
-
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.
-
-