1 /*
   2  * Copyright (c) 2012, 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
  23  * questions.
  24  */
  25 package java.util.stream;
  26 
  27 import java.util.Iterator;
  28 import java.util.Spliterator;
  29 
  30 /**
  31  * Base interface for stream types such as {@link Stream}, {@link IntStream},
  32  * etc.  Contains methods common to all stream types.
  33  *
  34  * @param <T> Type of stream elements.
  35  * @since 1.8
  36  */
  37 interface BaseStream<T, S extends BaseStream<T, S>> {
  38     /**
  39      * Returns an iterator for the elements of this stream.  This is
  40      * a <a href="package-summary.html#StreamOps">terminal operation</a>.
  41      *
  42      * @return the element iterator for this stream
  43      */
  44     Iterator<T> iterator();
  45 
  46     /**
  47      * Returns a spliterator for the elements of this stream.  This is
  48      * a <a href="package-summary.html#StreamOps">terminal operation</a>.
  49      *
  50      * @return the element spliterator for this stream
  51      */
  52     Spliterator<T> spliterator();
  53 
  54     /**
  55      * Returns whether this stream, when executed, will execute in parallel
  56      *
  57      * @return whether this stream will execute in parallel
  58      */
  59     boolean isParallel();
  60 
  61     /**
  62      * Returns the composition of stream flags of the stream source and all
  63      * intermediate operations.
  64      *
  65      * @return the composition of stream flags of the stream source and all
  66      *         intermediate operations
  67      * @see StreamOpFlag
  68      */
  69     int getStreamFlags();
  70 
  71     /**
  72      * Produces a stream which has the same contents as this stream, but is a
  73      * sequential stream.  If this stream is already sequential, may return
  74      * itself.  This is a
  75      * <a href="package-summary.html#StreamOps">stateful intermediate operation</a>.
  76      *
  77      * @return a sequential stream
  78      */
  79     S sequential();
  80 
  81     /**
  82      * Produces a stream which has the same contents as this stream, but is a
  83      * parallel stream.  If this stream is already parallel, may return itself.
  84      * This is a
  85      * <a href="package-summary.html#StreamOps">stateful intermediate operation</a>.
  86      *
  87      * @return a parallel stream
  88      */
  89     S parallel();
  90 }