org.apache.commons.collections.buffer
public class CircularFifoBuffer extends BoundedFifoBuffer
The removal order of a CircularFifoBuffer
is based on the
insertion order; elements are removed in the same order in which they
were added. The iteration order is the same as the removal order.
The add, CircularFifoBuffer and CircularFifoBuffer operations all perform in constant time. All other operations perform in linear time or worse.
Note that this implementation is not synchronized. The following can be
used to provide synchronized access to your CircularFifoBuffer
:
Buffer fifo = BufferUtils.synchronizedBuffer(new CircularFifoBuffer());
This buffer prevents null objects from being added.
This class is Serializable from Commons Collections 3.1.
Since: Commons Collections 3.0
Version: $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
Constructor Summary | |
---|---|
CircularFifoBuffer()
Constructor that creates a buffer with the default size of 32. | |
CircularFifoBuffer(int size)
Constructor that creates a buffer with the specified size.
| |
CircularFifoBuffer(Collection coll)
Constructor that creates a buffer from the specified collection.
|
Method Summary | |
---|---|
boolean | add(Object element)
If the buffer is full, the least recently added element is discarded so
that a new element can be inserted.
|
Parameters: size the size of the buffer (cannot be changed)
Throws: IllegalArgumentException if the size is less than 1
Parameters: coll the collection to copy into the buffer, may not be null
Throws: NullPointerException if the collection is null
Parameters: element the element to add
Returns: true, always