Package io.pravega.common
Class SimpleMovingAverage
- java.lang.Object
-
- io.pravega.common.SimpleMovingAverage
-
@NotThreadSafe public class SimpleMovingAverage extends java.lang.ObjectHelps calculate simple moving averages for a number of values. Only the last values added to the series will be included in the calculation.
-
-
Constructor Summary
Constructors Constructor Description SimpleMovingAverage(int count)Creates a new instance of the SimpleMovingAverage class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int value)Adds the given value to the moving average.doublegetAverage(double defaultValue)Gets a value indicating the current moving average.voidreset()Clears the SimpleMovingAverage of any data.
-
-
-
Method Detail
-
add
public void add(int value)
Adds the given value to the moving average. If the moving average is already at capacity, this will overwrite the oldest value in the series.- Parameters:
value- The value to add.
-
reset
public void reset()
Clears the SimpleMovingAverage of any data.
-
getAverage
public double getAverage(double defaultValue)
Gets a value indicating the current moving average.- Parameters:
defaultValue- The default value to use.- Returns:
- The average, or defaultValue if there are no values recorded.
-
-