| 1 | /* | |
| 2 | * Copyright 2014-2026 Grzegorz Piwowarek, https://4comprehension.com/ | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * https://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package com.pivovarit.collectors; | |
| 17 | ||
| 18 | import java.util.ArrayList; | |
| 19 | import java.util.Collections; | |
| 20 | import java.util.List; | |
| 21 | import java.util.Set; | |
| 22 | import java.util.concurrent.CompletableFuture; | |
| 23 | import java.util.function.BiConsumer; | |
| 24 | import java.util.function.BinaryOperator; | |
| 25 | import java.util.function.Function; | |
| 26 | import java.util.function.Supplier; | |
| 27 | import java.util.stream.Collector; | |
| 28 | ||
| 29 | /** | |
| 30 | * @author Grzegorz Piwowarek | |
| 31 | */ | |
| 32 | sealed abstract class AbstractParallelCollector<T, A, R> | |
| 33 | implements Collector<T, List<CompletableFuture<A>>, R> | |
| 34 | permits AsyncParallelCollector, AsyncParallelStreamingCollector { | |
| 35 | ||
| 36 | protected final Dispatcher<A> dispatcher; | |
| 37 | protected final Function<? super T, ? extends A> task; | |
| 38 | ||
| 39 | protected AbstractParallelCollector(Function<? super T, ? extends A> task, Dispatcher<A> dispatcher) { | |
| 40 | this.task = task; | |
| 41 | this.dispatcher = dispatcher; | |
| 42 | } | |
| 43 | ||
| 44 | abstract Function<List<CompletableFuture<A>>, R> finalizer(); | |
| 45 | ||
| 46 | @Override | |
| 47 | public final Supplier<List<CompletableFuture<A>>> supplier() { | |
| 48 |
1
1. supplier : replaced return value with null for com/pivovarit/collectors/AbstractParallelCollector::supplier → KILLED |
return ArrayList::new; |
| 49 | } | |
| 50 | ||
| 51 | @Override | |
| 52 | public final BiConsumer<List<CompletableFuture<A>>, T> accumulator() { | |
| 53 |
1
1. accumulator : replaced return value with null for com/pivovarit/collectors/AbstractParallelCollector::accumulator → KILLED |
return (acc, e) -> { |
| 54 |
1
1. lambda$accumulator$0 : negated conditional → TIMED_OUT |
if (!dispatcher.wasStarted()) { |
| 55 |
1
1. lambda$accumulator$0 : removed call to com/pivovarit/collectors/Dispatcher::start → TIMED_OUT |
dispatcher.start(); |
| 56 | } | |
| 57 |
1
1. lambda$accumulator$1 : replaced return value with null for com/pivovarit/collectors/AbstractParallelCollector::lambda$accumulator$1 → KILLED |
acc.add(dispatcher.submit(() -> task.apply(e))); |
| 58 | }; | |
| 59 | } | |
| 60 | ||
| 61 | @Override | |
| 62 | public BinaryOperator<List<CompletableFuture<A>>> combiner() { | |
| 63 |
1
1. combiner : replaced return value with null for com/pivovarit/collectors/AbstractParallelCollector::combiner → KILLED |
return (left, right) -> { |
| 64 | throw new UnsupportedOperationException("using parallel stream with parallel collectors is not supported"); | |
| 65 | }; | |
| 66 | } | |
| 67 | ||
| 68 | @Override | |
| 69 | public final Function<List<CompletableFuture<A>>, R> finisher() { | |
| 70 |
1
1. finisher : replaced return value with null for com/pivovarit/collectors/AbstractParallelCollector::finisher → KILLED |
return list -> { |
| 71 |
1
1. lambda$finisher$0 : removed call to com/pivovarit/collectors/Dispatcher::stop → TIMED_OUT |
dispatcher.stop(); |
| 72 |
1
1. lambda$finisher$0 : replaced return value with null for com/pivovarit/collectors/AbstractParallelCollector::lambda$finisher$0 → KILLED |
return finalizer().apply(list); |
| 73 | }; | |
| 74 | } | |
| 75 | ||
| 76 | @Override | |
| 77 | public Set<Characteristics> characteristics() { | |
| 78 | return Collections.emptySet(); | |
| 79 | } | |
| 80 | } | |
Mutations | ||
| 48 |
1.1 |
|
| 53 |
1.1 |
|
| 54 |
1.1 |
|
| 55 |
1.1 |
|
| 57 |
1.1 |
|
| 63 |
1.1 |
|
| 70 |
1.1 |
|
| 71 |
1.1 |
|
| 72 |
1.1 |