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 * @param <S> type of stream implementing {@code BaseStream}
36 * @since 1.8
37 */
38 public interface BaseStream<T, S extends BaseStream<T, S>> {
39 /**
40 * Returns an iterator for the elements of this stream.
41 *
42 * <p>This is a <a href="package-summary.html#StreamOps">terminal
43 * operation</a>.
44 *
45 * @return the element iterator for this stream
46 */
47 Iterator<T> iterator();
48
49 /**
50 * Returns a spliterator for the elements of this stream.
51 *
52 * <p>This is a <a href="package-summary.html#StreamOps">terminal
53 * operation</a>.
54 *
55 * @return the element spliterator for this stream
56 */
57 Spliterator<T> spliterator();
58
86 * the underlying stream state was modified to be parallel.
87 *
88 * <p>This is an <a href="package-summary.html#StreamOps">intermediate
89 * operation</a>.
90 *
91 * @return a parallel stream
92 */
93 S parallel();
94
95 /**
96 * Returns an equivalent stream that is
97 * <a href="package-summary.html#Ordering">unordered</a>. May return
98 * itself if the stream was already unordered.
99 *
100 * <p>This is an <a href="package-summary.html#StreamOps">intermediate
101 * operation</a>.
102 *
103 * @return an unordered stream
104 */
105 S unordered();
106 }
|
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.MayHoldCloseableResource;
28 import java.util.Iterator;
29 import java.util.Spliterator;
30
31 /**
32 * Base interface for stream types such as {@link Stream}, {@link IntStream},
33 * etc. Contains methods common to all stream types.
34 *
35 * @param <T> type of stream elements
36 * @param <S> type of stream implementing {@code BaseStream}
37 * @since 1.8
38 */
39 public interface BaseStream<T, S extends BaseStream<T, S>>
40 extends MayHoldCloseableResource {
41 /**
42 * Returns an iterator for the elements of this stream.
43 *
44 * <p>This is a <a href="package-summary.html#StreamOps">terminal
45 * operation</a>.
46 *
47 * @return the element iterator for this stream
48 */
49 Iterator<T> iterator();
50
51 /**
52 * Returns a spliterator for the elements of this stream.
53 *
54 * <p>This is a <a href="package-summary.html#StreamOps">terminal
55 * operation</a>.
56 *
57 * @return the element spliterator for this stream
58 */
59 Spliterator<T> spliterator();
60
88 * the underlying stream state was modified to be parallel.
89 *
90 * <p>This is an <a href="package-summary.html#StreamOps">intermediate
91 * operation</a>.
92 *
93 * @return a parallel stream
94 */
95 S parallel();
96
97 /**
98 * Returns an equivalent stream that is
99 * <a href="package-summary.html#Ordering">unordered</a>. May return
100 * itself if the stream was already unordered.
101 *
102 * <p>This is an <a href="package-summary.html#StreamOps">intermediate
103 * operation</a>.
104 *
105 * @return an unordered stream
106 */
107 S unordered();
108
109 /**
110 * Returns an equivalent stream with an additional close handler. Close
111 * handlers are run when the {@link MayHoldCloseableResource#close()} method
112 * is called on the stream, and are executed in the order they were
113 * added. All close handlers are run, even if earlier close handlers throw
114 * exceptions. If any close handler throws an exception, the first
115 * exception thrown will be relayed to the caller of {@code close()}, with
116 * any remaining exceptions added to that exception as suppressed exceptions.
117 *
118 * @param closeHandler A task to execute when the stream is closed
119 * @return a stream with a handler that is run if the stream is closed
120 */
121 S onClose(Runnable closeHandler);
122 }
|