public class CircularBuffer<T>
extends java.util.AbstractCollection<T>
Constructor and Description |
---|
CircularBuffer(int bufferSize) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(T element)
Add an element.
|
void |
clear()
clear the buffer;
|
int |
getBufferSize() |
T |
getElement(int index)
Get element
|
T |
getHead()
Get head element
|
T |
getTail()
Get tail element
|
java.util.Iterator<T> |
iterator() |
void |
setBufferSize(int bufferSize,
boolean clear)
Set the buffer size.
|
int |
size() |
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public boolean add(T element)
public T getElement(int index)
index
- the index of the element in the buffer.public T getHead()
public T getTail()
public void clear()
public void setBufferSize(int bufferSize, boolean clear)
bufferSize
- the bufferSize to setclear
- clear the buffer if true. Otherwise keep the exist data;
Oldest data will be omitted if the new bufferSize is less than
the exist data count.public int getBufferSize()
public java.util.Iterator<T> iterator()