Class RingBuffer<T>

  • Type Parameters:
    T - type of objects to store

    public class RingBuffer<T>
    extends Object
    A special ring buffer implementation that allows unlimited writes keeping only a preset size of buffer, followed by reading of what was written in the order it was written ignoring what was overwritten when writing beyond the preset size. This means you always read the least recently written item. This data structure cannot be written to once reading has begun.
    • Field Detail

      • ringBuffer

        protected T[] ringBuffer
      • writeCursor

        protected int writeCursor
      • readCursor

        protected int readCursor
      • size

        protected int size
    • Constructor Detail

      • RingBuffer

        public RingBuffer​(int size)
    • Method Detail

      • write

        public void write​(T element)
      • read

        public T read()