Package org.eclipse.mosaic.lib.util
Class RingBuffer<T>
java.lang.Object
org.eclipse.mosaic.lib.util.RingBuffer<T>
- Type Parameters:
T
- The class of the buffers elements.
- All Implemented Interfaces:
Iterable<T>
Ring buffer implementation. Provides methods to add elements continuously to
this collection. If its capacity is exceeded, the oldest elements are replaced.
Adding a value and assessing a specific element via its index is accomplished in O(1).
Contents cannot be deleted actively.
Provides furthermore
iterator()
and spliterator()
for
Stream
support.-
Constructor Details
-
RingBuffer
public RingBuffer(int capacity) Creates a new RingBuffer.- Parameters:
capacity
- the capacity of thisRingBuffer
-
-
Method Details
-
size
public int size()Returns the size of ring buffer.- Returns:
- size of the ring buffer
-
add
Adds the to the ring buffer.- Parameters:
element
- the element to be added
-
get
-
spliterator
- Specified by:
spliterator
in interfaceIterable<T>
-
iterator
-
clear
public void clear()
-