< prev index next >

src/java.base/share/classes/java/util/stream/AbstractPipeline.java

Print this page


   1 /*
   2  * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 310     public final S parallel() {
 311         sourceStage.parallel = true;
 312         return (S) this;
 313     }
 314 
 315     @Override
 316     public void close() {
 317         linkedOrConsumed = true;
 318         sourceSupplier = null;
 319         sourceSpliterator = null;
 320         if (sourceStage.sourceCloseAction != null) {
 321             Runnable closeAction = sourceStage.sourceCloseAction;
 322             sourceStage.sourceCloseAction = null;
 323             closeAction.run();
 324         }
 325     }
 326 
 327     @Override
 328     @SuppressWarnings("unchecked")
 329     public S onClose(Runnable closeHandler) {


 330         Objects.requireNonNull(closeHandler);
 331         Runnable existingHandler = sourceStage.sourceCloseAction;
 332         sourceStage.sourceCloseAction =
 333                 (existingHandler == null)
 334                 ? closeHandler
 335                 : Streams.composeWithExceptions(existingHandler, closeHandler);
 336         return (S) this;
 337     }
 338 
 339     // Primitive specialization use co-variant overrides, hence is not final
 340     @Override
 341     @SuppressWarnings("unchecked")
 342     public Spliterator<E_OUT> spliterator() {
 343         if (linkedOrConsumed)
 344             throw new IllegalStateException(MSG_STREAM_LINKED);
 345         linkedOrConsumed = true;
 346 
 347         if (this == sourceStage) {
 348             if (sourceStage.sourceSpliterator != null) {
 349                 @SuppressWarnings("unchecked")


   1 /*
   2  * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 310     public final S parallel() {
 311         sourceStage.parallel = true;
 312         return (S) this;
 313     }
 314 
 315     @Override
 316     public void close() {
 317         linkedOrConsumed = true;
 318         sourceSupplier = null;
 319         sourceSpliterator = null;
 320         if (sourceStage.sourceCloseAction != null) {
 321             Runnable closeAction = sourceStage.sourceCloseAction;
 322             sourceStage.sourceCloseAction = null;
 323             closeAction.run();
 324         }
 325     }
 326 
 327     @Override
 328     @SuppressWarnings("unchecked")
 329     public S onClose(Runnable closeHandler) {
 330         if (linkedOrConsumed)
 331             throw new IllegalStateException(MSG_STREAM_LINKED);
 332         Objects.requireNonNull(closeHandler);
 333         Runnable existingHandler = sourceStage.sourceCloseAction;
 334         sourceStage.sourceCloseAction =
 335                 (existingHandler == null)
 336                 ? closeHandler
 337                 : Streams.composeWithExceptions(existingHandler, closeHandler);
 338         return (S) this;
 339     }
 340 
 341     // Primitive specialization use co-variant overrides, hence is not final
 342     @Override
 343     @SuppressWarnings("unchecked")
 344     public Spliterator<E_OUT> spliterator() {
 345         if (linkedOrConsumed)
 346             throw new IllegalStateException(MSG_STREAM_LINKED);
 347         linkedOrConsumed = true;
 348 
 349         if (this == sourceStage) {
 350             if (sourceStage.sourceSpliterator != null) {
 351                 @SuppressWarnings("unchecked")


< prev index next >