8071597: Add Stream dropWhile and takeWhile operations

Reviewed-by: briangoetz, smarks, chegar, forax
This commit is contained in:
Paul Sandoz 2015-06-09 07:10:03 +01:00
parent 5d91ae3352
commit 5744f4fc30
18 changed files with 3665 additions and 41 deletions

View file

@ -156,10 +156,12 @@ abstract class IntPipeline<E_IN>
}
@Override
final void forEachWithCancel(Spliterator<Integer> spliterator, Sink<Integer> sink) {
final boolean forEachWithCancel(Spliterator<Integer> spliterator, Sink<Integer> sink) {
Spliterator.OfInt spl = adapt(spliterator);
IntConsumer adaptedSink = adapt(sink);
do { } while (!sink.cancellationRequested() && spl.tryAdvance(adaptedSink));
boolean cancelled;
do { } while (!(cancelled = sink.cancellationRequested()) && spl.tryAdvance(adaptedSink));
return cancelled;
}
@Override
@ -386,6 +388,16 @@ abstract class IntPipeline<E_IN>
return SliceOps.makeInt(this, n, -1);
}
@Override
public final IntStream takeWhile(IntPredicate predicate) {
return WhileOps.makeTakeWhileInt(this, predicate);
}
@Override
public final IntStream dropWhile(IntPredicate predicate) {
return WhileOps.makeDropWhileInt(this, predicate);
}
@Override
public final IntStream sorted() {
return SortedOps.makeInt(this);