Class StatisticsAccumulator

java.lang.Object
org.glassfish.pfl.tf.timer.spi.StatisticsAccumulator

public class StatisticsAccumulator extends Object

Author:
Hemanth Puttaswamy

StatisticsAccumulator accumulates the samples provided by the user and computes the value of minimum, maximum, sum and sample square sum. When the StatisticMonitoredAttribute calls getValue(), it will compute all the statistics for the collected samples (Which are Minimum, Maximum, Average, StandardDeviation) and provides a nice printable record as a String. Users can easily extend this class and provide the implementation of toString() method to format the stats as desired. By default all the stats are printed in a single line.

  • Constructor Details

    • StatisticsAccumulator

      public StatisticsAccumulator(String unit)
      Construct the Statistics Accumulator by providing the unit as a String. The examples of units are "Hours", "Minutes", "Seconds", "MilliSeconds", "Micro Seconds" etc.,

      Parameters:
      unit - a String representing the units for the samples collected
  • Method Details

    • unit

      public String unit()
    • count

      public long count()
    • min

      public double min()
    • max

      public double max()
    • average

      public double average()
    • standardDeviation

      public double standardDeviation()
    • sample

      public void sample(double value)
    • getStats

      public Statistics getStats()
    • augment

      public void augment(StatisticsAccumulator acc)
    • getValue

      public String getValue()
      Computes the Standard Statistic Results based on the samples collected so far and provides the complete value as a formatted String
    • toString

      public String toString()
      Users can extend StatisticsAccumulator to provide the complete Stats in the format they prefer, if the default format doesn't suffice.
      Overrides:
      toString in class Object
    • clearState

      public void clearState()
      Clears the samples and starts fresh on new samples.
    • unitTestValidate

      public void unitTestValidate(String expectedUnit, double expectedMin, double expectedMax, long expectedSampleCount, double expectedAverage, double expectedStandardDeviation)
      This is an internal API to test StatisticsAccumulator...