Class DoubleCircularBuffer


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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()  
      double[] get​(double[] into, int length)  
      double[] get​(double[] into, int readPos, int length)  
      double get​(int readPos)  
      static void main​(java.lang.String[] args)
      meant for testing/illustrating usage
      boolean put​(double element)
      add new element
      int put​(double[] newElements, int length)
      add multiple new elements
      int put​(double[] newElements, int startIndex, int length)
      add multiple new elements
      int remainingCapacity()  
      void reset()
      resets and clears buffer
      • Methods inherited from class java.lang.Object

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

      • DoubleCircularBuffer

        public DoubleCircularBuffer​(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)
        add new element
        Parameters:
        element - new element
        Returns:
        true
      • put

        public int put​(double[] newElements,
                       int length)
        add multiple new elements
        Parameters:
        newElements - array of new elements
        length - number of elements that are to be written from array
        Returns:
        true: write index is smaller than read index
      • put

        public int put​(double[] newElements,
                       int startIndex,
                       int length)
        add multiple new elements
        Parameters:
        newElements - array of new elements
        startIndex - 'null'
        length - number of elements that are to be written from array
        Returns:
        true: write index is smaller than read index
      • get

        public double get​(int readPos)
        Parameters:
        readPos - circular index (wraps around)
        Returns:
        the value
      • get

        public double[] get​(double[] into,
                            int length)
        Parameters:
        into - storage container
        length - number of elements to be read
        Returns:
        either into or newly allocated array containing the result
      • get

        public double[] get​(double[] into,
                            int readPos,
                            int length)
        Parameters:
        into - storage container
        readPos - circular index (wraps around)
        length - number of elements to be read
        Returns:
        either into or newly allocated array containing the result
      • main

        public static void main​(java.lang.String[] args)
        meant for testing/illustrating usage
        Parameters:
        args - the command line arguments