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>
public class RingBuffer<T> extends Object implements 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 furthermoreiterator()
andspliterator()
forStream
support.
-
-
Constructor Summary
Constructors Constructor Description RingBuffer(int capacity)
Creates a new RingBuffer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(T element)
Adds the {@param element} to the ring buffer.void
clear()
T
get(int index)
Iterator<T>
iterator()
int
size()
Returns the size of ring buffer.Spliterator<T>
spliterator()
-
-
-
Constructor Detail
-
RingBuffer
public RingBuffer(int capacity)
Creates a new RingBuffer.- Parameters:
capacity
- the capacity of thisRingBuffer
-
-
Method Detail
-
size
public int size()
Returns the size of ring buffer.- Returns:
- size of the ring buffer
-
add
public void add(T element)
Adds the {@param element} to the ring buffer.- Parameters:
element
- the element to be added
-
get
public T get(int index)
-
spliterator
public Spliterator<T> spliterator()
- Specified by:
spliterator
in interfaceIterable<T>
-
clear
public void clear()
-
-