8136686: Collectors.counting can use Collectors.summingLong to reduce boxing

Reviewed-by: psandoz
This commit is contained in:
Tagir Valeev 2015-09-19 15:26:34 +02:00 committed by Paul Sandoz
parent 2a12715485
commit 94ba18f8b4
2 changed files with 8 additions and 1 deletions

View File

@ -504,7 +504,7 @@ public final class Collectors {
*/
public static <T> Collector<T, ?, Long>
counting() {
return reducing(0L, e -> 1L, Long::sum);
return summingLong(e -> 1L);
}
/**

View File

@ -31,6 +31,7 @@ package org.openjdk.tests.java.util.stream;
import java.util.HashSet;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.DoubleStream;
import java.util.stream.DoubleStreamTestDataProvider;
import java.util.stream.IntStream;
@ -61,6 +62,12 @@ public class CountTest extends OpTestCase {
expectedResult(expectedCount).
exercise();
// Test counting collector
withData(data).
terminal(s -> s, s -> s.collect(Collectors.counting())).
expectedResult(expectedCount).
exercise();
// Test with stateful distinct op that is a barrier or lazy
// depending if source is not already distinct and encounter order is
// preserved or not