Class DoubleRingBuffer


  • public class DoubleRingBuffer
    extends java.lang.Object
    simple circular ring buffer implementation for double type (with read/write position)
    Author:
    rstein
    • Constructor Summary

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

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

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

      • DoubleRingBuffer

        public DoubleRingBuffer​(int capacity)
        Parameters:
        capacity - maximum capacity of buffer
    • Method Detail

      • reset

        public void reset()
        resets and clears buffer
      • available

        public int available()
        Returns:
        number of available buffer elements
      • remainingCapacity

        public int remainingCapacity()
        Returns:
        number of elements that can be written before buffer wraps-around
      • put

        public boolean put​(double element)
        Parameters:
        element - new element
        Returns:
        true: read index is above write index
      • put

        public int put​(double[] newElements,
                       int length)
        Parameters:
        newElements - new elements to be added
        length - number of elements to be added
        Returns:
        number of elements added
      • take

        public double take()
        Returns:
        element at head of buffer
      • take

        public int take​(double[] into,
                        int length)
        Parameters:
        into - storage container
        length - how many elements are to be retrieved
        Returns:
        n elements at the head of the buffer