public class RollingEventBuffer extends Object
Backed by a fixed-size array that is filled forward, then rolls back to the beginning keeping track of the current position.
Constructor and Description |
---|
RollingEventBuffer(int size)
Ctor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(EventBean theEvent)
Add an event to the buffer.
|
void |
add(EventBean[] events)
Add events to the buffer.
|
EventBean |
get(int index)
Get an event prior to the last event posted given a number of events before the last.
|
EventBean[] |
getBuffer() |
int |
getNextFreeIndex() |
int |
getSize() |
void |
setBuffer(EventBean[] buffer) |
void |
setNextFreeIndex(int nextFreeIndex) |
public RollingEventBuffer(int size)
size
- is the maximum number of events in bufferpublic void add(EventBean[] events)
events
- to addpublic void add(EventBean theEvent)
theEvent
- to addpublic EventBean get(int index)
Thus index 0 returns the last event added, index 1 returns the prior to the last event added up to the maximum buffer size.
index
- prior event index from zero to max sizepublic int getSize()
public EventBean[] getBuffer()
public int getNextFreeIndex()
public void setBuffer(EventBean[] buffer)
public void setNextFreeIndex(int nextFreeIndex)