|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbb.util.BufferFixed<E>
public class BufferFixed<E>
Simple data structure whose maximum number of elements stored is fixed to a constant value.
This size limit is enforced via a "drop oldest" policy; see add
.
Motivation: this class is useful when memory consumption must be bounded and old events may be safely discarded.
This class is not multithread safe.
Nested Class Summary | |
---|---|
static class |
BufferFixed.State<E>
Used to record a snapshot of the state of a BufferFixed instance. |
Field Summary | |
---|---|
private Deque<E> |
deque
Underlying data structure that holds elements. |
private long |
numDropped
Number of old elements that were dropped from deque since the last call to getAndResetState . |
private int |
sizeMax
Maximum number of elements that can be stored in deque . |
private static int |
sizeMax_default
Default value for sizeMax . |
Constructor Summary | |
---|---|
BufferFixed()
Calls . |
|
BufferFixed(int sizeMax)
Constructor. |
Method Summary | |
---|---|
void |
add(E element)
Adds element to an internal queue. |
BufferFixed.State<E> |
getAndResetState()
Returns a new BufferFixed.State instance which holds the complete state of this instance. |
int |
size()
Returns deque . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final int sizeMax_default
sizeMax
.
private final int sizeMax
deque
.
Contract: is > 0.
private Deque<E> deque
Contract: is never null.
private long numDropped
deque
since the last call to getAndResetState
.
Contract: is either >= 0 if is a legit value, or else is pegged at Long.MIN_VALUE
if overflow occurred.
Constructor Detail |
---|
public BufferFixed()
this
(sizeMax_default
)
.
public BufferFixed(int sizeMax) throws IllegalArgumentException
IllegalArgumentException
- if sizeMax <= 0Method Detail |
---|
public void add(E element) throws IllegalArgumentException
sizeMax
,
then first removes the oldest item from the queue before adding element.
IllegalArgumentException
- if element is nullpublic BufferFixed.State<E> getAndResetState()
BufferFixed.State
instance which holds the complete state of this instance.
The caller is free to manipulate the result in any way (e.g. mutate the BufferFixed.State.deque
field, such as remove undesired elements).
Side effect: before return, resets all this instance's state to its initial condition.
public int size()
deque
.size
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |