Package edu.wpi.first.wpiutil
Class CircularBuffer
- java.lang.Object
-
- edu.wpi.first.wpiutil.CircularBuffer
-
public class CircularBuffer extends Object
This is a simple circular buffer so we don't need to "bucket brigade" copy old values.
-
-
Constructor Summary
Constructors Constructor Description CircularBuffer(int size)Create a CircularBuffer with the provided size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFirst(double value)Push new value onto front of the buffer.voidaddLast(double value)Push new value onto back of the buffer.voidclear()Sets internal buffer contents to zero.doubleget(int index)Get the element at the provided index relative to the start of the buffer.doubleremoveFirst()Pop value at front of buffer.doubleremoveLast()Pop value at back of buffer.
-
-
-
Method Detail
-
addFirst
public void addFirst(double value)
Push new value onto front of the buffer. The value at the back is overwritten if the buffer is full.
-
addLast
public void addLast(double value)
Push new value onto back of the buffer. The value at the front is overwritten if the buffer is full.
-
removeFirst
public double removeFirst()
Pop value at front of buffer.- Returns:
- value at front of buffer
-
removeLast
public double removeLast()
Pop value at back of buffer.
-
clear
public void clear()
Sets internal buffer contents to zero.
-
get
public double get(int index)
Get the element at the provided index relative to the start of the buffer.- Returns:
- Element at index starting from front of buffer.
-
-