Class 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 Detail

      • RingBuffer

        public RingBuffer​(int capacity)
        Creates a new RingBuffer.
        Parameters:
        capacity - the capacity of this RingBuffer
    • 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)
      • clear

        public void clear()