Class MovingAverager


  • public class MovingAverager
    extends java.lang.Object
    Class for calculating a moving average.
    • Constructor Summary

      Constructors 
      Constructor Description
      MovingAverager​(int nValues)
      Creates a new MovingAverager.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(double value)
      Adds a new value to the ring buffer.
      double getAverage()
      Calculates and returns the average of the proviously added values.
      • Methods inherited from class java.lang.Object

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

      • MovingAverager

        public MovingAverager​(int nValues)
        Creates a new MovingAverager.
        Parameters:
        nValues - number of values to use for the moving average
    • Method Detail

      • add

        public void add​(double value)
        Adds a new value to the ring buffer.
        Parameters:
        value - the new value
      • getAverage

        public double getAverage()
        Calculates and returns the average of the proviously added values. Maximal number of previous values are defined by the initial nValues parameter of the contructor.
        Returns:
        the average value