Class CircularFifoBuffer
- java.lang.Object
-
- java.util.AbstractCollection
-
- org.apache.commons.collections.buffer.BoundedFifoBuffer
-
- org.apache.commons.collections.buffer.CircularFifoBuffer
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable
,java.util.Collection
,BoundedCollection
,Buffer
@Deprecated(since="2021-04-30") public class CircularFifoBuffer extends BoundedFifoBuffer
Deprecated.Commons Collections 3 is in maintenance mode. Commons Collections 4 should be used instead.CircularFifoBuffer is a first in first out buffer with a fixed size that replaces its oldest element if full.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(Object)
,BoundedFifoBuffer.remove()
andBoundedFifoBuffer.get()
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
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CircularFifoBuffer()
Deprecated.Constructor that creates a buffer with the default size of 32.CircularFifoBuffer(int size)
Deprecated.Constructor that creates a buffer with the specified size.CircularFifoBuffer(java.util.Collection coll)
Deprecated.Constructor that creates a buffer from the specified collection.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
add(java.lang.Object element)
Deprecated.If the buffer is full, the least recently added element is discarded so that a new element can be inserted.-
Methods inherited from class org.apache.commons.collections.buffer.BoundedFifoBuffer
clear, get, isEmpty, isFull, iterator, maxSize, remove, size
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Constructor Detail
-
CircularFifoBuffer
public CircularFifoBuffer()
Deprecated.Constructor that creates a buffer with the default size of 32.
-
CircularFifoBuffer
public CircularFifoBuffer(int size)
Deprecated.Constructor that creates a buffer with the specified size.- Parameters:
size
- the size of the buffer (cannot be changed)- Throws:
java.lang.IllegalArgumentException
- if the size is less than 1
-
CircularFifoBuffer
public CircularFifoBuffer(java.util.Collection coll)
Deprecated.Constructor that creates a buffer from the specified collection. The collection size also sets the buffer size- Parameters:
coll
- the collection to copy into the buffer, may not be null- Throws:
java.lang.NullPointerException
- if the collection is null
-
-
Method Detail
-
add
public boolean add(java.lang.Object element)
Deprecated.If the buffer is full, the least recently added element is discarded so that a new element can be inserted.- Specified by:
add
in interfacejava.util.Collection
- Overrides:
add
in classBoundedFifoBuffer
- Parameters:
element
- the element to add- Returns:
- true, always
-
-