8136686: Collectors.counting can use Collectors.summingLong to reduce boxing
Reviewed-by: psandoz
This commit is contained in:
parent
2a12715485
commit
94ba18f8b4
@ -504,7 +504,7 @@ public final class Collectors {
|
|||||||
*/
|
*/
|
||||||
public static <T> Collector<T, ?, Long>
|
public static <T> Collector<T, ?, Long>
|
||||||
counting() {
|
counting() {
|
||||||
return reducing(0L, e -> 1L, Long::sum);
|
return summingLong(e -> 1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,6 +31,7 @@ package org.openjdk.tests.java.util.stream;
|
|||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.DoubleStream;
|
import java.util.stream.DoubleStream;
|
||||||
import java.util.stream.DoubleStreamTestDataProvider;
|
import java.util.stream.DoubleStreamTestDataProvider;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
@ -61,6 +62,12 @@ public class CountTest extends OpTestCase {
|
|||||||
expectedResult(expectedCount).
|
expectedResult(expectedCount).
|
||||||
exercise();
|
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
|
// Test with stateful distinct op that is a barrier or lazy
|
||||||
// depending if source is not already distinct and encounter order is
|
// depending if source is not already distinct and encounter order is
|
||||||
// preserved or not
|
// preserved or not
|
||||||
|
Loading…
x
Reference in New Issue
Block a user