public class CircularBuffer<T>
extends java.util.AbstractCollection<T>
Constructor | Description |
---|---|
CircularBuffer(int bufferSize) |
Modifier and Type | Method | 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
public boolean add(T element)
add
in class java.util.AbstractCollection<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()
clear
in class java.util.AbstractCollection<T>
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()
iterator
in class java.util.AbstractCollection<T>
public int size()
size
in class java.util.AbstractCollection<T>