Package org.epics.pvaccess.util
Class CircularBuffer<T>
- java.lang.Object
-
- org.epics.pvaccess.util.CircularBuffer<T>
-
- Type Parameters:
T
- buffer element type.
public final class CircularBuffer<T> extends Object
Implementaton of circular FIFO buffer. If buffer is full, the oldest element is replaced with the new one. Instance is not a bit synchronized.- Author:
- Matej Sekoranja
-
-
Constructor Summary
Constructors Constructor Description CircularBuffer(int capacity)
Create a BoundedBuffer with the given capacity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
capacity()
Get buffer capacity.T
extract()
Extract the oldest element from the buffer.T
insert(T x)
Insert a new element in to the buffer.int
size()
Get number of elements in the buffer.
-
-
-
Constructor Detail
-
CircularBuffer
public CircularBuffer(int capacity) throws IllegalArgumentException
Create a BoundedBuffer with the given capacity.- Parameters:
capacity
- buffer capacity.- Throws:
IllegalArgumentException
- if capacity less or equal to zero
-
-
Method Detail
-
size
public int size()
Get number of elements in the buffer.- Returns:
- number of elements in the buffer.
-
capacity
public int capacity()
Get buffer capacity.- Returns:
- buffer capacity.
-
insert
public final T insert(T x)
Insert a new element in to the buffer. If buffer full, oldest element will be overriden.- Parameters:
x
- element to insert.- Returns:
- overriden element, if any.
-
extract
public final T extract()
Extract the oldest element from the buffer.- Returns:
- the oldest element from the buffer.
-
-