src/share/classes/java/util/stream/IntPipeline.java

Print this page
rev 7982 : 8017513: Support for closeable streams
8022237: j.u.s.BaseStream.onClose() has an issue in implementation or requires spec clarification
8022572: Same exception instances thrown from j.u.stream.Stream.onClose() handlers are not listed as suppressed
Summary: BaseStream implements AutoCloseable; Remove CloseableStream and DelegatingStream
Reviewed-by: alanb, mduigou, psandoz
Contributed-by: brian.goetz@oracle.com


 285                     }
 286                 };
 287             }
 288         };
 289     }
 290 
 291     @Override
 292     public final IntStream flatMap(IntFunction<? extends IntStream> mapper) {
 293         return new StatelessOp<Integer>(this, StreamShape.INT_VALUE,
 294                                         StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
 295             @Override
 296             Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
 297                 return new Sink.ChainedInt<Integer>(sink) {
 298                     @Override
 299                     public void begin(long size) {
 300                         downstream.begin(-1);
 301                     }
 302 
 303                     @Override
 304                     public void accept(int t) {

 305                         // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
 306                         IntStream result = mapper.apply(t);
 307                         if (result != null)
 308                             result.sequential().forEach(i -> downstream.accept(i));
 309                     }

 310                 };
 311             }
 312         };
 313     }
 314 
 315     @Override
 316     public IntStream unordered() {
 317         if (!isOrdered())
 318             return this;
 319         return new StatelessOp<Integer>(this, StreamShape.INT_VALUE, StreamOpFlag.NOT_ORDERED) {
 320             @Override
 321             Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
 322                 return sink;
 323             }
 324         };
 325     }
 326 
 327     @Override
 328     public final IntStream filter(IntPredicate predicate) {
 329         Objects.requireNonNull(predicate);




 285                     }
 286                 };
 287             }
 288         };
 289     }
 290 
 291     @Override
 292     public final IntStream flatMap(IntFunction<? extends IntStream> mapper) {
 293         return new StatelessOp<Integer>(this, StreamShape.INT_VALUE,
 294                                         StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
 295             @Override
 296             Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
 297                 return new Sink.ChainedInt<Integer>(sink) {
 298                     @Override
 299                     public void begin(long size) {
 300                         downstream.begin(-1);
 301                     }
 302 
 303                     @Override
 304                     public void accept(int t) {
 305                         try (IntStream result = mapper.apply(t)) {
 306                             // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it

 307                             if (result != null)
 308                                 result.sequential().forEach(i -> downstream.accept(i));
 309                         }
 310                     }
 311                 };
 312             }
 313         };
 314     }
 315 
 316     @Override
 317     public IntStream unordered() {
 318         if (!isOrdered())
 319             return this;
 320         return new StatelessOp<Integer>(this, StreamShape.INT_VALUE, StreamOpFlag.NOT_ORDERED) {
 321             @Override
 322             Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
 323                 return sink;
 324             }
 325         };
 326     }
 327 
 328     @Override
 329     public final IntStream filter(IntPredicate predicate) {
 330         Objects.requireNonNull(predicate);