Package org.apache.logging.log4j
Interface ThreadContext.ContextStack
- All Superinterfaces:
Collection<String>
,Iterable<String>
,Serializable
- All Known Subinterfaces:
ThreadContextStack
- All Known Implementing Classes:
DefaultThreadContextStack
,MutableThreadContextStack
- Enclosing class:
- ThreadContext
The ThreadContext Stack interface.
-
Method Summary
Modifier and TypeMethodDescriptionasList()
Returns all the elements in the stack in a List.copy()
Returns a copy of the ContextStack.int
getDepth()
Returns the number of elements in the stack.Returns a ContextStack with the same contents as this ContextStack ornull
.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.void
trim
(int depth) Trims elements from the end of the stack.Methods inherited from interface java.util.Collection
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray
-
Method Details
-
pop
String pop()Returns the element at the top of the stack.- Returns:
- The element at the top of the stack.
- Throws:
NoSuchElementException
- if the stack is empty.
-
peek
String peek()Returns the element at the top of the stack without removing it or null if the stack is empty.- Returns:
- the element at the top of the stack or null if the stack is empty.
-
push
Pushes an element onto the stack.- Parameters:
message
- The element to add.
-
getDepth
int getDepth()Returns the number of elements in the stack.- Returns:
- the number of elements in the stack.
-
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.
-
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
.
-