Package de.gsi.dataset.utils
Class RingBuffer<E>
- java.lang.Object
-
- de.gsi.dataset.utils.RingBuffer<E>
-
- Type Parameters:
E- the generic Object to be stored
public class RingBuffer<E> extends java.lang.Objectsimple circular ring buffer implementation for generic Object type (with read/write position)- Author:
- rstein
-
-
Constructor Summary
Constructors Constructor Description RingBuffer(int capacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()booleanput(E element)add new elementintput(E[] newElements, int length)intremainingCapacity()voidreset()clear all data and resets bufferEtake()inttake(E[] into, int length)
-
-
-
Method Detail
-
reset
public void reset()
clear all data and resets buffer
-
available
public int available()
- Returns:
- number of values that are already stored in buffer
-
remainingCapacity
public int remainingCapacity()
- Returns:
- number of values that can be stored before the buffer is full and rolls over
-
put
public boolean put(E element)
add new element- Parameters:
element- new element- Returns:
- true: if index of write position is below index of read position
-
put
public int put(E[] newElements, int length)
- Parameters:
newElements- new values to be addedlength- number of elements to be written- Returns:
- new index of read position
-
take
public E take()
- Returns:
- value at the head of the buffer
-
take
public int take(E[] into, int length)
- Parameters:
into- container to be written intolength- maximum length to be read- Returns:
- write position
-
-