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 furthermore iterator() and spliterator() for Stream support.
  • Constructor Details

    • RingBuffer

      public RingBuffer(int capacity)
      Creates a new RingBuffer.
      Parameters:
      capacity - the capacity of this RingBuffer
  • Method Details

    • size

      public int size()
      Returns the size of ring buffer.
      Returns:
      size of the ring buffer
    • add

      public void add(T element)
      Adds the 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 interface Iterable<T>
    • iterator

      @Nonnull public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • clear

      public void clear()