Class RingBuffer<T>

java.lang.Object
org.craftercms.studio.impl.v2.utils.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 Details

    • ringBuffer

      protected T[] ringBuffer
    • writeCursor

      protected int writeCursor
    • readCursor

      protected int readCursor
    • size

      protected int size
  • Constructor Details

    • RingBuffer

      public RingBuffer(int size)
  • Method Details

    • write

      public void write(T element)
    • read

      public T read()