jdk/src/share/classes/java/util/stream/Collector.java
author psandoz
Thu, 16 Jan 2014 18:20:31 +0100
changeset 22289 bb9c71b84919
parent 19850 93b368e54c1c
permissions -rw-r--r--
8029452: Fork/Join task ForEachOps.ForEachOrderedTask clarifications and minor improvements Reviewed-by: mduigou, briangoetz
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.Collections;
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
    28
import java.util.EnumSet;
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    29
import java.util.Objects;
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    30
import java.util.Set;
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
    31
import java.util.function.BiConsumer;
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    32
import java.util.function.BinaryOperator;
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
    33
import java.util.function.Function;
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    34
import java.util.function.Supplier;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    35
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    36
/**
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    37
 * A <a href="package-summary.html#Reduction">mutable reduction operation</a> that
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    38
 * accumulates input elements into a mutable result container, optionally transforming
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
    39
 * the accumulated result into a final representation after all input elements
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    40
 * have been processed.  Reduction operations can be performed either sequentially
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    41
 * or in parallel.
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
    42
 *
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
    43
 * <p>Examples of mutable reduction operations include:
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
    44
 * accumulating elements into a {@code Collection}; concatenating
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
    45
 * strings using a {@code StringBuilder}; computing summary information about
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
    46
 * elements such as sum, min, max, or average; computing "pivot table" summaries
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    47
 * such as "maximum valued transaction by seller", etc.  The class {@link Collectors}
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    48
 * provides implementations of many common mutable reductions.
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    49
 *
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
    50
 * <p>A {@code Collector} is specified by four functions that work together to
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
    51
 * accumulate entries into a mutable result container, and optionally perform
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    52
 * a final transform on the result.  They are: <ul>
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    53
 *     <li>creation of a new result container ({@link #supplier()})</li>
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    54
 *     <li>incorporating a new data element into a result container ({@link #accumulator()})</li>
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    55
 *     <li>combining two result containers into one ({@link #combiner()})</li>
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    56
 *     <li>performing an optional final transform on the container ({@link #finisher()})</li>
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    57
 * </ul>
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    58
 *
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
    59
 * <p>Collectors also have a set of characteristics, such as
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    60
 * {@link Characteristics#CONCURRENT}, that provide hints that can be used by a
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    61
 * reduction implementation to provide better performance.
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    62
 *
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    63
 * <p>A sequential implementation of a reduction using a collector would
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    64
 * create a single result container using the supplier function, and invoke the
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    65
 * accumulator function once for each input element.  A parallel implementation
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    66
 * would partition the input, create a result container for each partition,
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    67
 * accumulate the contents of each partition into a subresult for that partition,
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    68
 * and then use the combiner function to merge the subresults into a combined
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    69
 * result.
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    70
 *
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    71
 * <p>To ensure that sequential and parallel executions produce equivalent
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    72
 * results, the collector functions must satisfy an <em>identity</em> and an
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    73
 * <a href="package-summary.html#Associativity">associativity</a> constraints.
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    74
 *
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    75
 * <p>The identity constraint says that for any partially accumulated result,
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    76
 * combining it with an empty result container must produce an equivalent
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    77
 * result.  That is, for a partially accumulated result {@code a} that is the
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    78
 * result of any series of accumulator and combiner invocations, {@code a} must
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    79
 * be equivalent to {@code combiner.apply(a, supplier.get())}.
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    80
 *
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    81
 * <p>The associativity constraint says that splitting the computation must
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    82
 * produce an equivalent result.  That is, for any input elements {@code t1}
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    83
 * and {@code t2}, the results {@code r1} and {@code r2} in the computation
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    84
 * below must be equivalent:
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    85
 * <pre>{@code
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    86
 *     A a1 = supplier.get();
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    87
 *     accumulator.accept(a1, t1);
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    88
 *     accumulator.accept(a1, t2);
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    89
 *     R r1 = finisher.apply(a1);  // result without splitting
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    90
 *
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    91
 *     A a2 = supplier.get();
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    92
 *     accumulator.accept(a2, t1);
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    93
 *     A a3 = supplier.get();
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    94
 *     accumulator.accept(a3, t2);
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    95
 *     R r2 = finisher.apply(combiner.apply(a2, a3));  // result with splitting
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    96
 * } </pre>
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    97
 *
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    98
 * <p>For collectors that do not have the {@code UNORDERED} characteristic,
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
    99
 * two accumulated results {@code a1} and {@code a2} are equivalent if
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   100
 * {@code finisher.apply(a1).equals(finisher.apply(a2))}.  For unordered
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   101
 * collectors, equivalence is relaxed to allow for non-equality related to
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   102
 * differences in order.  (For example, an unordered collector that accumulated
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   103
 * elements to a {@code List} would consider two lists equivalent if they
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   104
 * contained the same elements, ignoring order.)
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   105
 *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   106
 * <p>Libraries that implement reduction based on {@code Collector}, such as
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   107
 * {@link Stream#collect(Collector)}, must adhere to the following constraints:
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   108
 * <ul>
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   109
 *     <li>The first argument passed to the accumulator function, both
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   110
 *     arguments passed to the combiner function, and the argument passed to the
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   111
 *     finisher function must be the result of a previous invocation of the
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   112
 *     result supplier, accumulator, or combiner functions.</li>
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   113
 *     <li>The implementation should not do anything with the result of any of
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   114
 *     the result supplier, accumulator, or combiner functions other than to
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   115
 *     pass them again to the accumulator, combiner, or finisher functions,
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   116
 *     or return them to the caller of the reduction operation.</li>
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   117
 *     <li>If a result is passed to the combiner or finisher
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   118
 *     function, and the same object is not returned from that function, it is
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   119
 *     never used again.</li>
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   120
 *     <li>Once a result is passed to the combiner or finisher function, it
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   121
 *     is never passed to the accumulator function again.</li>
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   122
 *     <li>For non-concurrent collectors, any result returned from the result
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   123
 *     supplier, accumulator, or combiner functions must be serially
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   124
 *     thread-confined.  This enables collection to occur in parallel without
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   125
 *     the {@code Collector} needing to implement any additional synchronization.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   126
 *     The reduction implementation must manage that the input is properly
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   127
 *     partitioned, that partitions are processed in isolation, and combining
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   128
 *     happens only after accumulation is complete.</li>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   129
 *     <li>For concurrent collectors, an implementation is free to (but not
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   130
 *     required to) implement reduction concurrently.  A concurrent reduction
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   131
 *     is one where the accumulator function is called concurrently from
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   132
 *     multiple threads, using the same concurrently-modifiable result container,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   133
 *     rather than keeping the result isolated during accumulation.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   134
 *     A concurrent reduction should only be applied if the collector has the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   135
 *     {@link Characteristics#UNORDERED} characteristics or if the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   136
 *     originating data is unordered.</li>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   137
 * </ul>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   138
 *
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   139
 * <p>In addition to the predefined implementations in {@link Collectors}, the
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   140
 * static factory methods {@link #of(Supplier, BiConsumer, BinaryOperator, Characteristics...)}
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   141
 * can be used to construct collectors.  For example, you could create a collector
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   142
 * that accumulates widgets into a {@code TreeSet} with:
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   143
 *
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   144
 * <pre>{@code
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   145
 *     Collector<Widget, ?, TreeSet<Widget>> intoSet =
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   146
 *         Collector.of(TreeSet::new, TreeSet::add,
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   147
 *                      (left, right) -> { left.addAll(right); return left; });
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   148
 * }</pre>
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   149
 *
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   150
 * (This behavior is also implemented by the predefined collector
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   151
 * {@link Collectors#toCollection(Supplier)}).
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   152
 *
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   153
 * @apiNote
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   154
 * Performing a reduction operation with a {@code Collector} should produce a
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   155
 * result equivalent to:
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   156
 * <pre>{@code
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   157
 *     R container = collector.supplier().get();
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   158
 *     for (T t : data)
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   159
 *         collector.accumulator().accept(container, t);
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   160
 *     return collector.finisher().apply(container);
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   161
 * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   162
 *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   163
 * <p>However, the library is free to partition the input, perform the reduction
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   164
 * on the partitions, and then use the combiner function to combine the partial
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   165
 * results to achieve a parallel reduction.  (Depending on the specific reduction
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   166
 * operation, this may perform better or worse, depending on the relative cost
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   167
 * of the accumulator and combiner functions.)
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   168
 *
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   169
 * <p>Collectors are designed to be <em>composed</em>; many of the methods
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   170
 * in {@link Collectors} are functions that take a collector and produce
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   171
 * a new collector.  For example, given the following collector that computes
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   172
 * the sum of the salaries of a stream of employees:
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   173
 *
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   174
 * <pre>{@code
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   175
 *     Collector<Employee, ?, Integer> summingSalaries
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   176
 *         = Collectors.summingInt(Employee::getSalary))
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   177
 * }</pre>
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   178
 *
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   179
 * If we wanted to create a collector to tabulate the sum of salaries by
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   180
 * department, we could reuse the "sum of salaries" logic using
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   181
 * {@link Collectors#groupingBy(Function, Collector)}:
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   182
 *
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   183
 * <pre>{@code
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   184
 *     Collector<Employee, ?, Map<Department, Integer>> summingSalariesByDept
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   185
 *         = Collectors.groupingBy(Employee::getDepartment, summingSalaries);
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   186
 * }</pre>
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   187
 *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   188
 * @see Stream#collect(Collector)
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   189
 * @see Collectors
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   190
 *
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   191
 * @param <T> the type of input elements to the reduction operation
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   192
 * @param <A> the mutable accumulation type of the reduction operation (often
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   193
 *            hidden as an implementation detail)
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   194
 * @param <R> the result type of the reduction operation
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   195
 * @since 1.8
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   196
 */
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   197
public interface Collector<T, A, R> {
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   198
    /**
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   199
     * A function that creates and returns a new mutable result container.
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   200
     *
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   201
     * @return a function which returns a new, mutable result container
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   202
     */
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   203
    Supplier<A> supplier();
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   204
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   205
    /**
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   206
     * A function that folds a value into a mutable result container.
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   207
     *
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   208
     * @return a function which folds a value into a mutable result container
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   209
     */
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   210
    BiConsumer<A, T> accumulator();
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   211
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   212
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   213
     * A function that accepts two partial results and merges them.  The
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   214
     * combiner function may fold state from one argument into the other and
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   215
     * return that, or may return a new result container.
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   216
     *
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   217
     * @return a function which combines two partial results into a combined
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   218
     * result
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   219
     */
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   220
    BinaryOperator<A> combiner();
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   221
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   222
    /**
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   223
     * Perform the final transformation from the intermediate accumulation type
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   224
     * {@code A} to the final result type {@code R}.
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   225
     *
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   226
     * <p>If the characteristic {@code IDENTITY_TRANSFORM} is
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   227
     * set, this function may be presumed to be an identity transform with an
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   228
     * unchecked cast from {@code A} to {@code R}.
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   229
     *
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   230
     * @return a function which transforms the intermediate result to the final
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   231
     * result
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   232
     */
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   233
    Function<A, R> finisher();
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   234
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   235
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   236
     * Returns a {@code Set} of {@code Collector.Characteristics} indicating
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   237
     * the characteristics of this Collector.  This set should be immutable.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   238
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   239
     * @return an immutable set of collector characteristics
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   240
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   241
    Set<Characteristics> characteristics();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   242
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   243
    /**
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   244
     * Returns a new {@code Collector} described by the given {@code supplier},
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   245
     * {@code accumulator}, and {@code combiner} functions.  The resulting
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   246
     * {@code Collector} has the {@code Collector.Characteristics.IDENTITY_FINISH}
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   247
     * characteristic.
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   248
     *
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   249
     * @param supplier The supplier function for the new collector
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   250
     * @param accumulator The accumulator function for the new collector
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   251
     * @param combiner The combiner function for the new collector
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   252
     * @param characteristics The collector characteristics for the new
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   253
     *                        collector
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   254
     * @param <T> The type of input elements for the new collector
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   255
     * @param <R> The type of intermediate accumulation result, and final result,
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   256
     *           for the new collector
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   257
     * @throws NullPointerException if any argument is null
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   258
     * @return the new {@code Collector}
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   259
     */
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   260
    public static<T, R> Collector<T, R, R> of(Supplier<R> supplier,
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   261
                                              BiConsumer<R, T> accumulator,
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   262
                                              BinaryOperator<R> combiner,
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   263
                                              Characteristics... characteristics) {
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   264
        Objects.requireNonNull(supplier);
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   265
        Objects.requireNonNull(accumulator);
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   266
        Objects.requireNonNull(combiner);
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   267
        Objects.requireNonNull(characteristics);
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   268
        Set<Characteristics> cs = (characteristics.length == 0)
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   269
                                  ? Collectors.CH_ID
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   270
                                  : Collections.unmodifiableSet(EnumSet.of(Collector.Characteristics.IDENTITY_FINISH,
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   271
                                                                           characteristics));
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   272
        return new Collectors.CollectorImpl<>(supplier, accumulator, combiner, cs);
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   273
    }
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   274
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   275
    /**
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   276
     * Returns a new {@code Collector} described by the given {@code supplier},
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   277
     * {@code accumulator}, {@code combiner}, and {@code finisher} functions.
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   278
     *
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   279
     * @param supplier The supplier function for the new collector
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   280
     * @param accumulator The accumulator function for the new collector
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   281
     * @param combiner The combiner function for the new collector
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   282
     * @param finisher The finisher function for the new collector
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   283
     * @param characteristics The collector characteristics for the new
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   284
     *                        collector
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   285
     * @param <T> The type of input elements for the new collector
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   286
     * @param <A> The intermediate accumulation type of the new collector
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   287
     * @param <R> The final result type of the new collector
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   288
     * @throws NullPointerException if any argument is null
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   289
     * @return the new {@code Collector}
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   290
     */
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   291
    public static<T, A, R> Collector<T, A, R> of(Supplier<A> supplier,
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   292
                                                 BiConsumer<A, T> accumulator,
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   293
                                                 BinaryOperator<A> combiner,
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   294
                                                 Function<A, R> finisher,
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   295
                                                 Characteristics... characteristics) {
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   296
        Objects.requireNonNull(supplier);
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   297
        Objects.requireNonNull(accumulator);
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   298
        Objects.requireNonNull(combiner);
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   299
        Objects.requireNonNull(finisher);
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   300
        Objects.requireNonNull(characteristics);
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   301
        Set<Characteristics> cs = Collectors.CH_NOID;
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   302
        if (characteristics.length > 0) {
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   303
            cs = EnumSet.noneOf(Characteristics.class);
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   304
            Collections.addAll(cs, characteristics);
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   305
            cs = Collections.unmodifiableSet(cs);
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   306
        }
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   307
        return new Collectors.CollectorImpl<>(supplier, accumulator, combiner, finisher, cs);
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   308
    }
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   309
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   310
    /**
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   311
     * Characteristics indicating properties of a {@code Collector}, which can
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   312
     * be used to optimize reduction implementations.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   313
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   314
    enum Characteristics {
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   315
        /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   316
         * Indicates that this collector is <em>concurrent</em>, meaning that
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   317
         * the result container can support the accumulator function being
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   318
         * called concurrently with the same result container from multiple
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   319
         * threads.
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   320
         *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   321
         * <p>If a {@code CONCURRENT} collector is not also {@code UNORDERED},
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   322
         * then it should only be evaluated concurrently if applied to an
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   323
         * unordered data source.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   324
         */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   325
        CONCURRENT,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   326
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   327
        /**
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   328
         * Indicates that the collection operation does not commit to preserving
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   329
         * the encounter order of input elements.  (This might be true if the
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19214
diff changeset
   330
         * result container has no intrinsic order, such as a {@link Set}.)
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   331
         */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   332
        UNORDERED,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   333
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   334
        /**
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   335
         * Indicates that the finisher function is the identity function and
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   336
         * can be elided.  If set, it must be the case that an unchecked cast
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   337
         * from A to R will succeed.
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   338
         */
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 17167
diff changeset
   339
        IDENTITY_FINISH
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   340
    }
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   341
}