Module org.apache.logging.log4j
Package org.apache.logging.log4j
Interface ThreadContext.ContextStack
-
- All Superinterfaces:
Collection<String>
,Iterable<String>
- All Known Subinterfaces:
ThreadContextStack
- All Known Implementing Classes:
DefaultThreadContextStack
,MutableThreadContextStack
- Enclosing class:
- ThreadContext
public static interface ThreadContext.ContextStack extends Collection<String>
The ThreadContext Stack interface.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description List<String>
asList()
Returns all the elements in the stack in a List.ThreadContext.ContextStack
copy()
Returns a copy of the ContextStack.int
getDepth()
Returns the number of elements in the stack.ThreadContext.ContextStack
getImmutableStackOrNull()
Returns a ContextStack with the same contents as this ContextStack ornull
.String
peek()
Returns the element at the top of the stack without removing it or the empty string 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.void
trim(int depth)
Trims elements from the end of the stack.
-
-
-
Method Detail
-
pop
String pop()
Returns the element at the top of the stack. If the stack is empty, then the empty string is returned.- Returns:
- The element at the top of the stack.
-
peek
String peek()
Returns the element at the top of the stack without removing it or the empty string if the stack is empty.- Returns:
- the element at the top of the stack or the empty string if the stack is empty.
-
push
void push(String message)
Pushes an element onto the stack.- Parameters:
message
- The element to add.- Throws:
NullPointerException
- if message is nullUnsupportedOperationException
- if the context stack is disabled
-
getDepth
int getDepth()
Returns the number of elements in the stack.- Returns:
- the number of elements in the stack.
-
asList
List<String> asList()
Returns all the elements in the stack in a List.- Returns:
- all the elements in the stack in a List.
-
trim
void trim(int depth)
Trims elements from the end of the stack.- Parameters:
depth
- The maximum number of items in the stack to keep.- Throws:
IllegalArgumentException
- if depth is negative
-
copy
ThreadContext.ContextStack copy()
Returns a copy of the ContextStack.- Returns:
- a copy of the ContextStack.
-
getImmutableStackOrNull
ThreadContext.ContextStack getImmutableStackOrNull()
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.- Returns:
- a ContextStack with the same contents as this ContextStack or
null
.
-
-