Class StatisticsUtils


  • public class StatisticsUtils
    extends java.lang.Object
    Utilities for getting some basic statistics out of numerical data collections.
    Since:
    4.5.0
    • Constructor Summary

      Constructors 
      Constructor Description
      StatisticsUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double getAverage​(java.util.Collection<? extends java.lang.Number> list)
      Calculates the average from a collection of numeric values.
      static <T extends java.lang.Number & java.lang.Comparable<T>>
      T
      getMax​(java.util.Collection<T> list)
      Examine list of numbers to find the instance which has the highest value.
      static <T extends java.lang.Number & java.lang.Comparable<T>>
      T
      getMin​(java.util.Collection<T> list)
      Examine list of numbers to find the instance which has the lowest value.
      static <T extends java.lang.Number>
      java.util.Map<java.lang.Double,​T>
      getPercentiles​(java.util.Collection<? extends T> values, double... percentiles)
      Gets percentile values from a collection of numeric values.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StatisticsUtils

        public StatisticsUtils()
    • Method Detail

      • getAverage

        public static double getAverage​(java.util.Collection<? extends java.lang.Number> list)
        Calculates the average from a collection of numeric values.
        Parameters:
        list - List of numbers to average against
        Returns:
        Zero if the list is empty, otherwise the average of the values inside the list
      • getMax

        public static <T extends java.lang.Number & java.lang.Comparable<T>> T getMax​(java.util.Collection<T> list)
        Examine list of numbers to find the instance which has the highest value. Because of the need to use the compareTo, the provided list must be generic to the specific type of Number contained, and not the generic Number itself.
        Type Parameters:
        T - The type of number contained within the list
        Parameters:
        list - List to examine for high value
        Returns:
        The instance which contains the highest value using the Comparable.compareTo(Object)
        Throws:
        java.lang.IllegalArgumentException - if the list is empty
      • getMin

        public static <T extends java.lang.Number & java.lang.Comparable<T>> T getMin​(java.util.Collection<T> list)
        Examine list of numbers to find the instance which has the lowest value. Because of the need to use the compareTo, the provided list must be generic to the specific type of Number contained, and not the generic Number itself.
        Type Parameters:
        T - The type of number contained within the list
        Parameters:
        list - List to examine for high value
        Returns:
        The instance which contains the highest value using the Comparable.compareTo(Object)
        Throws:
        java.lang.IllegalArgumentException - if the list is empty
      • getPercentiles

        public static <T extends java.lang.Number> java.util.Map<java.lang.Double,​T> getPercentiles​(java.util.Collection<? extends T> values,
                                                                                                          double... percentiles)
        Gets percentile values from a collection of numeric values. This function is NOT dependent on the collection already being sorted. This function accepts any decimal percentile between zero and one hundred, but requests for 99.9 and 99.99 may return the same result if the sample set is not large or varied enough. There is no attempt to extrapolate trends, thus only real samples are returned.

        The returned map's keys correspond exactly to the percentiles provided. Iterating over the returned map will iterate in order of the requested percentiles as well.

        Type Parameters:
        T - Specific number type contained in the collection
        Parameters:
        values - A non-empty collection of numbers to examine for percentiles
        percentiles - Percentiles requested, any decimal values between 0 and 100 (inclusive)
        Returns:
        Map with keys being the percentiles requested in the second argument