| 1 | package com.pivovarit.collectors; | |
| 2 | ||
| 3 | import java.util.List; | |
| 4 | import java.util.Objects; | |
| 5 | import java.util.concurrent.CompletableFuture; | |
| 6 | import java.util.concurrent.Executor; | |
| 7 | import java.util.function.Function; | |
| 8 | import java.util.stream.Collector; | |
| 9 | import java.util.stream.Stream; | |
| 10 | ||
| 11 | /** | |
| 12 | * An umbrella class exposing static factory methods for instantiating parallel {@link Collector}s | |
| 13 | * | |
| 14 | * @author Grzegorz Piwowarek | |
| 15 | */ | |
| 16 | public final class ParallelCollectors { | |
| 17 | ||
| 18 | private ParallelCollectors() { | |
| 19 | } | |
| 20 | ||
| 21 | /** | |
| 22 | * A convenience {@link Collector} used for executing parallel computations using Virtual Threads | |
| 23 | * and returning them as a {@link CompletableFuture} containing a result of the application of the user-provided {@link Collector}. | |
| 24 | * | |
| 25 | * <br> | |
| 26 | * Example: | |
| 27 | * <pre>{@code | |
| 28 | * CompletableFuture<List<String>> result = Stream.of(1, 2, 3) | |
| 29 | * .collect(parallel(i -> foo(i), toList())); | |
| 30 | * }</pre> | |
| 31 | * | |
| 32 | * @param mapper a transformation to be performed in parallel | |
| 33 | * @param collector the {@code Collector} describing the reduction | |
| 34 | * @param <T> the type of the collected elements | |
| 35 | * @param <R> the result returned by {@code mapper} | |
| 36 | * @param <RR> the reduction result {@code collector} | |
| 37 | * | |
| 38 | * @return a {@code Collector} which collects all processed elements into a user-provided mutable {@code Collection} in parallel | |
| 39 | * | |
| 40 | * @since 3.0.0 | |
| 41 | */ | |
| 42 | public static <T, R, RR> Collector<T, ?, CompletableFuture<RR>> parallel(Function<? super T, ? extends R> mapper, Collector<R, ?, RR> collector) { | |
| 43 | Objects.requireNonNull(collector, "collector cannot be null"); | |
| 44 |
2
1. lambda$parallel$0 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$0 → KILLED 2. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED |
return Factory.collecting(s -> s.collect(collector), mapper); |
| 45 | } | |
| 46 | ||
| 47 | /** | |
| 48 | * A convenience {@link Collector} used for executing parallel computations using Virtual Threads | |
| 49 | * and returning them as a {@link CompletableFuture} containing a result of the application of the user-provided {@link Collector}. | |
| 50 | * | |
| 51 | * <br> | |
| 52 | * Example: | |
| 53 | * <pre>{@code | |
| 54 | * CompletableFuture<List<String>> result = Stream.of(1, 2, 3) | |
| 55 | * .collect(parallel(i -> foo(i), toList(), executor, 2)); | |
| 56 | * }</pre> | |
| 57 | * | |
| 58 | * @param mapper a transformation to be performed in parallel | |
| 59 | * @param collector the {@code Collector} describing the reduction | |
| 60 | * @param <T> the type of the collected elements | |
| 61 | * @param <R> the result returned by {@code mapper} | |
| 62 | * @param <RR> the reduction result {@code collector} | |
| 63 | * @param parallelism the max parallelism level | |
| 64 | * | |
| 65 | * @return a {@code Collector} which collects all processed elements into a user-provided mutable {@code Collection} in parallel | |
| 66 | * | |
| 67 | * @since 3.2.0 | |
| 68 | */ | |
| 69 | public static <T, R, RR> Collector<T, ?, CompletableFuture<RR>> parallel(Function<? super T, ? extends R> mapper, Collector<R, ?, RR> collector, int parallelism) { | |
| 70 | Objects.requireNonNull(collector, "collector cannot be null"); | |
| 71 |
2
1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED 2. lambda$parallel$1 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$1 → KILLED |
return Factory.collecting(s -> s.collect(collector), mapper, Options.parallelism(parallelism)); |
| 72 | } | |
| 73 | ||
| 74 | /** | |
| 75 | * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor} | |
| 76 | * and returning them as a {@link CompletableFuture} containing a result of the application of the user-provided {@link Collector}. | |
| 77 | * | |
| 78 | * <br> | |
| 79 | * Example: | |
| 80 | * <pre>{@code | |
| 81 | * CompletableFuture<List<String>> result = Stream.of(1, 2, 3) | |
| 82 | * .collect(parallel(i -> foo(i), toList(), executor, 2)); | |
| 83 | * }</pre> | |
| 84 | * | |
| 85 | * @param mapper a transformation to be performed in parallel | |
| 86 | * @param collector the {@code Collector} describing the reduction | |
| 87 | * @param executor the {@code Executor} to use for asynchronous execution | |
| 88 | * @param <T> the type of the collected elements | |
| 89 | * @param <R> the result returned by {@code mapper} | |
| 90 | * @param <RR> the reduction result {@code collector} | |
| 91 | * @param parallelism the max parallelism level | |
| 92 | * | |
| 93 | * @return a {@code Collector} which collects all processed elements into a user-provided mutable {@code Collection} in parallel | |
| 94 | * | |
| 95 | * @since 2.0.0 | |
| 96 | */ | |
| 97 | public static <T, R, RR> Collector<T, ?, CompletableFuture<RR>> parallel(Function<? super T, ? extends R> mapper, Collector<R, ?, RR> collector, Executor executor, int parallelism) { | |
| 98 | Objects.requireNonNull(collector, "collector cannot be null"); | |
| 99 |
2
1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED 2. lambda$parallel$2 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$2 → KILLED |
return Factory.collecting(s -> s.collect(collector), mapper, Options.executor(executor), Options.parallelism(parallelism)); |
| 100 | } | |
| 101 | ||
| 102 | /** | |
| 103 | * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor} with unlimited parallelism | |
| 104 | * and returning them as a {@link CompletableFuture} containing a result of the application of the user-provided {@link Collector}. | |
| 105 | * | |
| 106 | * <br> | |
| 107 | * Example: | |
| 108 | * <pre>{@code | |
| 109 | * CompletableFuture<List<String>> result = Stream.of(1, 2, 3) | |
| 110 | * .collect(parallel(i -> foo(i), toList(), executor)); | |
| 111 | * }</pre> | |
| 112 | * | |
| 113 | * @param mapper a transformation to be performed in parallel | |
| 114 | * @param collector the {@code Collector} describing the reduction | |
| 115 | * @param executor the {@code Executor} to use for asynchronous execution | |
| 116 | * @param <T> the type of the collected elements | |
| 117 | * @param <R> the result returned by {@code mapper} | |
| 118 | * @param <RR> the reduction result {@code collector} | |
| 119 | * | |
| 120 | * @return a {@code Collector} which collects all processed elements into a user-provided mutable {@code Collection} in parallel | |
| 121 | * | |
| 122 | * @since 3.3.0 | |
| 123 | */ | |
| 124 | public static <T, R, RR> Collector<T, ?, CompletableFuture<RR>> parallel(Function<? super T, ? extends R> mapper, Collector<R, ?, RR> collector, Executor executor) { | |
| 125 | Objects.requireNonNull(collector, "collector cannot be null"); | |
| 126 |
2
1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED 2. lambda$parallel$3 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$3 → KILLED |
return Factory.collecting(s -> s.collect(collector), mapper, Options.executor(executor)); |
| 127 | } | |
| 128 | ||
| 129 | /** | |
| 130 | * A convenience {@link Collector} used for executing parallel computations using Virtual Threads | |
| 131 | * and returning them as {@link CompletableFuture} containing a {@link Stream} of these elements. | |
| 132 | * | |
| 133 | * <br><br> | |
| 134 | * The collector maintains the order of processed {@link Stream}. Instances should not be reused. | |
| 135 | * | |
| 136 | * <br> | |
| 137 | * Example: | |
| 138 | * <pre>{@code | |
| 139 | * CompletableFuture<Stream<String>> result = Stream.of(1, 2, 3) | |
| 140 | * .collect(parallel(i -> foo())); | |
| 141 | * }</pre> | |
| 142 | * | |
| 143 | * @param mapper a transformation to be performed in parallel | |
| 144 | * @param <T> the type of the collected elements | |
| 145 | * @param <R> the result returned by {@code mapper} | |
| 146 | * | |
| 147 | * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel | |
| 148 | * | |
| 149 | * @since 3.0.0 | |
| 150 | */ | |
| 151 | public static <T, R> Collector<T, ?, CompletableFuture<Stream<R>>> parallel(Function<? super T, ? extends R> mapper) { | |
| 152 |
1
1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED |
return Factory.collecting(mapper); |
| 153 | } | |
| 154 | ||
| 155 | /** | |
| 156 | * A convenience {@link Collector} used for executing parallel computations using Virtual Threads | |
| 157 | * and returning them as {@link CompletableFuture} containing a {@link Stream} of these elements. | |
| 158 | * | |
| 159 | * <br><br> | |
| 160 | * The collector maintains the order of processed {@link Stream}. Instances should not be reused. | |
| 161 | * | |
| 162 | * <br> | |
| 163 | * Example: | |
| 164 | * <pre>{@code | |
| 165 | * CompletableFuture<Stream<String>> result = Stream.of(1, 2, 3) | |
| 166 | * .collect(parallel(i -> foo())); | |
| 167 | * }</pre> | |
| 168 | * | |
| 169 | * @param mapper a transformation to be performed in parallel | |
| 170 | * @param parallelism the max parallelism level | |
| 171 | * @param <T> the type of the collected elements | |
| 172 | * @param <R> the result returned by {@code mapper} | |
| 173 | * | |
| 174 | * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel | |
| 175 | * | |
| 176 | * @since 3.2.0 | |
| 177 | */ | |
| 178 | public static <T, R> Collector<T, ?, CompletableFuture<Stream<R>>> parallel(Function<? super T, ? extends R> mapper, int parallelism) { | |
| 179 |
1
1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED |
return Factory.collecting(mapper, Options.parallelism(parallelism)); |
| 180 | } | |
| 181 | ||
| 182 | /** | |
| 183 | * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor} | |
| 184 | * and returning them as {@link CompletableFuture} containing a {@link Stream} of these elements. | |
| 185 | * | |
| 186 | * <br><br> | |
| 187 | * The collector maintains the order of processed {@link Stream}. Instances should not be reused. | |
| 188 | * | |
| 189 | * <br> | |
| 190 | * Example: | |
| 191 | * <pre>{@code | |
| 192 | * CompletableFuture<Stream<String>> result = Stream.of(1, 2, 3) | |
| 193 | * .collect(parallel(i -> foo(), executor, 2)); | |
| 194 | * }</pre> | |
| 195 | * | |
| 196 | * @param mapper a transformation to be performed in parallel | |
| 197 | * @param executor the {@code Executor} to use for asynchronous execution | |
| 198 | * @param parallelism the max parallelism level | |
| 199 | * @param <T> the type of the collected elements | |
| 200 | * @param <R> the result returned by {@code mapper} | |
| 201 | * | |
| 202 | * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel | |
| 203 | * | |
| 204 | * @since 2.0.0 | |
| 205 | */ | |
| 206 | public static <T, R> Collector<T, ?, CompletableFuture<Stream<R>>> parallel(Function<? super T, ? extends R> mapper, Executor executor, int parallelism) { | |
| 207 |
1
1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED |
return Factory.collecting(mapper, Options.executor(executor), Options.parallelism(parallelism)); |
| 208 | } | |
| 209 | ||
| 210 | /** | |
| 211 | * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor} with unlimited parallelism | |
| 212 | * and returning them as {@link CompletableFuture} containing a {@link Stream} of these elements. | |
| 213 | * | |
| 214 | * <br><br> | |
| 215 | * The collector maintains the order of processed {@link Stream}. Instances should not be reused. | |
| 216 | * | |
| 217 | * <br> | |
| 218 | * Example: | |
| 219 | * <pre>{@code | |
| 220 | * CompletableFuture<Stream<String>> result = Stream.of(1, 2, 3) | |
| 221 | * .collect(parallel(i -> foo(), executor)); | |
| 222 | * }</pre> | |
| 223 | * | |
| 224 | * @param mapper a transformation to be performed in parallel | |
| 225 | * @param executor the {@code Executor} to use for asynchronous execution | |
| 226 | * @param <T> the type of the collected elements | |
| 227 | * @param <R> the result returned by {@code mapper} | |
| 228 | * | |
| 229 | * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel | |
| 230 | * | |
| 231 | * @since 3.3.0 | |
| 232 | */ | |
| 233 | public static <T, R> Collector<T, ?, CompletableFuture<Stream<R>>> parallel(Function<? super T, ? extends R> mapper, Executor executor) { | |
| 234 |
1
1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED |
return Factory.collecting(mapper, Options.executor(executor)); |
| 235 | } | |
| 236 | ||
| 237 | /** | |
| 238 | * A convenience {@link Collector} used for executing parallel computations using Virtual Threads | |
| 239 | * and returning a {@link Stream} instance returning results as they arrive. | |
| 240 | * <p> | |
| 241 | * For the parallelism of 1, the stream is executed by the calling thread. | |
| 242 | * | |
| 243 | * <br> | |
| 244 | * Example: | |
| 245 | * <pre>{@code | |
| 246 | * Stream.of(1, 2, 3) | |
| 247 | * .collect(parallelToStream(i -> foo())) | |
| 248 | * .forEach(System.out::println); | |
| 249 | * }</pre> | |
| 250 | * | |
| 251 | * @param mapper a transformation to be performed in parallel | |
| 252 | * @param <T> the type of the collected elements | |
| 253 | * @param <R> the result returned by {@code mapper} | |
| 254 | * | |
| 255 | * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel | |
| 256 | * | |
| 257 | * @since 3.0.0 | |
| 258 | */ | |
| 259 | public static <T, R> Collector<T, ?, Stream<R>> parallelToStream(Function<? super T, ? extends R> mapper) { | |
| 260 |
1
1. parallelToStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED |
return Factory.streaming(mapper); |
| 261 | } | |
| 262 | ||
| 263 | /** | |
| 264 | * A convenience {@link Collector} used for executing parallel computations using Virtual Threads | |
| 265 | * and returning a {@link Stream} instance returning results as they arrive. | |
| 266 | * <p> | |
| 267 | * For the parallelism of 1, the stream is executed by the calling thread. | |
| 268 | * | |
| 269 | * <br> | |
| 270 | * Example: | |
| 271 | * <pre>{@code | |
| 272 | * Stream.of(1, 2, 3) | |
| 273 | * .collect(parallelToStream(i -> foo(), executor, 2)) | |
| 274 | * .forEach(System.out::println); | |
| 275 | * }</pre> | |
| 276 | * | |
| 277 | * @param mapper a transformation to be performed in parallel | |
| 278 | * @param parallelism the max parallelism level | |
| 279 | * @param <T> the type of the collected elements | |
| 280 | * @param <R> the result returned by {@code mapper} | |
| 281 | * | |
| 282 | * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel | |
| 283 | * | |
| 284 | * @since 3.2.0 | |
| 285 | */ | |
| 286 | public static <T, R> Collector<T, ?, Stream<R>> parallelToStream(Function<? super T, ? extends R> mapper, int parallelism) { | |
| 287 |
1
1. parallelToStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED |
return Factory.streaming(mapper, Options.parallelism(parallelism)); |
| 288 | } | |
| 289 | ||
| 290 | /** | |
| 291 | * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor} with unlimited parallelism | |
| 292 | * and returning a {@link Stream} instance returning results as they arrive. | |
| 293 | * <p> | |
| 294 | * For the parallelism of 1, the stream is executed by the calling thread. | |
| 295 | * | |
| 296 | * <br> | |
| 297 | * Example: | |
| 298 | * <pre>{@code | |
| 299 | * Stream.of(1, 2, 3) | |
| 300 | * .collect(parallelToStream(i -> foo(), executor, 2)) | |
| 301 | * .forEach(System.out::println); | |
| 302 | * }</pre> | |
| 303 | * | |
| 304 | * @param mapper a transformation to be performed in parallel | |
| 305 | * @param executor the {@code Executor} to use for asynchronous execution | |
| 306 | * @param <T> the type of the collected elements | |
| 307 | * @param <R> the result returned by {@code mapper} | |
| 308 | * | |
| 309 | * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel | |
| 310 | * | |
| 311 | * @since 3.3.0 | |
| 312 | */ | |
| 313 | public static <T, R> Collector<T, ?, Stream<R>> parallelToStream(Function<? super T, ? extends R> mapper, Executor executor) { | |
| 314 |
1
1. parallelToStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED |
return Factory.streaming(mapper, Options.executor(executor)); |
| 315 | } | |
| 316 | ||
| 317 | /** | |
| 318 | * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor} | |
| 319 | * and returning a {@link Stream} instance returning results as they arrive. | |
| 320 | * <p> | |
| 321 | * For the parallelism of 1, the stream is executed by the calling thread. | |
| 322 | * | |
| 323 | * <br> | |
| 324 | * Example: | |
| 325 | * <pre>{@code | |
| 326 | * Stream.of(1, 2, 3) | |
| 327 | * .collect(parallelToStream(i -> foo(), executor, 2)) | |
| 328 | * .forEach(System.out::println); | |
| 329 | * }</pre> | |
| 330 | * | |
| 331 | * @param mapper a transformation to be performed in parallel | |
| 332 | * @param executor the {@code Executor} to use for asynchronous execution | |
| 333 | * @param parallelism the max parallelism level | |
| 334 | * @param <T> the type of the collected elements | |
| 335 | * @param <R> the result returned by {@code mapper} | |
| 336 | * | |
| 337 | * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel | |
| 338 | * | |
| 339 | * @since 2.0.0 | |
| 340 | */ | |
| 341 | public static <T, R> Collector<T, ?, Stream<R>> parallelToStream(Function<? super T, ? extends R> mapper, Executor executor, int parallelism) { | |
| 342 |
1
1. parallelToStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED |
return Factory.streaming(mapper, Options.executor(executor), Options.parallelism(parallelism)); |
| 343 | } | |
| 344 | ||
| 345 | /** | |
| 346 | * A convenience {@link Collector} used for executing parallel computations using Virtual Threads | |
| 347 | * and returning a {@link Stream} instance returning results as they arrive while maintaining the initial order. | |
| 348 | * <p> | |
| 349 | * For the parallelism of 1, the stream is executed by the calling thread. | |
| 350 | * | |
| 351 | * <br> | |
| 352 | * Example: | |
| 353 | * <pre>{@code | |
| 354 | * Stream.of(1, 2, 3) | |
| 355 | * .collect(parallelToOrderedStream(i -> foo())) | |
| 356 | * .forEach(System.out::println); | |
| 357 | * }</pre> | |
| 358 | * | |
| 359 | * @param mapper a transformation to be performed in parallel | |
| 360 | * @param <T> the type of the collected elements | |
| 361 | * @param <R> the result returned by {@code mapper} | |
| 362 | * | |
| 363 | * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel | |
| 364 | * | |
| 365 | * @since 3.0.0 | |
| 366 | */ | |
| 367 | public static <T, R> Collector<T, ?, Stream<R>> parallelToOrderedStream(Function<? super T, ? extends R> mapper) { | |
| 368 |
1
1. parallelToOrderedStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStream → KILLED |
return Factory.streaming(mapper, Options.ordered()); |
| 369 | } | |
| 370 | ||
| 371 | /** | |
| 372 | * A convenience {@link Collector} used for executing parallel computations using Virtual Threads | |
| 373 | * and returning a {@link Stream} instance returning results as they arrive while maintaining the initial order. | |
| 374 | * <p> | |
| 375 | * For the parallelism of 1, the stream is executed by the calling thread. | |
| 376 | * | |
| 377 | * <br> | |
| 378 | * Example: | |
| 379 | * <pre>{@code | |
| 380 | * Stream.of(1, 2, 3) | |
| 381 | * .collect(parallelToOrderedStream(i -> foo(), executor, 2)) | |
| 382 | * .forEach(System.out::println); | |
| 383 | * }</pre> | |
| 384 | * | |
| 385 | * @param mapper a transformation to be performed in parallel | |
| 386 | * @param parallelism the max parallelism level | |
| 387 | * @param <T> the type of the collected elements | |
| 388 | * @param <R> the result returned by {@code mapper} | |
| 389 | * | |
| 390 | * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel | |
| 391 | * | |
| 392 | * @since 3.2.0 | |
| 393 | */ | |
| 394 | public static <T, R> Collector<T, ?, Stream<R>> parallelToOrderedStream(Function<? super T, ? extends R> mapper, int parallelism) { | |
| 395 |
1
1. parallelToOrderedStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStream → KILLED |
return Factory.streaming(mapper, Options.ordered(), Options.parallelism(parallelism)); |
| 396 | } | |
| 397 | ||
| 398 | /** | |
| 399 | * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor} with unlimited parallelism | |
| 400 | * and returning a {@link Stream} instance returning results as they arrive while maintaining the initial order. | |
| 401 | * <p> | |
| 402 | * For the parallelism of 1, the stream is executed by the calling thread. | |
| 403 | * | |
| 404 | * <br> | |
| 405 | * Example: | |
| 406 | * <pre>{@code | |
| 407 | * Stream.of(1, 2, 3) | |
| 408 | * .collect(parallelToOrderedStream(i -> foo(), executor)) | |
| 409 | * .forEach(System.out::println); | |
| 410 | * }</pre> | |
| 411 | * | |
| 412 | * @param mapper a transformation to be performed in parallel | |
| 413 | * @param executor the {@code Executor} to use for asynchronous execution | |
| 414 | * @param <T> the type of the collected elements | |
| 415 | * @param <R> the result returned by {@code mapper} | |
| 416 | * | |
| 417 | * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel | |
| 418 | * | |
| 419 | * @since 3.3.0 | |
| 420 | */ | |
| 421 | public static <T, R> Collector<T, ?, Stream<R>> parallelToOrderedStream(Function<? super T, ? extends R> mapper, Executor executor) { | |
| 422 |
1
1. parallelToOrderedStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStream → KILLED |
return Factory.streaming(mapper, Options.ordered(), Options.executor(executor)); |
| 423 | } | |
| 424 | ||
| 425 | /** | |
| 426 | * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor} | |
| 427 | * and returning a {@link Stream} instance returning results as they arrive while maintaining the initial order. | |
| 428 | * <p> | |
| 429 | * For the parallelism of 1, the stream is executed by the calling thread. | |
| 430 | * | |
| 431 | * <br> | |
| 432 | * Example: | |
| 433 | * <pre>{@code | |
| 434 | * Stream.of(1, 2, 3) | |
| 435 | * .collect(parallelToOrderedStream(i -> foo(), executor, 2)) | |
| 436 | * .forEach(System.out::println); | |
| 437 | * }</pre> | |
| 438 | * | |
| 439 | * @param mapper a transformation to be performed in parallel | |
| 440 | * @param executor the {@code Executor} to use for asynchronous execution | |
| 441 | * @param parallelism the max parallelism level | |
| 442 | * @param <T> the type of the collected elements | |
| 443 | * @param <R> the result returned by {@code mapper} | |
| 444 | * | |
| 445 | * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel | |
| 446 | * | |
| 447 | * @since 2.0.0 | |
| 448 | */ | |
| 449 | public static <T, R> Collector<T, ?, Stream<R>> parallelToOrderedStream(Function<? super T, ? extends R> mapper, Executor executor, int parallelism) { | |
| 450 |
1
1. parallelToOrderedStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStream → KILLED |
return Factory.streaming(mapper, Options.ordered(), Options.executor(executor), Options.parallelism(parallelism)); |
| 451 | } | |
| 452 | ||
| 453 | /** | |
| 454 | * A convenience {@code Collector} for collecting a {@code Stream<CompletableFuture<T>>} | |
| 455 | * into a {@code CompletableFuture<R>} using a provided {@code Collector<T, ?, R>} | |
| 456 | * | |
| 457 | * @param collector the {@code Collector} describing the reduction | |
| 458 | * @param <T> the type of the collected elements | |
| 459 | * @param <R> the result of the transformation | |
| 460 | * | |
| 461 | * @return a {@code Collector} which collects all futures and combines them into a single future | |
| 462 | * using the provided downstream {@code Collector} | |
| 463 | * | |
| 464 | * @since 2.3.0 | |
| 465 | */ | |
| 466 | public static <T, R> Collector<CompletableFuture<T>, ?, CompletableFuture<R>> toFuture(Collector<T, ?, R> collector) { | |
| 467 |
1
1. toFuture : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::toFuture → KILLED |
return FutureCollectors.toFuture(collector); |
| 468 | } | |
| 469 | ||
| 470 | /** | |
| 471 | * A convenience {@code Collector} for collecting a {@code Stream<CompletableFuture<T>>} into a {@code CompletableFuture<List<T>>} | |
| 472 | * | |
| 473 | * @param <T> the type of the collected elements | |
| 474 | * | |
| 475 | * @return a {@code Collector} which collects all futures and combines them into a single future | |
| 476 | * returning a list of results | |
| 477 | * | |
| 478 | * @since 2.3.0 | |
| 479 | */ | |
| 480 | public static <T> Collector<CompletableFuture<T>, ?, CompletableFuture<List<T>>> toFuture() { | |
| 481 |
1
1. toFuture : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::toFuture → KILLED |
return FutureCollectors.toFuture(); |
| 482 | } | |
| 483 | ||
| 484 | /** | |
| 485 | * A subset of collectors which perform operations in batches and not separately (one object in a thread pool's worker queue represents a batch of operations to be performed by a single thread) | |
| 486 | */ | |
| 487 | public static final class Batching { | |
| 488 | ||
| 489 | private Batching() { | |
| 490 | } | |
| 491 | ||
| 492 | /** | |
| 493 | * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor} | |
| 494 | * and returning them as a {@link CompletableFuture} containing a result of the application of the user-provided {@link Collector}. | |
| 495 | * | |
| 496 | * <br> | |
| 497 | * Example: | |
| 498 | * <pre>{@code | |
| 499 | * CompletableFuture<List<String>> result = Stream.of(1, 2, 3) | |
| 500 | * .collect(parallel(i -> foo(i), toList(), executor, 2)); | |
| 501 | * }</pre> | |
| 502 | * | |
| 503 | * @param mapper a transformation to be performed in parallel | |
| 504 | * @param collector the {@code Collector} describing the reduction | |
| 505 | * @param executor the {@code Executor} to use for asynchronous execution | |
| 506 | * @param parallelism the max parallelism level | |
| 507 | * @param <T> the type of the collected elements | |
| 508 | * @param <R> the result returned by {@code mapper} | |
| 509 | * @param <RR> the reduction result {@code collector} | |
| 510 | * | |
| 511 | * @return a {@code Collector} which collects all processed elements into a user-provided mutable {@code Collection} in parallel | |
| 512 | * | |
| 513 | * @since 2.1.0 | |
| 514 | */ | |
| 515 | public static <T, R, RR> Collector<T, ?, CompletableFuture<RR>> parallel(Function<? super T, ? extends R> mapper, Collector<R, ?, RR> collector, Executor executor, int parallelism) { | |
| 516 | Objects.requireNonNull(collector, "collector cannot be null"); | |
| 517 |
2
1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::parallel → KILLED 2. lambda$parallel$0 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::lambda$parallel$0 → KILLED |
return Factory.collecting(s -> s.collect(collector), mapper, |
| 518 | Options.batched(), | |
| 519 | Options.executor(executor), | |
| 520 | Options.parallelism(parallelism)); | |
| 521 | } | |
| 522 | ||
| 523 | /** | |
| 524 | * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor} | |
| 525 | * and returning them as {@link CompletableFuture} containing a {@link Stream} of these elements. | |
| 526 | * | |
| 527 | * <br><br> | |
| 528 | * The collector maintains the order of processed {@link Stream}. Instances should not be reused. | |
| 529 | * | |
| 530 | * <br> | |
| 531 | * Example: | |
| 532 | * <pre>{@code | |
| 533 | * CompletableFuture<Stream<String>> result = Stream.of(1, 2, 3) | |
| 534 | * .collect(parallel(i -> foo(), executor, 2)); | |
| 535 | * }</pre> | |
| 536 | * | |
| 537 | * @param mapper a transformation to be performed in parallel | |
| 538 | * @param executor the {@code Executor} to use for asynchronous execution | |
| 539 | * @param parallelism the max parallelism level | |
| 540 | * @param <T> the type of the collected elements | |
| 541 | * @param <R> the result returned by {@code mapper} | |
| 542 | * | |
| 543 | * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel | |
| 544 | * | |
| 545 | * @since 2.1.0 | |
| 546 | */ | |
| 547 | public static <T, R> Collector<T, ?, CompletableFuture<Stream<R>>> parallel(Function<? super T, ? extends R> mapper, Executor executor, int parallelism) { | |
| 548 |
1
1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::parallel → KILLED |
return Factory.collecting(mapper, |
| 549 | Options.batched(), | |
| 550 | Options.executor(executor), | |
| 551 | Options.parallelism(parallelism)); | |
| 552 | } | |
| 553 | ||
| 554 | /** | |
| 555 | * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor} | |
| 556 | * and returning a {@link Stream} instance returning results as they arrive. | |
| 557 | * <p> | |
| 558 | * For the parallelism of 1, the stream is executed by the calling thread. | |
| 559 | * | |
| 560 | * <br> | |
| 561 | * Example: | |
| 562 | * <pre>{@code | |
| 563 | * Stream.of(1, 2, 3) | |
| 564 | * .collect(parallelToStream(i -> foo(), executor, 2)) | |
| 565 | * .forEach(System.out::println); | |
| 566 | * }</pre> | |
| 567 | * | |
| 568 | * @param mapper a transformation to be performed in parallel | |
| 569 | * @param executor the {@code Executor} to use for asynchronous execution | |
| 570 | * @param parallelism the max parallelism level | |
| 571 | * @param <T> the type of the collected elements | |
| 572 | * @param <R> the result returned by {@code mapper} | |
| 573 | * | |
| 574 | * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel | |
| 575 | * | |
| 576 | * @since 2.1.0 | |
| 577 | */ | |
| 578 | public static <T, R> Collector<T, ?, Stream<R>> parallelToStream(Function<? super T, ? extends R> mapper, Executor executor, int parallelism) { | |
| 579 |
1
1. parallelToStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::parallelToStream → KILLED |
return Factory.streaming(mapper, |
| 580 | Options.batched(), | |
| 581 | Options.executor(executor), | |
| 582 | Options.parallelism(parallelism)); | |
| 583 | } | |
| 584 | ||
| 585 | /** | |
| 586 | * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor} | |
| 587 | * and returning a {@link Stream} instance returning results as they arrive while maintaining the initial order. | |
| 588 | * <p> | |
| 589 | * For the parallelism of 1, the stream is executed by the calling thread. | |
| 590 | * | |
| 591 | * <br> | |
| 592 | * Example: | |
| 593 | * <pre>{@code | |
| 594 | * Stream.of(1, 2, 3) | |
| 595 | * .collect(parallelToOrderedStream(i -> foo(), executor, 2)) | |
| 596 | * .forEach(System.out::println); | |
| 597 | * }</pre> | |
| 598 | * | |
| 599 | * @param mapper a transformation to be performed in parallel | |
| 600 | * @param executor the {@code Executor} to use for asynchronous execution | |
| 601 | * @param parallelism the max parallelism level | |
| 602 | * @param <T> the type of the collected elements | |
| 603 | * @param <R> the result returned by {@code mapper} | |
| 604 | * | |
| 605 | * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel | |
| 606 | * | |
| 607 | * @since 2.1.0 | |
| 608 | */ | |
| 609 | public static <T, R> Collector<T, ?, Stream<R>> parallelToOrderedStream(Function<? super T, ? extends R> mapper, Executor executor, int parallelism) { | |
| 610 |
1
1. parallelToOrderedStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::parallelToOrderedStream → KILLED |
return Factory.streaming(mapper, |
| 611 | Options.ordered(), | |
| 612 | Options.batched(), | |
| 613 | Options.executor(executor), | |
| 614 | Options.parallelism(parallelism)); | |
| 615 | } | |
| 616 | } | |
| 617 | } | |
Mutations | ||
| 44 |
1.1 2.2 |
|
| 71 |
1.1 2.2 |
|
| 99 |
1.1 2.2 |
|
| 126 |
1.1 2.2 |
|
| 152 |
1.1 |
|
| 179 |
1.1 |
|
| 207 |
1.1 |
|
| 234 |
1.1 |
|
| 260 |
1.1 |
|
| 287 |
1.1 |
|
| 314 |
1.1 |
|
| 342 |
1.1 |
|
| 368 |
1.1 |
|
| 395 |
1.1 |
|
| 422 |
1.1 |
|
| 450 |
1.1 |
|
| 467 |
1.1 |
|
| 481 |
1.1 |
|
| 517 |
1.1 2.2 |
|
| 548 |
1.1 |
|
| 579 |
1.1 |
|
| 610 |
1.1 |