From 7c658527094083b2037d362916adf8eb2493ea65 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Tue, 27 Jul 2021 12:57:32 -0400 Subject: [PATCH] Close Javadoc tags. --- .../org/apache/commons/lang3/Streams.java | 75 ++++++++++++++----- .../apache/commons/lang3/stream/Streams.java | 21 +++++- 2 files changed, 77 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/Streams.java b/src/main/java/org/apache/commons/lang3/Streams.java index c284944f9..73330374e 100644 --- a/src/main/java/org/apache/commons/lang3/Streams.java +++ b/src/main/java/org/apache/commons/lang3/Streams.java @@ -101,7 +101,9 @@ public class Streams { * Returns a FailableStream consisting of the elements of this stream that match * the given FailablePredicate. * - *

This is an intermediate operation. + *

+ * This is an intermediate operation. + *

* * @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. * - *

This is a terminal operation. + *

+ * This is an intermediate operation. + *

* - *

The behavior of this operation is explicitly nondeterministic. + *

+ * The behavior of this operation is explicitly nondeterministic. * For parallel stream pipelines, this operation does not * 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. + *

* * @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. * - *

If the underlying stream is parallel, and the {@code Collector} + *

+ * 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.) + *

* - *

This is a terminal operation. + *

+ * This is an intermediate operation. + *

* - *

When executed in parallel, multiple intermediate results may be + *

+ * 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. - * + *

+ *

* Note * The following will accumulate strings into an ArrayList: + *

*
{@code
          *     List asList = stringStream.collect(Collectors.toList());
          * }
* - *

The following will classify {@code Person} objects by city: + *

+ * The following will classify {@code Person} objects by city: + *

*
{@code
          *     Map> peopleByCity
          *         = personStream.collect(Collectors.groupingBy(Person::getCity));
          * }
* - *

The following will classify {@code Person} objects by state and city, + *

+ * The following will classify {@code Person} objects by state and city, * cascading two {@code Collector}s together: + *

*
{@code
          *     Map>> peopleByStateAndCity
          *         = personStream.collect(Collectors.groupingBy(Person::getState,
@@ -198,21 +215,29 @@ public class Streams {
          *     return result;
          * }
* - *

Like {@link #reduce(Object, BinaryOperator)}, {@code collect} operations + *

+ * Like {@link #reduce(Object, BinaryOperator)}, {@code collect} operations * can be parallelized without requiring additional synchronization. + *

* - *

This is a terminal operation. + *

+ * This is an intermediate operation. + *

* + *

* 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}: + *

*
{@code
          *     List asList = stringStream.collect(ArrayList::new, ArrayList::add,
          *                                                ArrayList::addAll);
          * }
* - *

The following will take a stream of strings and concatenates them into a + *

+ * The following will take a stream of strings and concatenates them into a * single string: + *

*
{@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.
          *
-         * 

The {@code identity} value must be an identity for the accumulator + *

+ * 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. + *

* - *

This is a terminal operation. + *

+ * This is an intermediate operation. + *

* * 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); * }
* - *

While this may seem a more roundabout way to perform an aggregation + *

+ * 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. + *

* * @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. * - *

This is an intermediate operation. + *

+ * This is an intermediate operation. + *

* * @param 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. * - *

This is a short-circuiting terminal operation. + *

+ * This is a short-circuiting terminal operation. + *

* + *

* Note * This method evaluates the universal quantification 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 vacuously * satisfied and is always {@code true} (regardless of P(x)). + *

* * @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. * - *

This is a short-circuiting terminal operation. + *

+ * This is a short-circuiting terminal operation. + *

* * Note * This method evaluates the existential quantification of the diff --git a/src/main/java/org/apache/commons/lang3/stream/Streams.java b/src/main/java/org/apache/commons/lang3/stream/Streams.java index fd981e604..cd112e7d9 100644 --- a/src/main/java/org/apache/commons/lang3/stream/Streams.java +++ b/src/main/java/org/apache/commons/lang3/stream/Streams.java @@ -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: *
  *     Consumer<java.lang.reflect.Method> consumer = m -> {
  *         try {
@@ -54,7 +54,9 @@ import org.apache.commons.lang3.function.FailablePredicate;
  *    };
  *    stream.forEach(consumer);
  * 
+ *

* Using a {@link FailableStream}, this can be rewritten as follows: + *

*
  *     Streams.failable(stream).forEach((m) -> m.invoke(o, args));
  * 
@@ -140,6 +142,7 @@ public class Streams { * *

* This is a short-circuiting terminal operation. + *

* * Note This method evaluates the universal quantification 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 vacuously @@ -161,6 +164,7 @@ public class Streams { * *

* This is a short-circuiting terminal operation. + *

* * Note This method evaluates the existential quantification 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.) + *

* *

* This is a terminal operation. + *

* *

* 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. + *

* * Note The following will accumulate strings into an ArrayList: * @@ -214,6 +221,7 @@ public class Streams { * *

* The following will classify {@code Person} objects by city: + *

* *
          *     {@code
@@ -224,6 +232,7 @@ public class Streams {
          * 

* The following will classify {@code Person} objects by state and city, cascading two {@code Collector}s * together: + *

* *
          *     {@code
@@ -262,9 +271,11 @@ public class Streams {
          * 

* Like {@link #reduce(Object, BinaryOperator)}, {@code collect} operations can be parallelized without * requiring additional synchronization. + *

* *

* This is a terminal operation. + *

* * 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 { * *

* The following will take a stream of strings and concatenates them into a single string: + *

* *
          *     {@code
@@ -307,6 +319,7 @@ public class Streams {
          *
          * 

* This is an intermediate operation. + *

* * @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 { * *

* This is a terminal operation. + *

* *

* 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. + *

* * @param action a non-interfering action to perform on the elements */ @@ -353,6 +368,7 @@ public class Streams { * *

* This is an intermediate operation. + *

* * @param 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. + *

* *

* This is a terminal operation. + *

* * 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. + *

* * @param identity the identity value for the accumulating function * @param accumulator an associative, non-interfering, stateless function for combining two values