17167
|
1 |
/*
|
|
2 |
* Copyright (c) 2012, 2013, 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},
|
18789
|
32 |
* etc. Contains methods common to all stream types.
|
17167
|
33 |
*
|
|
34 |
* @param <T> type of stream elements
|
|
35 |
* @param <S> type of stream implementing {@code BaseStream}
|
|
36 |
* @since 1.8
|
|
37 |
*/
|
18789
|
38 |
public interface BaseStream<T, S extends BaseStream<T, S>> {
|
17167
|
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 |
|
|
59 |
/**
|
|
60 |
* Returns whether this stream, when executed, would execute in parallel
|
|
61 |
* (assuming no further modification of the stream, such as appending
|
|
62 |
* further intermediate operations or changing its parallelism). Calling
|
|
63 |
* this method after invoking an intermediate or terminal stream operation
|
|
64 |
* method may yield unpredictable results.
|
|
65 |
*
|
|
66 |
* @return {@code true} if this stream would execute in parallel if executed
|
|
67 |
* without further modification otherwise {@code false}
|
|
68 |
*/
|
|
69 |
boolean isParallel();
|
|
70 |
|
|
71 |
/**
|
|
72 |
* Returns an equivalent stream that is sequential. May return
|
|
73 |
* itself, either because the stream was already sequential, or because
|
|
74 |
* the underlying stream state was modified to be sequential.
|
|
75 |
*
|
|
76 |
* <p>This is an <a href="package-summary.html#StreamOps">intermediate
|
|
77 |
* operation</a>.
|
|
78 |
*
|
|
79 |
* @return a sequential stream
|
|
80 |
*/
|
|
81 |
S sequential();
|
|
82 |
|
|
83 |
/**
|
|
84 |
* Returns an equivalent stream that is parallel. May return
|
|
85 |
* itself, either because the stream was already parallel, or because
|
|
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 |
}
|