Class CircularBuffer<T>
- java.lang.Object
-
- java.util.AbstractCollection<T>
-
- org.eclipse.nebula.visualization.xygraph.dataprovider.CircularBuffer<T>
-
- All Implemented Interfaces:
java.lang.Iterable<T>
,java.util.Collection<T>
public class CircularBuffer<T> extends java.util.AbstractCollection<T>
A particular circular buffer. New arrived data will be appended to the tail of the buffer. When buffer is full, the oldest data will be deleted when new data arrived.
-
-
Constructor Summary
Constructors Constructor Description CircularBuffer(int bufferSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(T element)
Add an element.void
clear()
clear the buffer;int
getBufferSize()
T
getElement(int index)
Get elementT
getHead()
Get head elementT
getTail()
Get tail elementjava.util.Iterator<T>
iterator()
void
setBufferSize(int bufferSize, boolean clear)
Set the buffer size.int
size()
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Field Detail
-
bufferSize
private int bufferSize
-
buffer
private T[] buffer
-
head
private int head
-
tail
private int tail
-
count
private int count
-
-
Method Detail
-
add
public boolean add(T element)
Add an element.
-
getElement
public T getElement(int index)
Get element- Parameters:
index
- the index of the element in the buffer.- Returns:
- the element. null if the data at the index doesn't exist.
-
getHead
public T getHead()
Get head element- Returns:
- the head element. null if the buffer is empty.
-
getTail
public T getTail()
Get tail element- Returns:
- the tail element. null if the buffer is empty.
-
clear
public void clear()
clear the buffer;
-
setBufferSize
public void setBufferSize(int bufferSize, boolean clear)
Set the buffer size.- Parameters:
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.
-
getBufferSize
public int getBufferSize()
- Returns:
- the bufferSize
-
iterator
public java.util.Iterator<T> iterator()
-
-