|
|
|
@ -222,7 +222,7 @@ public final class Collectors {
|
|
|
|
|
* {@code Collection}, in encounter order
|
|
|
|
|
*/
|
|
|
|
|
public static <T, C extends Collection<T>>
|
|
|
|
|
Collector<T, ?, C> toCollection(Supplier<C> collectionFactory) {
|
|
|
|
|
Collector<T, C, C> toCollection(Supplier<C> collectionFactory) {
|
|
|
|
|
return new CollectorImpl<>(collectionFactory, Collection::add,
|
|
|
|
|
(r1, r2) -> { r1.addAll(r2); return r1; },
|
|
|
|
|
CH_ID);
|
|
|
|
@ -239,10 +239,10 @@ public final class Collectors {
|
|
|
|
|
* {@code List}, in encounter order
|
|
|
|
|
*/
|
|
|
|
|
public static <T>
|
|
|
|
|
Collector<T, ?, List<T>> toList() {
|
|
|
|
|
Collector<T, ArrayList<Object>, List<T>> toList() {
|
|
|
|
|
return new CollectorImpl<>(ArrayList::new, List::add,
|
|
|
|
|
(left, right) -> { left.addAll(right); return left; },
|
|
|
|
|
CH_ID);
|
|
|
|
|
(left, right) -> { left.addAll(right); return left; },
|
|
|
|
|
CH_ID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -257,7 +257,7 @@ public final class Collectors {
|
|
|
|
|
* @since 10
|
|
|
|
|
*/
|
|
|
|
|
public static <T>
|
|
|
|
|
Collector<T, ?, List<T>> toUnmodifiableList() {
|
|
|
|
|
Collector<T, ArrayList<Object>, List<T>> toUnmodifiableList() {
|
|
|
|
|
return new CollectorImpl<>(ArrayList::new, List::add,
|
|
|
|
|
(left, right) -> { left.addAll(right); return left; },
|
|
|
|
|
list -> {
|
|
|
|
@ -286,7 +286,7 @@ public final class Collectors {
|
|
|
|
|
* {@code Set}
|
|
|
|
|
*/
|
|
|
|
|
public static <T>
|
|
|
|
|
Collector<T, ?, Set<T>> toSet() {
|
|
|
|
|
Collector<T, HashSet<Object>, Set<T>> toSet() {
|
|
|
|
|
return new CollectorImpl<>(HashSet::new, Set::add,
|
|
|
|
|
(left, right) -> {
|
|
|
|
|
if (left.size() < right.size()) {
|
|
|
|
@ -315,7 +315,7 @@ public final class Collectors {
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
public static <T>
|
|
|
|
|
Collector<T, ?, Set<T>> toUnmodifiableSet() {
|
|
|
|
|
Collector<T, HashSet<Object>, Set<T>> toUnmodifiableSet() {
|
|
|
|
|
return new CollectorImpl<>(HashSet::new, Set::add,
|
|
|
|
|
(left, right) -> {
|
|
|
|
|
if (left.size() < right.size()) {
|
|
|
|
@ -335,7 +335,7 @@ public final class Collectors {
|
|
|
|
|
* @return a {@code Collector} that concatenates the input elements into a
|
|
|
|
|
* {@code String}, in encounter order
|
|
|
|
|
*/
|
|
|
|
|
public static Collector<CharSequence, ?, String> joining() {
|
|
|
|
|
public static Collector<CharSequence, StringBuilder, String> joining() {
|
|
|
|
|
return new CollectorImpl<>(
|
|
|
|
|
StringBuilder::new, StringBuilder::append,
|
|
|
|
|
(r1, r2) -> {
|
|
|
|
@ -353,7 +353,7 @@ public final class Collectors {
|
|
|
|
|
* @return A {@code Collector} which concatenates CharSequence elements,
|
|
|
|
|
* separated by the specified delimiter, in encounter order
|
|
|
|
|
*/
|
|
|
|
|
public static Collector<CharSequence, ?, String> joining(CharSequence delimiter) {
|
|
|
|
|
public static Collector<CharSequence, StringJoiner, String> joining(CharSequence delimiter) {
|
|
|
|
|
return joining(delimiter, "", "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -370,7 +370,7 @@ public final class Collectors {
|
|
|
|
|
* @return A {@code Collector} which concatenates CharSequence elements,
|
|
|
|
|
* separated by the specified delimiter, in encounter order
|
|
|
|
|
*/
|
|
|
|
|
public static Collector<CharSequence, ?, String> joining(CharSequence delimiter,
|
|
|
|
|
public static Collector<CharSequence, StringJoiner, String> joining(CharSequence delimiter,
|
|
|
|
|
CharSequence prefix,
|
|
|
|
|
CharSequence suffix) {
|
|
|
|
|
return new CollectorImpl<>(
|
|
|
|
@ -428,7 +428,7 @@ public final class Collectors {
|
|
|
|
|
* elements and provides the mapped results to the downstream collector
|
|
|
|
|
*/
|
|
|
|
|
public static <T, U, A, R>
|
|
|
|
|
Collector<T, ?, R> mapping(Function<? super T, ? extends U> mapper,
|
|
|
|
|
Collector<T, A, R> mapping(Function<? super T, ? extends U> mapper,
|
|
|
|
|
Collector<? super U, A, R> downstream) {
|
|
|
|
|
BiConsumer<A, ? super U> downstreamAccumulator = downstream.accumulator();
|
|
|
|
|
return new CollectorImpl<>(downstream.supplier(),
|
|
|
|
@ -473,7 +473,7 @@ public final class Collectors {
|
|
|
|
|
* @since 9
|
|
|
|
|
*/
|
|
|
|
|
public static <T, U, A, R>
|
|
|
|
|
Collector<T, ?, R> flatMapping(Function<? super T, ? extends Stream<? extends U>> mapper,
|
|
|
|
|
Collector<T, A, R> flatMapping(Function<? super T, ? extends Stream<? extends U>> mapper,
|
|
|
|
|
Collector<? super U, A, R> downstream) {
|
|
|
|
|
BiConsumer<A, ? super U> downstreamAccumulator = downstream.accumulator();
|
|
|
|
|
return new CollectorImpl<>(downstream.supplier(),
|
|
|
|
@ -904,9 +904,8 @@ public final class Collectors {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new CollectorImpl<>(
|
|
|
|
|
OptionalBox::new, OptionalBox::accept,
|
|
|
|
|
OptionalBox::new, Consumer<T>::accept,
|
|
|
|
|
(a, b) -> {
|
|
|
|
|
if (b.present) a.accept(b.value);
|
|
|
|
|
return a;
|
|
|
|
@ -952,7 +951,7 @@ public final class Collectors {
|
|
|
|
|
* @see #reducing(BinaryOperator)
|
|
|
|
|
*/
|
|
|
|
|
public static <T, U>
|
|
|
|
|
Collector<T, ?, U> reducing(U identity,
|
|
|
|
|
Collector<T, U[], U> reducing(U identity,
|
|
|
|
|
Function<? super T, ? extends U> mapper,
|
|
|
|
|
BinaryOperator<U> op) {
|
|
|
|
|
return new CollectorImpl<>(
|
|
|
|
@ -1102,7 +1101,7 @@ public final class Collectors {
|
|
|
|
|
* @see #groupingByConcurrent(Function, Supplier, Collector)
|
|
|
|
|
*/
|
|
|
|
|
public static <T, K, D, A, M extends Map<K, D>>
|
|
|
|
|
Collector<T, ?, M> groupingBy(Function<? super T, ? extends K> classifier,
|
|
|
|
|
Collector<T, Map<K,A>, M> groupingBy(Function<? super T, ? extends K> classifier,
|
|
|
|
|
Supplier<M> mapFactory,
|
|
|
|
|
Collector<? super T, A, D> downstream) {
|
|
|
|
|
Supplier<A> downstreamSupplier = downstream.supplier();
|
|
|
|
@ -1260,7 +1259,7 @@ public final class Collectors {
|
|
|
|
|
* @see #groupingBy(Function, Supplier, Collector)
|
|
|
|
|
*/
|
|
|
|
|
public static <T, K, A, D, M extends ConcurrentMap<K, D>>
|
|
|
|
|
Collector<T, ?, M> groupingByConcurrent(Function<? super T, ? extends K> classifier,
|
|
|
|
|
Collector<T, ConcurrentMap<K,A>, M> groupingByConcurrent(Function<? super T, ? extends K> classifier,
|
|
|
|
|
Supplier<M> mapFactory,
|
|
|
|
|
Collector<? super T, A, D> downstream) {
|
|
|
|
|
Supplier<A> downstreamSupplier = downstream.supplier();
|
|
|
|
@ -1438,7 +1437,7 @@ public final class Collectors {
|
|
|
|
|
* @see #toConcurrentMap(Function, Function)
|
|
|
|
|
*/
|
|
|
|
|
public static <T, K, U>
|
|
|
|
|
Collector<T, ?, Map<K,U>> toMap(Function<? super T, ? extends K> keyMapper,
|
|
|
|
|
Collector<T, Map<K,U>, Map<K,U>> toMap(Function<? super T, ? extends K> keyMapper,
|
|
|
|
|
Function<? super T, ? extends U> valueMapper) {
|
|
|
|
|
return new CollectorImpl<>(HashMap::new,
|
|
|
|
|
uniqKeysMapAccumulator(keyMapper, valueMapper),
|
|
|
|
|