T
- The type of object stored in the buffer.public final class CyclicBuffer<T>
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.lang.Class<T> |
clazz |
private int |
first |
private int |
last |
private int |
numElems |
private T[] |
ring |
Constructor and Description |
---|
CyclicBuffer(java.lang.Class<T> clazz,
int size)
Instantiates a new CyclicBuffer of at most
maxSize events. |
Modifier and Type | Method and Description |
---|---|
void |
add(T item)
Adds an item as the last event in the buffer.
|
boolean |
isEmpty()
Determines if the buffer contains elements.
|
private T[] |
makeArray(java.lang.Class<T> cls,
int size) |
T[] |
removeAll()
Removes all the elements from the buffer and returns them.
|
private final T[] ring
private int first
private int last
private int numElems
private final java.lang.Class<T> clazz
public CyclicBuffer(java.lang.Class<T> clazz, int size) throws java.lang.IllegalArgumentException
maxSize
events.clazz
- The Class associate with the type of object in the buffer.size
- The number of items in the buffer.java.lang.IllegalArgumentException
- if the size is negative.public void add(T item)
item
- The item to add to the buffer.public T[] removeAll()
public boolean isEmpty()