Class CircularBuffer<T>
java.lang.Object
org.wpilib.util.container.CircularBuffer<T>
- Type Parameters:
T- Buffer element type.
This is a simple circular buffer so we don't need to "bucket brigade" copy old values.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidPush new value onto front of the buffer.voidPush new value onto back of the buffer.voidclear()Sets internal buffer contents to zero.get(int index) Get the element at the provided index relative to the start of the buffer.getFirst()Get value at front of buffer.getLast()Get value at back of buffer.Pop value at front of buffer.Pop value at back of buffer.voidresize(int size) Resizes internal buffer to given size.intsize()Returns number of elements in buffer.
-
Constructor Details
-
CircularBuffer
Create a CircularBuffer with the provided size.- Parameters:
size- Maximum number of buffer elements.
-
-
Method Details
-
size
-
getFirst
-
getLast
Get value at back of buffer.- Returns:
- value at back of buffer
- Throws:
IndexOutOfBoundsException- if the index is out of range (index < 0 || index >= size())
-
addFirst
-
addLast
-
removeFirst
Pop value at front of buffer.- Returns:
- value at front of buffer
- Throws:
IndexOutOfBoundsException- if the index is out of range (index < 0 || index >= size())
-
removeLast
Pop value at back of buffer.- Returns:
- value at back of buffer
- Throws:
IndexOutOfBoundsException- if the index is out of range (index < 0 || index >= size())
-
resize
Resizes internal buffer to given size.A new buffer is allocated because arrays are not resizable.
- Parameters:
size- New buffer size.
-
clear
Sets internal buffer contents to zero. -
get
-