public class CyclicBuffer<E>
extends java.lang.Object
It allows read access to any element in the buffer not just the first or last element.
| Modifier and Type | Field and Description |
|---|---|
(package private) E[] |
ea |
(package private) int |
first |
(package private) int |
last |
(package private) int |
maxSize |
(package private) int |
numElems |
| Constructor and Description |
|---|
CyclicBuffer(CyclicBuffer<E> other) |
CyclicBuffer(int maxSize)
Instantiate a new CyclicBuffer of at most
maxSize events. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(E event)
Add an
event as the last event in the buffer. |
java.util.List<E> |
asList() |
void |
clear()
Clears the buffer and resets all attributes.
|
E |
get()
Get the oldest (first) element in the buffer.
|
E |
get(int i)
Get the ith oldest event currently in the buffer.
|
int |
getMaxSize() |
private void |
init(int maxSize) |
int |
length()
Get the number of elements in the buffer.
|
void |
resize(int newSize)
Resize the cyclic buffer to
newSize. |
E[] ea
int first
int last
int numElems
int maxSize
public CyclicBuffer(int maxSize)
throws java.lang.IllegalArgumentException
maxSize events.
The maxSize argument must a positive integer.maxSize - The maximum number of elements in the buffer.java.lang.IllegalArgumentExceptionpublic CyclicBuffer(CyclicBuffer<E> other)
private void init(int maxSize)
public void clear()
public void add(E event)
event as the last event in the buffer.public E get(int i)
null is returned.public int getMaxSize()
public E get()
public java.util.List<E> asList()
public int length()
maxSize (inclusive).public void resize(int newSize)
newSize.java.lang.IllegalArgumentException - if newSize is negative.