Код: Выделить всё
void process(Stream input) {
input.allMatch(element -> {
if (isCancelled) {
return false;
}
send(element); // Should receive all elements in any order exactly once unless cancelled
return true;
});
}
Код: Выделить всё
@Test
public void anyMatch() {
AtomicLong count = new AtomicLong(0);
IntStream.range(0, Integer.MAX_VALUE).parallel().mapToObj(ignored -> new Object()) .allMatch(i -> {
count.incrementAndGet(); // verify that no objects are processed more than once
return true;
});
Assert.assertEquals(count.get(), Integer.MAX_VALUE);
}
< /code>
imo, учитывая природу базового Spliterator.trysplit () < /code> Это надежный подход, но я хотел бы как -то получить подтверждение и прогноз.PushSpliterator.parallel()Подробнее здесь: https://stackoverflow.com/questions/797 ... me-element