use of java.util.DoubleSummaryStatistics in project tutorials by eugenp.
the class EmployeeTest method whenApplySummaryStatistics_thenGetBasicStats.
@Test
public void whenApplySummaryStatistics_thenGetBasicStats() {
DoubleSummaryStatistics stats = empList.stream().mapToDouble(Employee::getSalary).summaryStatistics();
assertEquals(stats.getCount(), 3);
assertEquals(stats.getSum(), 600000.0, 0);
assertEquals(stats.getMin(), 100000.0, 0);
assertEquals(stats.getMax(), 300000.0, 0);
assertEquals(stats.getAverage(), 200000.0, 0);
}
use of java.util.DoubleSummaryStatistics in project eclipse-collections by eclipse.
the class AbstractRichIterableTestCase method summarizeFloat.
@Test
public void summarizeFloat() {
RichIterable<Integer> objects = this.newWith(1, 2, 3);
DoubleSummaryStatistics expected = objects.summarizeFloat(Integer::floatValue);
Assert.assertEquals(6.0d, expected.getSum(), 0.0);
Assert.assertEquals(3, expected.getCount());
}
use of java.util.DoubleSummaryStatistics in project eclipse-collections by eclipse.
the class RichIterable method summarizeDouble.
/**
* Returns the result of summarizing the value returned from applying the DoubleFunction to
* each element of the iterable.
* <p>
* <pre>
* DoubleSummaryStatistics stats =
* Lists.mutable.with(1, 2, 3).summarizeDouble(Integer::doubleValue);
* </pre>
*
* @since 8.0
*/
default DoubleSummaryStatistics summarizeDouble(DoubleFunction<? super T> function) {
DoubleSummaryStatistics stats = new DoubleSummaryStatistics();
this.each(each -> stats.accept(function.doubleValueOf(each)));
return stats;
}
use of java.util.DoubleSummaryStatistics in project eclipse-collections by eclipse.
the class InternalArrayIterate method summarizeFloat.
/**
* @since 8.0
*/
public static <T> DoubleSummaryStatistics summarizeFloat(T[] items, int size, FloatFunction<? super T> function) {
DoubleSummaryStatistics stats = new DoubleSummaryStatistics();
for (int i = 0; i < size; i++) {
T item = items[i];
stats.accept((double) function.floatValueOf(item));
}
return stats;
}
use of java.util.DoubleSummaryStatistics in project eclipse-collections by eclipse.
the class SerializableDoubleSummaryStatisticsTest method valuesEqual.
@Test
public void valuesEqual() {
SerializableDoubleSummaryStatistics with = SerializableDoubleSummaryStatistics.with(1.0, 2.0, 3.0);
DoubleSummaryStatistics without = new DoubleSummaryStatistics();
without.accept(1.0d);
without.accept(2.0d);
without.accept(3.0d);
Assert.assertTrue(with.valuesEqual(without));
}
Aggregations