Package org.jgroups.util
Class Average
java.lang.Object
org.jgroups.util.Average
- All Implemented Interfaces:
Streamable
- Direct Known Subclasses:
AverageMinMax
Maintains an approximation of an average of values. Done by keeping track of the number of samples, and computing
the new average as (count*avg + new-sample) / ++count. We reset the count if count*avg would lead to an overflow.
This class is not thread-safe and relies on external synchronization.
- Since:
- 3.4
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T extends Average>
Tadd(long num) doubleaverage()voidclear()longcount()doublelonggetCount()<T extends Average>
Tmerge(T other) Merges this average with another onevoidRead the state of the current object (including superclasses) from instream Note that the input stream must not be closedtoString()unit()<T extends Average>
TvoidwriteTo(DataOutput out) Write the entire state of the current object (including superclasses) to outstream.
-
Field Details
-
avg
protected double avg -
count
protected long count -
unit
-
-
Constructor Details
-
Average
public Average()
-
-
Method Details
-
add
-
merge
Merges this average with another one -
getAverage
public double getAverage() -
average
public double average() -
getCount
public long getCount() -
count
public long count() -
unit
-
unit
-
clear
public void clear() -
toString
-
toString
-
writeTo
Description copied from interface:StreamableWrite the entire state of the current object (including superclasses) to outstream. Note that the output stream must not be closed- Specified by:
writeToin interfaceStreamable- Throws:
IOException
-
readFrom
Description copied from interface:StreamableRead the state of the current object (including superclasses) from instream Note that the input stream must not be closed- Specified by:
readFromin interfaceStreamable- Throws:
IOException
-