Class Measures
java.lang.Object
org.moeaframework.analysis.stream.Measures
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 Summary
Modifier and TypeMethodDescriptionaverage()
Computes the average of all values in the stream.count()
Measures the number of items in the stream.static <T extends Comparable<T>>
Function<Stream<T>,T> max()
Measures the maximum value in the stream according to their natural order.median()
Computes the median of all values in the stream.static <T extends Comparable<T>>
Function<Stream<T>,T> min()
Measures the minimum value in the stream according to their natural order.percentile
(double percentile) Computes the percentile of all values in the stream.static <T extends Number>
Function<Stream<T>,org.apache.commons.math3.stat.descriptive.StatisticalSummary> stats()
Computes statistics for the values in the stream.sum()
Computes the sum of all values in the stream.
-
Method Details
-
count
Measures the number of items in the stream.- Type Parameters:
T
- the type of the stream- Returns:
- the number of items
-
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
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
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
Computes the average of all values in the stream.- Type Parameters:
T
- the type of the stream- Returns:
- the average value
-
median
Computes the median of all values in the stream.- Type Parameters:
T
- the type of the stream- Returns:
- the median value
-
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
-