org.apache.jorphan.math

## Class StatCalculator<T extends java.lang.Number & java.lang.Comparable<? super T>>

- java.lang.Object
- - org.apache.jorphan.math.StatCalculator<T>

- Type Parameters:
    `T` - type parameter for the calculator
  Direct Known Subclasses:
    StatCalculatorInteger, StatCalculatorLong

      public abstract class StatCalculator<T extends java.lang.Number & java.lang.Comparable<? super T>>
      extends java.lang.Object

  This class serves as a way to calculate the median, max, min etc. of a list of values. It is not threadsafe.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `StatCalculator(T zero, T min, T max)` This constructor is used to set up particular values for the generic class instance.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addAll(StatCalculator<T> calc)`
    `void` | `addBytes(long newValue)` Add to received bytes
    `void` | `addSentBytes(long newValue)` Add to sent bytes
    `void` | `addValue(T val)` Add a single value (normally elapsed time)
    `void` | `addValue(T val, long sampleCount)` Update the calculator with the value for an aggregated sample.
    `void` | `clear()`
    `protected abstract T` | `divide(T val, int n)`
    `protected abstract T` | `divide(T val, long n)`
    `long` | `getCount()`
    `java.util.Map<java.lang.Number,java.lang.Number[]>` | `getDistribution()` Returns the distribution of the values in the list.
    `T` | `getMax()`
    `double` | `getMean()`
    `T` | `getMedian()`
    `T` | `getMin()`
    `T` | `getPercentPoint(double percent)` Get the value which %percent% of the values are less than.
    `T` | `getPercentPoint(float percent)` Get the value which %percent% of the values are less than.
    `double` | `getStandardDeviation()`
    `double` | `getSum()`
    `long` | `getTotalBytes()`
    `long` | `getTotalSentBytes()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### StatCalculator

          public StatCalculator(T zero,
                                T min,
                                T max)

      This constructor is used to set up particular values for the generic class instance.
      Parameters:
        `zero` - - value to return for Median and PercentPoint if there are no values
        `min` - - value to return for minimum if there are no values
        `max` - - value to return for maximum if there are no values

  - ### Method Detail

    - #### clear

          public void clear()

    - #### addBytes

          public void addBytes(long newValue)

      Add to received bytes
      Parameters:
        `newValue` - number of newly received bytes

    - #### addSentBytes

          public void addSentBytes(long newValue)

      Add to sent bytes
      Parameters:
        `newValue` - number of newly sent bytes

    - #### addAll

          public void addAll(StatCalculator<T> calc)

    - #### getMedian

          public T getMedian()

    - #### getTotalBytes

          public long getTotalBytes()

    - #### getTotalSentBytes

          public long getTotalSentBytes()

    - #### getPercentPoint

          public T getPercentPoint(float percent)

      Get the value which %percent% of the values are less than. This works just like median (where median represents the 50% point). A typical desire is to see the 90% point - the value that 90% of the data points are below, the remaining 10% are above.
      Parameters:
        `percent` - number representing the wished percent (between `0` and `1.0`)
      Returns:
        number of values less than the percentage

    - #### getPercentPoint

          public T getPercentPoint(double percent)

      Get the value which %percent% of the values are less than. This works just like median (where median represents the 50% point). A typical desire is to see the 90% point - the value that 90% of the data points are below, the remaining 10% are above.
      Parameters:
        `percent` - number representing the wished percent (between `0` and `1.0`)
      Returns:
        the value which %percent% of the values are less than

    - #### getDistribution

          public java.util.Map<java.lang.Number,java.lang.Number[]> getDistribution()

      Returns the distribution of the values in the list.
      Returns:
        map containing either Integer or Long keys; entries are a Number array containing the key and the [Integer] count. TODO - why is the key value also stored in the entry array? See Bug 53825

    - #### getMean

          public double getMean()

    - #### getStandardDeviation

          public double getStandardDeviation()

    - #### getMin

          public T getMin()

    - #### getMax

          public T getMax()

    - #### getCount

          public long getCount()

    - #### getSum

          public double getSum()

    - #### divide

          protected abstract T divide(T val,
                                      int n)

    - #### divide

          protected abstract T divide(T val,
                                      long n)

    - #### addValue

          public void addValue(T val,
                               long sampleCount)

      Update the calculator with the value for an aggregated sample.
      Parameters:
        `val` - the aggregate value, normally the elapsed time
        `sampleCount` - the number of samples contributing to the aggregate value

    - #### addValue

          public void addValue(T val)

      Add a single value (normally elapsed time)
      Parameters:
        `val` - the value to add, which should correspond with a single sample
      See Also:
        `addValue(Number, long)`

Copyright © 1998-2018 Apache Software Foundation. All Rights Reserved.