/** * Returns a {@code DoubleCollector} that produces the sum of the input * elements. If no elements are present, the result is 0.0. * * @return a {@code DoubleCollector} that produces the sum of the input * elements */ static DoubleCollector<?, Double> summing() { // Using DoubleSummaryStatistics as Kahan algorithm is implemented there return summarizing().andThen(DoubleSummaryStatistics::getSum); }
/** * Returns a {@code DoubleCollector} that produces the arithmetic mean of * the input elements or an empty optional if no elements are collected. * * @return a {@code DoubleCollector} that produces the arithmetic mean of * the input elements * @since 0.3.7 */ static DoubleCollector<?, OptionalDouble> averaging() { return summarizing().andThen( dss -> dss.getCount() == 0L ? OptionalDouble.empty() : OptionalDouble.of(dss.getAverage())); }