Package de.gsi.dataset.utils
Class DoubleCircularBuffer
- java.lang.Object
-
- de.gsi.dataset.utils.DoubleCircularBuffer
-
public class DoubleCircularBuffer extends java.lang.Objectsimple circular ring buffer implementation for double type (with read == write position)- Author:
- rstein
-
-
Constructor Summary
Constructors Constructor Description DoubleCircularBuffer(int capacity)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()double[]get(double[] into, int length)double[]get(double[] into, int readPos, int length)doubleget(int readPos)static voidmain(java.lang.String[] args)meant for testing/illustrating usagebooleanput(double element)add new elementintput(double[] newElements, int length)add multiple new elementsintput(double[] newElements, int startIndex, int length)add multiple new elementsintremainingCapacity()voidreset()resets and clears buffer
-
-
-
Method Detail
-
reset
public void reset()
resets and clears buffer
-
available
public int available()
- Returns:
- number of available buffer elements
-
remainingCapacity
public int remainingCapacity()
- Returns:
- number of elements that can be written before buffer wraps-around
-
put
public boolean put(double element)
add new element- Parameters:
element- new element- Returns:
- true
-
put
public int put(double[] newElements, int length)add multiple new elements- Parameters:
newElements- array of new elementslength- number of elements that are to be written from array- Returns:
- true: write index is smaller than read index
-
put
public int put(double[] newElements, int startIndex, int length)add multiple new elements- Parameters:
newElements- array of new elementsstartIndex- 'null'length- number of elements that are to be written from array- Returns:
- true: write index is smaller than read index
-
get
public double get(int readPos)
- Parameters:
readPos- circular index (wraps around)- Returns:
- the value
-
get
public double[] get(double[] into, int length)- Parameters:
into- storage containerlength- number of elements to be read- Returns:
- either into or newly allocated array containing the result
-
get
public double[] get(double[] into, int readPos, int length)- Parameters:
into- storage containerreadPos- circular index (wraps around)length- number of elements to be read- Returns:
- either into or newly allocated array containing the result
-
main
public static void main(java.lang.String[] args)
meant for testing/illustrating usage- Parameters:
args- the command line arguments
-
-