|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object info.monitorenter.util.collections.RingBufferArrayFast<T> info.monitorenter.util.collections.RingBufferArray<T>
T
- the type to store.public class RingBufferArray<T>
A RingBuffer can be used to store a limited number of entries of any type within a buffer.
As soon as the maximum number of entries is reached, the next entry is added
to the end and the first entry is removed from it. In this case, all elements
are stored in a Object[]. But don't worry there will not be a single call to
System.arraycopy
caused by invocation of the
add(Object element)
- method. Internal indexes into the array for
the head and tail allow to reuse the same memory again and again.
No element is lost: If setBufferSize(int asize)
decreases the
size of the buffer and it will get smaller than the actual amount of elements
stored, they will get cached until removed.
For allowing high performance single-threaded use this implementation and the
implementations of the retrievable Iterator
- instances are not
synchronized at all.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface info.monitorenter.util.collections.IRingBuffer |
---|
IRingBuffer.RingBufferException |
Field Summary | |
---|---|
protected java.util.List<T> |
m_pendingremove
Elements that stores elements that have to be removed due to an invocation to setBufferSize(int) with a smaller argument than the amount of
elements stored. |
Fields inherited from class info.monitorenter.util.collections.RingBufferArrayFast |
---|
DEBUG, m_buffer, m_empty, m_headpointer, m_size, m_tailpointer |
Constructor Summary | |
---|---|
RingBufferArray(int aSize)
Constructs a RingBuffer with the given size. |
Method Summary | |
---|---|
boolean |
equals(java.lang.Object obj)
|
int |
hashCode()
|
boolean |
isEmpty()
Tests whether no elements are stored in the buffer. |
java.util.Iterator<T> |
iteratorF2L()
Returns an Iterator that will return the elements in exactly
the inverse order the subsequent call to remove() would do. |
java.util.Iterator<T> |
iteratorL2F()
Returns an Iterator that will return the elements in exactly
the order the subsequent call to remove() would do. |
T |
remove()
Removes the oldest element from the buffer. |
T[] |
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. |
java.lang.String |
toString()
Returns a string representation of the RingBuffer and it's contents. |
Methods inherited from class info.monitorenter.util.collections.RingBufferArrayFast |
---|
add, clear, clone, getBufferSize, getOldest, getYoungest, isFull, iterator |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.util.List<T> m_pendingremove
setBufferSize(int)
with a smaller argument than the amount of
elements stored.
Constructor Detail |
---|
public RingBufferArray(int aSize)
aSize
- the size of the buffer.Method Detail |
---|
public boolean equals(java.lang.Object obj)
equals
in class RingBufferArrayFast<T>
Object.equals(java.lang.Object)
public int hashCode()
hashCode
in class RingBufferArrayFast<T>
Object.hashCode()
public boolean isEmpty()
IRingBuffer
isEmpty
in interface IRingBuffer<T>
isEmpty
in class RingBufferArrayFast<T>
IRingBuffer.isEmpty()
public java.util.Iterator<T> iteratorF2L()
RingBufferArrayFast
Iterator
that will return the elements in exactly
the inverse order the subsequent call to remove()
would do.
The youngest elements are returned first. The Iterator
returned is not thread- safe!
iteratorF2L
in interface IRingBuffer<T>
iteratorF2L
in class RingBufferArrayFast<T>
Iterator
that will return the elements in exactly
the inverse order the subsequent call to remove()
would do.IRingBuffer.iteratorF2L()
public java.util.Iterator<T> iteratorL2F()
RingBufferArrayFast
Iterator
that will return the elements in exactly
the order the subsequent call to remove()
would do.
The oldest elements are returned first. The Iterator
returned is not thread- safe!
iteratorL2F
in interface IRingBuffer<T>
iteratorL2F
in class RingBufferArrayFast<T>
Iterator
that will return the elements in exactly
the order the subsequent call to remove()
would do.IRingBuffer.iteratorL2F()
public T remove()
IRingBuffer
remove
in interface IRingBuffer<T>
remove
in class RingBufferArrayFast<T>
IRingBuffer.remove()
public T[] removeAll()
IRingBuffer
removeAll
in interface IRingBuffer<T>
removeAll
in class RingBufferArrayFast<T>
IRingBuffer.removeAll()
public void setBufferSize(int newSize)
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. Don't pretend on calling this method for
saving of memory very often as the whole buffer has to be copied into a new
array every time- and if newSize < getSize() additional the overhanging
elements references have to be moved to the internal
List pendingremove
.
setBufferSize
in interface IRingBuffer<T>
setBufferSize
in class RingBufferArrayFast<T>
newSize
- the new size of the buffer.public int size()
IRingBuffer
size
in interface IRingBuffer<T>
size
in class RingBufferArrayFast<T>
IRingBuffer.size()
public java.lang.String toString()
Don't call this in your application too often: hard array copy - operation and memory allocations are triggered.
toString
in class RingBufferArrayFast<T>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |