|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface IRingBuffer
Interface for implementations of RingBuffers.
Nested Class Summary | |
---|---|
static class |
IRingBuffer.RingBufferException
Special exception related to ringbuffer operations. |
Method Summary | |
---|---|
Object |
add(Object element)
Adds element to the RingBuffer. |
void |
clear()
Clears the buffer without returning anything. |
int |
getBufferSize()
Returns the absolute amount of space in the buffer. |
Object |
getOldest()
Returns the oldest element from the buffer. |
Object |
getYoungest()
Returns the last element added. |
boolean |
isEmpty()
Tests wether no elements are stored in the buffer. |
boolean |
isFull()
Returns true if no more space in the buffer is available. |
Iterator |
iteratorF2L()
Returns an iterator starting from the first (youngest) to the last (oldest) element. |
Iterator |
iteratorL2F()
Returns an iterator starting from the last (oldest) to the first (youngest) element. |
Object |
remove()
Removes the oldest element from the buffer. |
Object[] |
removeAll()
Clears the buffer. |
void |
setBufferSize(int newSize)
Sets a new buffer- size. |
int |
size()
Returns the actual amount of elements stored in the buffer. |
Method Detail |
---|
Object add(Object element) throws IRingBuffer.RingBufferException
If the buffer is full, an Exception will be thrown.
Note that RingBufferException
does not need to be caught
because it is an inheritant of java.lang.RuntimeException
.
Especially for the Object add(Object element)
- method there
may be an implementation that never throws BUFFER_FULL
but
returns the oldest element in case the buffer is full.
element
- the element to add.
IRingBuffer.RingBufferException
- if the buffer cannot accept any more elements.void clear()
If the content is of no interest prefer using this method instead of
removeAll()
as it may be implemented in a much faster way (
O(constant)
instead of O(n)
).
int getBufferSize()
Object getOldest() throws IRingBuffer.RingBufferException
IRingBuffer.RingBufferException
- if the buffer is empty.Object getYoungest() throws IRingBuffer.RingBufferException
IRingBuffer.RingBufferException
- if the buffer is empty.boolean isEmpty()
boolean isFull()
add(Object)
.
Iterator iteratorF2L()
Iterator iteratorL2F()
Object remove() throws IRingBuffer.RingBufferException
IRingBuffer.RingBufferException
- if the buffer is empty.Object[] removeAll()
void setBufferSize(int newSize)
Implementations may vary on handling the problem that the new size is
smaller than the actual amount of elements in the buffer:
The oldest elements may be thrown away.
A new size is assigned but the elements "overhanging" are returned by the
Object remove()
- method first. This may take time until the
buffer has its actual size again.
newSize
- the new buffer size to set.int size()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |