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
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
-
Constructor Details
-
CircularBuffer
public CircularBuffer(int bufferSize)
-
-
Method Details
-
add
Add an element. -
getElement
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
Get head element- Returns:
- the head element. null if the buffer is empty.
-
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
-
size
public int size()
-