Class Average

java.lang.Object
org.jgroups.util.Average
All Implemented Interfaces:
Streamable
Direct Known Subclasses:
AverageMinMax

public class Average extends 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
  • Field Details

    • avg

      protected double avg
    • count

      protected long count
    • unit

      protected TimeUnit unit
  • Constructor Details

    • Average

      public Average()
  • Method Details

    • 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 TimeUnit unit()
    • unit

      public <T extends Average> T unit(TimeUnit u)
    • clear

      public void clear()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public String toString(TimeUnit u)
    • writeTo

      public void writeTo(DataOutput out) throws IOException
      Description copied from interface: Streamable
      Write the entire state of the current object (including superclasses) to outstream. Note that the output stream must not be closed
      Specified by:
      writeTo in interface Streamable
      Throws:
      IOException
    • readFrom

      public void readFrom(DataInput in) throws IOException
      Description copied from interface: Streamable
      Read the state of the current object (including superclasses) from instream Note that the input stream must not be closed
      Specified by:
      readFrom in interface Streamable
      Throws:
      IOException