org.apache.logging.log4j.core.util
Class CyclicBuffer<T>

java.lang.Object
  extended by org.apache.logging.log4j.core.util.CyclicBuffer<T>
Type Parameters:
T - The type of object stored in the buffer.

public final class CyclicBuffer<T>
extends Object

A bounded buffer containing elements of type T. When the number of elements to be added will exceed the size of the buffer the oldest element will be overwritten. Access to the buffer is thread safe.


Constructor Summary
CyclicBuffer(Class<T> clazz, int size)
          Instantiate a new CyclicBuffer of at most maxSize events.
 
Method Summary
 void add(T item)
          Add an item as the last event in the buffer.
 boolean isEmpty()
          Determines if the buffer contains elements.
 T[] removeAll()
          Removes all the elements from the buffer and returns them.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CyclicBuffer

public CyclicBuffer(Class<T> clazz,
                    int size)
             throws IllegalArgumentException
Instantiate a new CyclicBuffer of at most maxSize events.

Parameters:
clazz - The Class associate with the type of object in the buffer.
size - The number of items in the buffer.
Throws:
IllegalArgumentException - if the size is negative.
Method Detail

add

public void add(T item)
Add an item as the last event in the buffer.

Parameters:
item - The item to add to the buffer.

removeAll

public T[] removeAll()
Removes all the elements from the buffer and returns them.

Returns:
An array of the elements in the buffer.

isEmpty

public boolean isEmpty()
Determines if the buffer contains elements.

Returns:
true if the buffer is empty, false otherwise.


Copyright © 1999-2014 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.