Class Measures

java.lang.Object
org.moeaframework.analysis.stream.Measures

public class Measures extends Object
Standard collection of measurement functions.

Implementation note: All functions assume the underlying stream contains at least one element, otherwise NoSuchElementException is thrown. This simplifies the interface since we don't need to return Optional when it's generally not necessary.

  • Method Details

    • count

      public static <T> Function<Stream<T>,Integer> count()
      Measures the number of items in the stream.
      Type Parameters:
      T - the type of the stream
      Returns:
      the number of items
    • sum

      public static <T extends Number> Function<Stream<T>,Double> sum()
      Computes the sum of all values in the stream.
      Type Parameters:
      T - the type of the stream
      Returns:
      the sum, or 0.0 if the stream is empty
    • min

      public static <T extends Comparable<T>> Function<Stream<T>,T> min()
      Measures the minimum value in the stream according to their natural order.
      Type Parameters:
      T - the type of the stream
      Returns:
      the minimum value
      Throws:
      NoSuchElementException - if the stream is empty
    • max

      public static <T extends Comparable<T>> Function<Stream<T>,T> max()
      Measures the maximum value in the stream according to their natural order.
      Type Parameters:
      T - the type of the stream
      Returns:
      the maximum value
      Throws:
      NoSuchElementException - if the stream is empty
    • average

      public static <T extends Number> Function<Stream<T>,Double> average()
      Computes the average of all values in the stream.
      Type Parameters:
      T - the type of the stream
      Returns:
      the average value
    • median

      public static <T extends Number> Function<Stream<T>,Double> median()
      Computes the median of all values in the stream.
      Type Parameters:
      T - the type of the stream
      Returns:
      the median value
    • percentile

      public static <T extends Number> Function<Stream<T>,Double> percentile(double percentile)
      Computes the percentile of all values in the stream.
      Type Parameters:
      T - the type of the stream
      Parameters:
      percentile - the percentile (e.g., 50.0 for the 50-th percentile)
      Returns:
      the percentile value
    • stats

      public static <T extends Number> Function<Stream<T>,org.apache.commons.math3.stat.descriptive.StatisticalSummary> stats()
      Computes statistics for the values in the stream.
      Type Parameters:
      T - the type of the stream
      Returns:
      the resulting statistics