351 @Override
352 public final IntStream peek(IntConsumer action) {
353 Objects.requireNonNull(action);
354 return new StatelessOp<Integer>(this, StreamShape.INT_VALUE,
355 0) {
356 @Override
357 Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
358 return new Sink.ChainedInt<Integer>(sink) {
359 @Override
360 public void accept(int t) {
361 action.accept(t);
362 downstream.accept(t);
363 }
364 };
365 }
366 };
367 }
368
369 // Stateful intermediate ops from IntStream
370
371 private IntStream slice(long skip, long limit) {
372 return SliceOps.makeInt(this, skip, limit);
373 }
374
375 @Override
376 public final IntStream limit(long maxSize) {
377 if (maxSize < 0)
378 throw new IllegalArgumentException(Long.toString(maxSize));
379 return slice(0, maxSize);
380 }
381
382 @Override
383 public final IntStream substream(long startingOffset) {
384 if (startingOffset < 0)
385 throw new IllegalArgumentException(Long.toString(startingOffset));
386 if (startingOffset == 0)
387 return this;
388 else
389 return slice(startingOffset, -1);
390 }
391
392 @Override
393 public final IntStream substream(long startingOffset, long endingOffset) {
394 if (startingOffset < 0 || endingOffset < startingOffset)
395 throw new IllegalArgumentException(String.format("substream(%d, %d)", startingOffset, endingOffset));
396 return slice(startingOffset, endingOffset - startingOffset);
397 }
398
399 @Override
400 public final IntStream sorted() {
401 return SortedOps.makeInt(this);
402 }
403
404 @Override
405 public final IntStream distinct() {
406 // While functional and quick to implement, this approach is not very efficient.
407 // An efficient version requires an int-specific map/set implementation.
408 return boxed().distinct().mapToInt(i -> i);
409 }
410
411 // Terminal ops from IntStream
412
413 @Override
414 public void forEach(IntConsumer action) {
415 evaluate(ForEachOps.makeInt(action, false));
416 }
|
351 @Override
352 public final IntStream peek(IntConsumer action) {
353 Objects.requireNonNull(action);
354 return new StatelessOp<Integer>(this, StreamShape.INT_VALUE,
355 0) {
356 @Override
357 Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
358 return new Sink.ChainedInt<Integer>(sink) {
359 @Override
360 public void accept(int t) {
361 action.accept(t);
362 downstream.accept(t);
363 }
364 };
365 }
366 };
367 }
368
369 // Stateful intermediate ops from IntStream
370
371 @Override
372 public final IntStream limit(long maxSize) {
373 if (maxSize < 0)
374 throw new IllegalArgumentException(Long.toString(maxSize));
375 return SliceOps.makeInt(this, 0, maxSize);
376 }
377
378 @Override
379 public final IntStream skip(long n) {
380 if (n < 0)
381 throw new IllegalArgumentException(Long.toString(n));
382 if (n == 0)
383 return this;
384 else
385 return SliceOps.makeInt(this, n, -1);
386 }
387
388 @Override
389 public final IntStream sorted() {
390 return SortedOps.makeInt(this);
391 }
392
393 @Override
394 public final IntStream distinct() {
395 // While functional and quick to implement, this approach is not very efficient.
396 // An efficient version requires an int-specific map/set implementation.
397 return boxed().distinct().mapToInt(i -> i);
398 }
399
400 // Terminal ops from IntStream
401
402 @Override
403 public void forEach(IntConsumer action) {
404 evaluate(ForEachOps.makeInt(action, false));
405 }
|