Class RingBuffer<E>

  • Type Parameters:
    E - the generic Object to be stored

    public class RingBuffer<E>
    extends java.lang.Object
    simple circular ring buffer implementation for generic Object type (with read/write position)
    Author:
    rstein
    • Constructor Summary

      Constructors 
      Constructor Description
      RingBuffer​(int capacity)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()  
      boolean put​(E element)
      add new element
      int put​(E[] newElements, int length)  
      int remainingCapacity()  
      void reset()
      clear all data and resets buffer
      E take()  
      int take​(E[] into, int length)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RingBuffer

        public RingBuffer​(int capacity)
        Parameters:
        capacity - of the buffer
    • Method Detail

      • reset

        public void reset()
        clear all data and resets buffer
      • available

        public int available()
        Returns:
        number of values that are already stored in buffer
      • remainingCapacity

        public int remainingCapacity()
        Returns:
        number of values that can be stored before the buffer is full and rolls over
      • put

        public boolean put​(E element)
        add new element
        Parameters:
        element - new element
        Returns:
        true: if index of write position is below index of read position
      • put

        public int put​(E[] newElements,
                       int length)
        Parameters:
        newElements - new values to be added
        length - number of elements to be written
        Returns:
        new index of read position
      • take

        public E take()
        Returns:
        value at the head of the buffer
      • take

        public int take​(E[] into,
                        int length)
        Parameters:
        into - container to be written into
        length - maximum length to be read
        Returns:
        write position