Package com.treemap.swing.voronoi
Class MovingAverager
java.lang.Object
com.treemap.swing.voronoi.MovingAverager
Class for calculating a moving average.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(double value) Adds a new value to the ring buffer.double
Calculates and returns the average of the proviously added values.
-
Constructor Details
-
MovingAverager
public MovingAverager(int nValues) Creates a new MovingAverager.- Parameters:
nValues
- number of values to use for the moving average
-
-
Method Details
-
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
-