com.pivovarit.collectors.CompletionStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of parallel-collectors Show documentation
Show all versions of parallel-collectors Show documentation
Parallel collection processing with customizable thread pools
The newest version!
package com.pivovarit.collectors;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
sealed interface CompletionStrategy extends Function>, Stream> permits CompletionStrategy.Unordered, CompletionStrategy.Ordered {
Unordered> UNORDERED = new Unordered<>();
Ordered> ORDERED = new Ordered<>();
static CompletionStrategy unordered() {
return (CompletionStrategy) UNORDERED;
}
static CompletionStrategy ordered() {
return (CompletionStrategy) ORDERED;
}
final class Unordered implements CompletionStrategy {
@Override
public Stream apply(List> futures) {
return StreamSupport.stream(new CompletionOrderSpliterator<>(futures), false);
}
}
final class Ordered implements CompletionStrategy {
@Override
public Stream apply(List> futures) {
return futures.stream().map(CompletableFuture::join);
}
}
}