public class Average extends Object
Using the maxSamples can be used to implement something like a sliding avarage as the value is reset (computed) once the counter hits maxSamples.
Constructor and Description |
---|
Average()
Creates a new average which averages up to
DEFAULT_MAX_SAMPLES and then computes the effective
avarage and resets the counter to 1 using that value. |
Average(long maxSamples)
Creates a new average which averages up to maxSamples and then computes the effective
avarage and resets the counter to 1 using that value.
|
Modifier and Type | Method and Description |
---|---|
void |
addValue(double value)
Adds the given value to the set of values on which the average is based.
|
void |
addValue(long value)
Adds the given value to the set of values on which the average is based.
|
void |
addValues(long numberOfValues,
double sumOfValue)
Adds the given number of values to the counter and increments the sum by the given delta.
|
double |
getAndClear()
Returns the average just like
getAvg() but then resets the internal buffers to zero. |
double |
getAvg()
Returns the average of the added values.
|
long |
getCount()
Returns the number of total values inserted in the average.
|
long |
getSampleCount()
Returns the number of values used to compute the average.
|
String |
toString() |
public Average()
DEFAULT_MAX_SAMPLES
and then computes the effective
avarage and resets the counter to 1 using that value.public Average(long maxSamples)
public void addValue(long value)
If the sum of all values is greater as Double.MAX_VALUE / 2 or the count of all values is greater as Long.Max_VALUE / 2, the average is resetted.
value
- to value to add to the averagepublic void addValue(double value)
If the sum of all values is greater as Double.MAX_VALUE / 2 or the count of all values is greater as Long.Max_VALUE / 2, the average is resetted.
value
- to value to add to the averagepublic void addValues(long numberOfValues, double sumOfValue)
numberOfValues
- the number of values to addsumOfValue
- the total sum of the values to addpublic double getAvg()
Returns the sliding average of the last 100 values
public double getAndClear()
getAvg()
but then resets the internal buffers to zero.public long getSampleCount()
public long getCount()
Copyright © 2018. All rights reserved.