org.apache.logging.log4j.spi
Class DefaultThreadContextStack

java.lang.Object
  extended by org.apache.logging.log4j.spi.DefaultThreadContextStack
All Implemented Interfaces:
Serializable, Iterable<String>, Collection<String>, ThreadContextStack, ThreadContext.ContextStack

public class DefaultThreadContextStack
extends Object
implements ThreadContextStack

A copy-on-write thread-safe variant of org.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
DefaultThreadContextStack(boolean useStack)
           
 
Method Summary
 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()
          Clears all elements from the stack.
 boolean contains(Object o)
           
 boolean containsAll(Collection<?> objects)
           
 ThreadContextStack copy()
          Returns a copy of the ContextStack.
 int getDepth()
          Returns the number of elements in the stack.
 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)
          Add an element to 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, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

DefaultThreadContextStack

public DefaultThreadContextStack(boolean useStack)
Method Detail

pop

public String pop()
Description copied from interface: ThreadContext.ContextStack
Returns the element at the top of the stack.

Specified by:
pop in interface ThreadContext.ContextStack
Returns:
The element at the top of the stack.

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 interface ThreadContext.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.ContextStack
Add an element to the stack.

Specified by:
push in interface ThreadContext.ContextStack
Parameters:
message - The element to add.

getDepth

public int getDepth()
Description copied from interface: ThreadContext.ContextStack
Returns the number of elements in the stack.

Specified by:
getDepth in interface ThreadContext.ContextStack
Returns:
the number of elements in the stack.

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 interface ThreadContext.ContextStack
Returns:
all the elements in the stack in a List.

trim

public void trim(int depth)
Description copied from interface: ThreadContext.ContextStack
Trims elements from the end of the stack.

Specified by:
trim in interface ThreadContext.ContextStack
Parameters:
depth - The maximum number of items in the stack to keep.

copy

public ThreadContextStack copy()
Description copied from interface: ThreadContext.ContextStack
Returns a copy of the ContextStack.

Specified by:
copy in interface ThreadContext.ContextStack
Returns:
a copy of the ContextStack.s

clear

public void clear()
Description copied from interface: ThreadContext.ContextStack
Clears all elements from the stack.

Specified by:
clear in interface Collection<String>
Specified by:
clear in interface ThreadContext.ContextStack

size

public int size()
Specified by:
size in interface Collection<String>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<String>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<String>

iterator

public Iterator<String> iterator()
Specified by:
iterator in interface Iterable<String>
Specified by:
iterator in interface Collection<String>

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<String>

toArray

public <T> T[] toArray(T[] ts)
Specified by:
toArray in interface Collection<String>

add

public boolean add(String s)
Specified by:
add in interface Collection<String>

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<String>

containsAll

public boolean containsAll(Collection<?> objects)
Specified by:
containsAll in interface Collection<String>

addAll

public boolean addAll(Collection<? extends String> strings)
Specified by:
addAll in interface Collection<String>

removeAll

public boolean removeAll(Collection<?> objects)
Specified by:
removeAll in interface Collection<String>

retainAll

public boolean retainAll(Collection<?> objects)
Specified by:
retainAll in interface Collection<String>

toString

public String toString()
Overrides:
toString in class Object


Copyright © 1999-2013 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.