Package org.jgroups.util
Class Average
- java.lang.Object
-
- org.jgroups.util.Average
-
- All Implemented Interfaces:
Streamable
- Direct Known Subclasses:
AverageMinMax
public class Average extends java.lang.Object implements Streamable
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
- Author:
- Bela Ban
-
-
Constructor Summary
Constructors Constructor Description Average()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends Average>
Tadd(long num)doubleaverage()voidclear()longcount()doublegetAverage()longgetCount()<T extends Average>
Tmerge(T other)Merges this average with another onevoidreadFrom(java.io.DataInput in)Read the state of the current object (including superclasses) from instream Note that the input stream must not be closedjava.lang.StringtoString()java.lang.StringtoString(java.util.concurrent.TimeUnit u)java.util.concurrent.TimeUnitunit()<T extends Average>
Tunit(java.util.concurrent.TimeUnit u)voidwriteTo(java.io.DataOutput out)Write the entire state of the current object (including superclasses) to outstream.
-
-
-
Method Detail
-
add
public <T extends Average> T add(long num)
-
merge
public <T extends Average> T merge(T other)
Merges this average with another one
-
getAverage
public double getAverage()
-
average
public double average()
-
getCount
public long getCount()
-
count
public long count()
-
unit
public java.util.concurrent.TimeUnit unit()
-
unit
public <T extends Average> T unit(java.util.concurrent.TimeUnit u)
-
clear
public void clear()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toString
public java.lang.String toString(java.util.concurrent.TimeUnit u)
-
writeTo
public void writeTo(java.io.DataOutput out) throws java.io.IOExceptionDescription 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:
java.io.IOException
-
readFrom
public void readFrom(java.io.DataInput in) throws java.io.IOExceptionDescription 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:
java.io.IOException
-
-