8136686: Collectors.counting can use Collectors.summingLong to reduce boxing
Reviewed-by: psandoz
Contributed-by: Tagir Valeev <amaembo@gmail.com>
--- a/jdk/src/java.base/share/classes/java/util/stream/Collectors.java Wed Jul 05 20:50:41 2017 +0200
+++ b/jdk/src/java.base/share/classes/java/util/stream/Collectors.java Sat Sep 19 15:26:34 2015 +0200
@@ -504,7 +504,7 @@
*/
public static <T> Collector<T, ?, Long>
counting() {
- return reducing(0L, e -> 1L, Long::sum);
+ return summingLong(e -> 1L);
}
/**
--- a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/CountTest.java Wed Jul 05 20:50:41 2017 +0200
+++ b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/CountTest.java Sat Sep 19 15:26:34 2015 +0200
@@ -31,6 +31,7 @@
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 @@
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