public class FullRunningAverage extends Object implements RunningAverage, Serializable
A simple class that can keep track of a running average of a series of numbers. One can add to or remove from the series, as well as update a datum in the series. The class does not actually keep track of the series of values, just its running average, so it doesn't even matter if you remove/change a value that wasn't added.
Constructor and Description |
---|
FullRunningAverage() |
FullRunningAverage(int count,
double average) |
Modifier and Type | Method and Description |
---|---|
void |
addDatum(double datum) |
void |
changeDatum(double delta) |
double |
getAverage() |
int |
getCount() |
RunningAverage |
inverse() |
void |
removeDatum(double datum) |
String |
toString() |
public FullRunningAverage()
public FullRunningAverage(int count, double average)
public void addDatum(double datum)
addDatum
in interface RunningAverage
datum
- new item to add to the running averagepublic void removeDatum(double datum)
removeDatum
in interface RunningAverage
datum
- item to remove to the running averageIllegalStateException
- if count is 0public void changeDatum(double delta)
changeDatum
in interface RunningAverage
delta
- amount by which to change a datum in the running averageIllegalStateException
- if count is 0public int getCount()
getCount
in interface RunningAverage
public double getAverage()
getAverage
in interface RunningAverage
public RunningAverage inverse()
inverse
in interface RunningAverage
Copyright © 2008–2017 The Apache Software Foundation. All rights reserved.