@Override public MonetarySummaryStatistics combine(MonetarySummaryStatistics summaryStatistics) { Objects.requireNonNull(summaryStatistics); if (!equals(summaryStatistics)) { return this; } min = MonetaryFunctions.min(min, summaryStatistics.getMin()); max = MonetaryFunctions.max(max, summaryStatistics.getMax()); sum = sum.add(summaryStatistics.getSum()); count += summaryStatistics.getCount(); average = sum.divide(count); return this; }
@Test public void summarizingMonetaryTest() { MonetarySummaryStatistics summary = currenciesToSummary() .filter(isCurrency(BRAZILIAN_REAL)) .collect(summarizingMonetary(BRAZILIAN_REAL)); assertEquals(8L, summary.getCount()); assertEquals(0L, summary.getMin().getNumber().longValue()); assertEquals(10L, summary.getMax().getNumber().longValue()); assertEquals(16L, summary.getSum().getNumber().longValue()); assertEquals(2L, summary.getAverage().getNumber().longValue()); }