jdk/src/share/classes/java/util/stream/BaseStream.java
author darcy
Wed, 10 Jul 2013 11:05:39 -0700
changeset 18796 486b43748d9b
parent 18789 b518cd4045bc
child 19800 6e1fef53ea55
permissions -rw-r--r--
8020294: Fix doclint issues in java.util.Spliterator Reviewed-by: psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
     1
/*
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
     4
 *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    10
 *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    15
 * accompanied this code).
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    16
 *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    20
 *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    23
 * questions.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    24
 */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    25
package java.util.stream;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    26
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    27
import java.util.Iterator;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    28
import java.util.Spliterator;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    29
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    30
/**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    31
 * Base interface for stream types such as {@link Stream}, {@link IntStream},
18789
b518cd4045bc 8019551: Make BaseStream public
psandoz
parents: 17167
diff changeset
    32
 * etc.  Contains methods common to all stream types.
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    33
 *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    34
 * @param <T> type of stream elements
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    35
 * @param <S> type of stream implementing {@code BaseStream}
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    36
 * @since 1.8
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    37
 */
18789
b518cd4045bc 8019551: Make BaseStream public
psandoz
parents: 17167
diff changeset
    38
public interface BaseStream<T, S extends BaseStream<T, S>> {
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    39
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    40
     * Returns an iterator for the elements of this stream.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    41
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    42
     * <p>This is a <a href="package-summary.html#StreamOps">terminal
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    43
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    44
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    45
     * @return the element iterator for this stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    46
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    47
    Iterator<T> iterator();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    48
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    49
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    50
     * Returns a spliterator for the elements of this stream.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    51
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    52
     * <p>This is a <a href="package-summary.html#StreamOps">terminal
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    53
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    54
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    55
     * @return the element spliterator for this stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    56
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    57
    Spliterator<T> spliterator();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    58
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    59
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    60
     * Returns whether this stream, when executed, would execute in parallel
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    61
     * (assuming no further modification of the stream, such as appending
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    62
     * further intermediate operations or changing its parallelism).  Calling
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    63
     * this method after invoking an intermediate or terminal stream operation
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    64
     * method may yield unpredictable results.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    65
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    66
     * @return {@code true} if this stream would execute in parallel if executed
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    67
     * without further modification otherwise {@code false}
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    68
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    69
    boolean isParallel();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    70
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    71
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    72
     * Returns an equivalent stream that is sequential.  May return
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    73
     * itself, either because the stream was already sequential, or because
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    74
     * the underlying stream state was modified to be sequential.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    75
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    76
     * <p>This is an <a href="package-summary.html#StreamOps">intermediate
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    77
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    78
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    79
     * @return a sequential stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    80
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    81
    S sequential();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    82
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    83
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    84
     * Returns an equivalent stream that is parallel.  May return
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    85
     * itself, either because the stream was already parallel, or because
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    86
     * the underlying stream state was modified to be parallel.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    87
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    88
     * <p>This is an <a href="package-summary.html#StreamOps">intermediate
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    89
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    90
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    91
     * @return a parallel stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    92
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    93
    S parallel();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    94
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    95
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    96
     * Returns an equivalent stream that is
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    97
     * <a href="package-summary.html#Ordering">unordered</a>.  May return
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    98
     * itself if the stream was already unordered.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    99
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   100
     * <p>This is an <a href="package-summary.html#StreamOps">intermediate
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   101
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   102
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   103
     * @return an unordered stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   104
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   105
    S unordered();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   106
}