Close Javadoc tags.
This commit is contained in:
parent
66455cbaf8
commit
7c65852709
|
@ -101,7 +101,9 @@ public class Streams {
|
|||
* Returns a FailableStream consisting of the elements of this stream that match
|
||||
* the given FailablePredicate.
|
||||
*
|
||||
* <p>This is an intermediate operation.
|
||||
* <p>
|
||||
* This is an intermediate operation.
|
||||
* </p>
|
||||
*
|
||||
* @param predicate a non-interfering, stateless predicate to apply to each
|
||||
* element to determine if it should be included.
|
||||
|
@ -116,15 +118,19 @@ public class Streams {
|
|||
/**
|
||||
* Performs an action for each element of this stream.
|
||||
*
|
||||
* <p>This is a terminal operation.
|
||||
* <p>
|
||||
* This is an intermediate operation.
|
||||
* </p>
|
||||
*
|
||||
* <p>The behavior of this operation is explicitly nondeterministic.
|
||||
* <p>
|
||||
* The behavior of this operation is explicitly nondeterministic.
|
||||
* For parallel stream pipelines, this operation does <em>not</em>
|
||||
* guarantee to respect the encounter order of the stream, as doing so
|
||||
* would sacrifice the benefit of parallelism. For any given element, the
|
||||
* action may be performed at whatever time and in whatever thread the
|
||||
* library chooses. If the action accesses shared state, it is
|
||||
* responsible for providing the required synchronization.
|
||||
* </p>
|
||||
*
|
||||
* @param action a non-interfering action to perform on the elements
|
||||
*/
|
||||
|
@ -141,33 +147,44 @@ public class Streams {
|
|||
* collection strategies and composition of collect operations such as
|
||||
* multiple-level grouping or partitioning.
|
||||
*
|
||||
* <p>If the underlying stream is parallel, and the {@code Collector}
|
||||
* <p>
|
||||
* If the underlying stream is parallel, and the {@code Collector}
|
||||
* is concurrent, and either the stream is unordered or the collector is
|
||||
* unordered, then a concurrent reduction will be performed
|
||||
* (see {@link Collector} for details on concurrent reduction.)
|
||||
* </p>
|
||||
*
|
||||
* <p>This is a terminal operation.
|
||||
* <p>
|
||||
* This is an intermediate operation.
|
||||
* </p>
|
||||
*
|
||||
* <p>When executed in parallel, multiple intermediate results may be
|
||||
* <p>
|
||||
* When executed in parallel, multiple intermediate results may be
|
||||
* instantiated, populated, and merged so as to maintain isolation of
|
||||
* mutable data structures. Therefore, even when executed in parallel
|
||||
* with non-thread-safe data structures (such as {@code ArrayList}), no
|
||||
* additional synchronization is needed for a parallel reduction.
|
||||
*
|
||||
* </p>
|
||||
* <p>
|
||||
* Note
|
||||
* The following will accumulate strings into an ArrayList:
|
||||
* </p>
|
||||
* <pre>{@code
|
||||
* List<String> asList = stringStream.collect(Collectors.toList());
|
||||
* }</pre>
|
||||
*
|
||||
* <p>The following will classify {@code Person} objects by city:
|
||||
* <p>
|
||||
* The following will classify {@code Person} objects by city:
|
||||
* </p>
|
||||
* <pre>{@code
|
||||
* Map<String, List<Person>> peopleByCity
|
||||
* = personStream.collect(Collectors.groupingBy(Person::getCity));
|
||||
* }</pre>
|
||||
*
|
||||
* <p>The following will classify {@code Person} objects by state and city,
|
||||
* <p>
|
||||
* The following will classify {@code Person} objects by state and city,
|
||||
* cascading two {@code Collector}s together:
|
||||
* </p>
|
||||
* <pre>{@code
|
||||
* Map<String, Map<String, List<Person>>> peopleByStateAndCity
|
||||
* = personStream.collect(Collectors.groupingBy(Person::getState,
|
||||
|
@ -198,21 +215,29 @@ public class Streams {
|
|||
* return result;
|
||||
* }</pre>
|
||||
*
|
||||
* <p>Like {@link #reduce(Object, BinaryOperator)}, {@code collect} operations
|
||||
* <p>
|
||||
* Like {@link #reduce(Object, BinaryOperator)}, {@code collect} operations
|
||||
* can be parallelized without requiring additional synchronization.
|
||||
* </p>
|
||||
*
|
||||
* <p>This is a terminal operation.
|
||||
* <p>
|
||||
* This is an intermediate operation.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* Note There are many existing classes in the JDK whose signatures are
|
||||
* well-suited for use with method references as arguments to {@code collect()}.
|
||||
* For example, the following will accumulate strings into an {@code ArrayList}:
|
||||
* </p>
|
||||
* <pre>{@code
|
||||
* List<String> asList = stringStream.collect(ArrayList::new, ArrayList::add,
|
||||
* ArrayList::addAll);
|
||||
* }</pre>
|
||||
*
|
||||
* <p>The following will take a stream of strings and concatenates them into a
|
||||
* <p>
|
||||
* The following will take a stream of strings and concatenates them into a
|
||||
* single string:
|
||||
* </p>
|
||||
* <pre>{@code
|
||||
* String concat = stringStream.collect(StringBuilder::new, StringBuilder::append,
|
||||
* StringBuilder::append)
|
||||
|
@ -249,12 +274,16 @@ public class Streams {
|
|||
*
|
||||
* but is not constrained to execute sequentially.
|
||||
*
|
||||
* <p>The {@code identity} value must be an identity for the accumulator
|
||||
* <p>
|
||||
* The {@code identity} value must be an identity for the accumulator
|
||||
* function. This means that for all {@code t},
|
||||
* {@code accumulator.apply(identity, t)} is equal to {@code t}.
|
||||
* The {@code accumulator} function must be an associative function.
|
||||
* </p>
|
||||
*
|
||||
* <p>This is a terminal operation.
|
||||
* <p>
|
||||
* This is an intermediate operation.
|
||||
* </p>
|
||||
*
|
||||
* Note Sum, min, max, average, and string concatenation are all special
|
||||
* cases of reduction. Summing a stream of numbers can be expressed as:
|
||||
|
@ -269,10 +298,12 @@ public class Streams {
|
|||
* Integer sum = integers.reduce(0, Integer::sum);
|
||||
* }</pre>
|
||||
*
|
||||
* <p>While this may seem a more roundabout way to perform an aggregation
|
||||
* <p>
|
||||
* While this may seem a more roundabout way to perform an aggregation
|
||||
* compared to simply mutating a running total in a loop, reduction
|
||||
* operations parallelize more gracefully, without needing additional
|
||||
* synchronization and with greatly reduced risk of data races.
|
||||
* </p>
|
||||
*
|
||||
* @param identity the identity value for the accumulating function
|
||||
* @param accumulator an associative, non-interfering, stateless
|
||||
|
@ -288,7 +319,9 @@ public class Streams {
|
|||
* Returns a stream consisting of the results of applying the given
|
||||
* function to the elements of this stream.
|
||||
*
|
||||
* <p>This is an intermediate operation.
|
||||
* <p>
|
||||
* This is an intermediate operation.
|
||||
* </p>
|
||||
*
|
||||
* @param <R> The element type of the new stream
|
||||
* @param mapper A non-interfering, stateless function to apply to each element
|
||||
|
@ -313,13 +346,17 @@ public class Streams {
|
|||
* determining the result. If the stream is empty then {@code true} is
|
||||
* returned and the predicate is not evaluated.
|
||||
*
|
||||
* <p>This is a short-circuiting terminal operation.
|
||||
* <p>
|
||||
* This is a short-circuiting terminal operation.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* Note
|
||||
* This method evaluates the <em>universal quantification</em> of the
|
||||
* predicate over the elements of the stream (for all x P(x)). If the
|
||||
* stream is empty, the quantification is said to be <em>vacuously
|
||||
* satisfied</em> and is always {@code true} (regardless of P(x)).
|
||||
* </p>
|
||||
*
|
||||
* @param predicate A non-interfering, stateless predicate to apply to
|
||||
* elements of this stream
|
||||
|
@ -337,7 +374,9 @@ public class Streams {
|
|||
* necessary for determining the result. If the stream is empty then
|
||||
* {@code false} is returned and the predicate is not evaluated.
|
||||
*
|
||||
* <p>This is a short-circuiting terminal operation.
|
||||
* <p>
|
||||
* This is a short-circuiting terminal operation.
|
||||
* </p>
|
||||
*
|
||||
* Note
|
||||
* This method evaluates the <em>existential quantification</em> of the
|
||||
|
|
|
@ -43,7 +43,7 @@ import org.apache.commons.lang3.function.FailablePredicate;
|
|||
* {@code java.util.stream} package, or more generally, with Java 8 lambdas. More
|
||||
* specifically, it attempts to address the fact that lambdas are supposed
|
||||
* not to throw Exceptions, at least not checked Exceptions, AKA instances
|
||||
* of {@link Exception}. This enforces the use of constructs like
|
||||
* of {@link Exception}. This enforces the use of constructs like:
|
||||
* <pre>
|
||||
* Consumer<java.lang.reflect.Method> consumer = m -> {
|
||||
* try {
|
||||
|
@ -54,7 +54,9 @@ import org.apache.commons.lang3.function.FailablePredicate;
|
|||
* };
|
||||
* stream.forEach(consumer);
|
||||
* </pre>
|
||||
* <p>
|
||||
* Using a {@link FailableStream}, this can be rewritten as follows:
|
||||
* </p>
|
||||
* <pre>
|
||||
* Streams.failable(stream).forEach((m) -> m.invoke(o, args));
|
||||
* </pre>
|
||||
|
@ -140,6 +142,7 @@ public class Streams {
|
|||
*
|
||||
* <p>
|
||||
* This is a short-circuiting terminal operation.
|
||||
* </p>
|
||||
*
|
||||
* Note This method evaluates the <em>universal quantification</em> of the predicate over the elements of
|
||||
* the stream (for all x P(x)). If the stream is empty, the quantification is said to be <em>vacuously
|
||||
|
@ -161,6 +164,7 @@ public class Streams {
|
|||
*
|
||||
* <p>
|
||||
* This is a short-circuiting terminal operation.
|
||||
* </p>
|
||||
*
|
||||
* Note This method evaluates the <em>existential quantification</em> of the predicate over the elements of
|
||||
* the stream (for some x P(x)).
|
||||
|
@ -194,15 +198,18 @@ public class Streams {
|
|||
* If the underlying stream is parallel, and the {@code Collector} is concurrent, and either the stream is
|
||||
* unordered or the collector is unordered, then a concurrent reduction will be performed (see {@link Collector}
|
||||
* for details on concurrent reduction.)
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* This is a terminal operation.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* When executed in parallel, multiple intermediate results may be instantiated, populated, and merged so as to
|
||||
* maintain isolation of mutable data structures. Therefore, even when executed in parallel with non-thread-safe
|
||||
* data structures (such as {@code ArrayList}), no additional synchronization is needed for a parallel
|
||||
* reduction.
|
||||
* </p>
|
||||
*
|
||||
* Note The following will accumulate strings into an ArrayList:
|
||||
*
|
||||
|
@ -214,6 +221,7 @@ public class Streams {
|
|||
*
|
||||
* <p>
|
||||
* The following will classify {@code Person} objects by city:
|
||||
* </p>
|
||||
*
|
||||
* <pre>
|
||||
* {@code
|
||||
|
@ -224,6 +232,7 @@ public class Streams {
|
|||
* <p>
|
||||
* The following will classify {@code Person} objects by state and city, cascading two {@code Collector}s
|
||||
* together:
|
||||
* </p>
|
||||
*
|
||||
* <pre>
|
||||
* {@code
|
||||
|
@ -262,9 +271,11 @@ public class Streams {
|
|||
* <p>
|
||||
* Like {@link #reduce(Object, BinaryOperator)}, {@code collect} operations can be parallelized without
|
||||
* requiring additional synchronization.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* This is a terminal operation.
|
||||
* </p>
|
||||
*
|
||||
* Note There are many existing classes in the JDK whose signatures are well-suited for use with method
|
||||
* references as arguments to {@code collect()}. For example, the following will accumulate strings into an
|
||||
|
@ -278,6 +289,7 @@ public class Streams {
|
|||
*
|
||||
* <p>
|
||||
* The following will take a stream of strings and concatenates them into a single string:
|
||||
* </p>
|
||||
*
|
||||
* <pre>
|
||||
* {@code
|
||||
|
@ -307,6 +319,7 @@ public class Streams {
|
|||
*
|
||||
* <p>
|
||||
* This is an intermediate operation.
|
||||
* </p>
|
||||
*
|
||||
* @param predicate a non-interfering, stateless predicate to apply to each element to determine if it should be
|
||||
* included.
|
||||
|
@ -323,6 +336,7 @@ public class Streams {
|
|||
*
|
||||
* <p>
|
||||
* This is a terminal operation.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* The behavior of this operation is explicitly nondeterministic. For parallel stream pipelines, this operation
|
||||
|
@ -330,6 +344,7 @@ public class Streams {
|
|||
* benefit of parallelism. For any given element, the action may be performed at whatever time and in whatever
|
||||
* thread the library chooses. If the action accesses shared state, it is responsible for providing the required
|
||||
* synchronization.
|
||||
* </p>
|
||||
*
|
||||
* @param action a non-interfering action to perform on the elements
|
||||
*/
|
||||
|
@ -353,6 +368,7 @@ public class Streams {
|
|||
*
|
||||
* <p>
|
||||
* This is an intermediate operation.
|
||||
* </p>
|
||||
*
|
||||
* @param <R> The element type of the new stream
|
||||
* @param mapper A non-interfering, stateless function to apply to each element
|
||||
|
@ -382,9 +398,11 @@ public class Streams {
|
|||
* The {@code identity} value must be an identity for the accumulator function. This means that for all
|
||||
* {@code t}, {@code accumulator.apply(identity, t)} is equal to {@code t}. The {@code accumulator} function
|
||||
* must be an associative function.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* This is a terminal operation.
|
||||
* </p>
|
||||
*
|
||||
* Note Sum, min, max, average, and string concatenation are all special cases of reduction. Summing a
|
||||
* stream of numbers can be expressed as:
|
||||
|
@ -407,6 +425,7 @@ public class Streams {
|
|||
* While this may seem a more roundabout way to perform an aggregation compared to simply mutating a running
|
||||
* total in a loop, reduction operations parallelize more gracefully, without needing additional synchronization
|
||||
* and with greatly reduced risk of data races.
|
||||
* </p>
|
||||
*
|
||||
* @param identity the identity value for the accumulating function
|
||||
* @param accumulator an associative, non-interfering, stateless function for combining two values
|
||||
|
|
Loading…
Reference in New Issue