From 7ec4e0c3e9fcd2e69d4e73099b87f63f58336750 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 11 Jul 2024 11:20:02 -0400 Subject: [PATCH] Javadoc --- .../apache/commons/collections4/Closure.java | 2 +- .../functors/CatchAndRethrowClosure.java | 7 ++--- .../collections4/functors/ChainedClosure.java | 15 ++++++----- .../functors/ExceptionClosure.java | 9 ++++--- .../collections4/functors/ForClosure.java | 11 ++++---- .../collections4/functors/IfClosure.java | 23 ++++++++-------- .../collections4/functors/NOPClosure.java | 5 ++-- .../collections4/functors/SwitchClosure.java | 27 ++++++++++--------- .../functors/TransformerClosure.java | 11 ++++---- .../collections4/functors/WhileClosure.java | 15 ++++++----- 10 files changed, 67 insertions(+), 58 deletions(-) diff --git a/src/main/java/org/apache/commons/collections4/Closure.java b/src/main/java/org/apache/commons/collections4/Closure.java index 84e33484d..ef6cf3246 100644 --- a/src/main/java/org/apache/commons/collections4/Closure.java +++ b/src/main/java/org/apache/commons/collections4/Closure.java @@ -29,7 +29,7 @@ import java.util.function.Consumer; * {@link ClosureUtils}. These include method invocation and for/while loops. *

* - * @param the type that the closure acts on + * @param the type of the input to the operation. * @since 1.0 * @deprecated Use {@link Consumer}. */ diff --git a/src/main/java/org/apache/commons/collections4/functors/CatchAndRethrowClosure.java b/src/main/java/org/apache/commons/collections4/functors/CatchAndRethrowClosure.java index d4d4b0ba7..a0c927a58 100644 --- a/src/main/java/org/apache/commons/collections4/functors/CatchAndRethrowClosure.java +++ b/src/main/java/org/apache/commons/collections4/functors/CatchAndRethrowClosure.java @@ -43,9 +43,10 @@ import org.apache.commons.collections4.FunctorException; * } * * + * @param the type of the input to the operation. * @since 4.0 */ -public abstract class CatchAndRethrowClosure implements Closure { +public abstract class CatchAndRethrowClosure implements Closure { /** * Execute this closure on the specified input object. @@ -55,7 +56,7 @@ public abstract class CatchAndRethrowClosure implements Closure { * checked exception. */ @Override - public void execute(final E input) { + public void execute(final T input) { try { executeAndThrow(input); } catch (final RuntimeException ex) { @@ -72,5 +73,5 @@ public abstract class CatchAndRethrowClosure implements Closure { * @throws Throwable if the closure execution resulted in a checked * exception. */ - protected abstract void executeAndThrow(E input) throws Throwable; + protected abstract void executeAndThrow(T input) throws Throwable; } diff --git a/src/main/java/org/apache/commons/collections4/functors/ChainedClosure.java b/src/main/java/org/apache/commons/collections4/functors/ChainedClosure.java index 3eeba857d..784cab9dd 100644 --- a/src/main/java/org/apache/commons/collections4/functors/ChainedClosure.java +++ b/src/main/java/org/apache/commons/collections4/functors/ChainedClosure.java @@ -25,9 +25,10 @@ import org.apache.commons.collections4.Closure; /** * Closure implementation that chains the specified closures together. * + * @param the type of the input to the operation. * @since 3.0 */ -public class ChainedClosure implements Closure, Serializable { +public class ChainedClosure implements Closure, Serializable { /** Serial version UID */ private static final long serialVersionUID = -3520677225766901240L; @@ -77,7 +78,7 @@ public class ChainedClosure implements Closure, Serializable { } /** The closures to call in turn */ - private final Closure[] iClosures; + private final Closure[] iClosures; /** * Hidden constructor for the use by the static factory methods. @@ -85,7 +86,7 @@ public class ChainedClosure implements Closure, Serializable { * @param clone if {@code true} the input argument will be cloned * @param closures the closures to chain, no nulls */ - private ChainedClosure(final boolean clone, final Closure... closures) { + private ChainedClosure(final boolean clone, final Closure... closures) { iClosures = clone ? FunctorUtils.copy(closures) : closures; } @@ -95,7 +96,7 @@ public class ChainedClosure implements Closure, Serializable { * * @param closures the closures to chain, copied, no nulls */ - public ChainedClosure(final Closure... closures) { + public ChainedClosure(final Closure... closures) { this(true, closures); } @@ -105,8 +106,8 @@ public class ChainedClosure implements Closure, Serializable { * @param input the input object passed to each closure */ @Override - public void execute(final E input) { - for (final Closure iClosure : iClosures) { + public void execute(final T input) { + for (final Closure iClosure : iClosures) { iClosure.accept(input); } } @@ -117,7 +118,7 @@ public class ChainedClosure implements Closure, Serializable { * @return a copy of the closures * @since 3.1 */ - public Closure[] getClosures() { + public Closure[] getClosures() { return FunctorUtils.copy(iClosures); } diff --git a/src/main/java/org/apache/commons/collections4/functors/ExceptionClosure.java b/src/main/java/org/apache/commons/collections4/functors/ExceptionClosure.java index 1b5196d25..58e91c64b 100644 --- a/src/main/java/org/apache/commons/collections4/functors/ExceptionClosure.java +++ b/src/main/java/org/apache/commons/collections4/functors/ExceptionClosure.java @@ -24,9 +24,10 @@ import org.apache.commons.collections4.FunctorException; /** * Closure implementation that always throws an exception. * + * @param the type of the input to the operation. * @since 3.0 */ -public final class ExceptionClosure implements Closure, Serializable { +public final class ExceptionClosure implements Closure, Serializable { /** Serial version UID */ private static final long serialVersionUID = 7179106032121985545L; @@ -38,11 +39,11 @@ public final class ExceptionClosure implements Closure, Serializable { /** * Factory returning the singleton instance. * - * @param the type that the closure acts on + * @param the type of the input to the operation. * @return the singleton instance * @since 3.1 */ - public static Closure exceptionClosure() { + public static Closure exceptionClosure() { return INSTANCE; } @@ -59,7 +60,7 @@ public final class ExceptionClosure implements Closure, Serializable { * @throws FunctorException always */ @Override - public void execute(final E input) { + public void execute(final T input) { throw new FunctorException("ExceptionClosure invoked"); } diff --git a/src/main/java/org/apache/commons/collections4/functors/ForClosure.java b/src/main/java/org/apache/commons/collections4/functors/ForClosure.java index 907d6e80a..09c1effca 100644 --- a/src/main/java/org/apache/commons/collections4/functors/ForClosure.java +++ b/src/main/java/org/apache/commons/collections4/functors/ForClosure.java @@ -27,9 +27,10 @@ import org.apache.commons.collections4.Closure; * for more details. *

* + * @param the type of the input to the operation. * @since 3.0 */ -public class ForClosure implements Closure { +public class ForClosure implements Closure { /** * Factory method that performs validation. @@ -56,7 +57,7 @@ public class ForClosure implements Closure { private final int iCount; /** The closure to call */ - private final Closure iClosure; + private final Closure iClosure; /** * Constructor that performs no validation. @@ -65,7 +66,7 @@ public class ForClosure implements Closure { * @param count the number of times to execute the closure * @param closure the closure to execute, not null */ - public ForClosure(final int count, final Closure closure) { + public ForClosure(final int count, final Closure closure) { iCount = count; iClosure = closure; } @@ -76,7 +77,7 @@ public class ForClosure implements Closure { * @param input the input object */ @Override - public void execute(final E input) { + public void execute(final T input) { for (int i = 0; i < iCount; i++) { iClosure.accept(input); } @@ -88,7 +89,7 @@ public class ForClosure implements Closure { * @return the closure * @since 3.1 */ - public Closure getClosure() { + public Closure getClosure() { return iClosure; } diff --git a/src/main/java/org/apache/commons/collections4/functors/IfClosure.java b/src/main/java/org/apache/commons/collections4/functors/IfClosure.java index d2d10d9e3..886127a09 100644 --- a/src/main/java/org/apache/commons/collections4/functors/IfClosure.java +++ b/src/main/java/org/apache/commons/collections4/functors/IfClosure.java @@ -26,9 +26,10 @@ import org.apache.commons.collections4.Predicate; * Closure implementation acts as an if statement calling one or other closure * based on a predicate. * + * @param the type of the input to the operation. * @since 3.0 */ -public class IfClosure implements Closure, Serializable { +public class IfClosure implements Closure, Serializable { /** Serial version UID */ private static final long serialVersionUID = 3518477308466486130L; @@ -67,13 +68,13 @@ public class IfClosure implements Closure, Serializable { Objects.requireNonNull(falseClosure, "falseClosure")); } /** The test */ - private final Predicate iPredicate; + private final Predicate iPredicate; /** The closure to use if true */ - private final Closure iTrueClosure; + private final Closure iTrueClosure; /** The closure to use if false */ - private final Closure iFalseClosure; + private final Closure iFalseClosure; /** * Constructor that performs no validation. @@ -86,7 +87,7 @@ public class IfClosure implements Closure, Serializable { * @param trueClosure closure used if true, not null * @since 3.2 */ - public IfClosure(final Predicate predicate, final Closure trueClosure) { + public IfClosure(final Predicate predicate, final Closure trueClosure) { this(predicate, trueClosure, NOPClosure.nopClosure()); } @@ -98,8 +99,8 @@ public class IfClosure implements Closure, Serializable { * @param trueClosure closure used if true, not null * @param falseClosure closure used if false, not null */ - public IfClosure(final Predicate predicate, final Closure trueClosure, - final Closure falseClosure) { + public IfClosure(final Predicate predicate, final Closure trueClosure, + final Closure falseClosure) { iPredicate = predicate; iTrueClosure = trueClosure; iFalseClosure = falseClosure; @@ -111,7 +112,7 @@ public class IfClosure implements Closure, Serializable { * @param input the input object */ @Override - public void execute(final E input) { + public void execute(final T input) { if (iPredicate.test(input)) { iTrueClosure.accept(input); } else { @@ -125,7 +126,7 @@ public class IfClosure implements Closure, Serializable { * @return the closure * @since 3.1 */ - public Closure getFalseClosure() { + public Closure getFalseClosure() { return iFalseClosure; } @@ -135,7 +136,7 @@ public class IfClosure implements Closure, Serializable { * @return the predicate * @since 3.1 */ - public Predicate getPredicate() { + public Predicate getPredicate() { return iPredicate; } @@ -145,7 +146,7 @@ public class IfClosure implements Closure, Serializable { * @return the closure * @since 3.1 */ - public Closure getTrueClosure() { + public Closure getTrueClosure() { return iTrueClosure; } diff --git a/src/main/java/org/apache/commons/collections4/functors/NOPClosure.java b/src/main/java/org/apache/commons/collections4/functors/NOPClosure.java index 252221e7f..1c3feac49 100644 --- a/src/main/java/org/apache/commons/collections4/functors/NOPClosure.java +++ b/src/main/java/org/apache/commons/collections4/functors/NOPClosure.java @@ -23,9 +23,10 @@ import org.apache.commons.collections4.Closure; /** * Closure implementation that does nothing. * + * @param the type of the input to the operation. * @since 3.0 */ -public final class NOPClosure implements Closure, Serializable { +public final class NOPClosure implements Closure, Serializable { /** Serial version UID */ private static final long serialVersionUID = 3518477308466486130L; @@ -57,7 +58,7 @@ public final class NOPClosure implements Closure, Serializable { * @param input the input object */ @Override - public void execute(final E input) { + public void execute(final T input) { // do nothing } diff --git a/src/main/java/org/apache/commons/collections4/functors/SwitchClosure.java b/src/main/java/org/apache/commons/collections4/functors/SwitchClosure.java index 32775d0df..d623f1cf4 100644 --- a/src/main/java/org/apache/commons/collections4/functors/SwitchClosure.java +++ b/src/main/java/org/apache/commons/collections4/functors/SwitchClosure.java @@ -27,9 +27,10 @@ import org.apache.commons.collections4.Predicate; * Closure implementation calls the closure whose predicate returns true, * like a switch statement. * + * @param the type of the input to the operation. * @since 3.0 */ -public class SwitchClosure implements Closure, Serializable { +public class SwitchClosure implements Closure, Serializable { /** Serial version UID */ private static final long serialVersionUID = 3518477308466486130L; @@ -98,13 +99,13 @@ public class SwitchClosure implements Closure, Serializable { return new SwitchClosure<>(predicates, closures, defaultClosure); } /** The tests to consider */ - private final Predicate[] iPredicates; + private final Predicate[] iPredicates; /** The matching closures to call */ - private final Closure[] iClosures; + private final Closure[] iClosures; /** The default closure to call if no tests match */ - private final Closure iDefault; + private final Closure iDefault; /** * Hidden constructor for the use by the static factory methods. @@ -114,11 +115,11 @@ public class SwitchClosure implements Closure, Serializable { * @param closures matching array of closures, no nulls * @param defaultClosure the closure to use if no match, null means nop */ - private SwitchClosure(final boolean clone, final Predicate[] predicates, - final Closure[] closures, final Closure defaultClosure) { + private SwitchClosure(final boolean clone, final Predicate[] predicates, + final Closure[] closures, final Closure defaultClosure) { iPredicates = clone ? FunctorUtils.copy(predicates) : predicates; iClosures = clone ? FunctorUtils.copy(closures) : closures; - iDefault = defaultClosure == null ? NOPClosure.nopClosure() : defaultClosure; + iDefault = defaultClosure == null ? NOPClosure.nopClosure() : defaultClosure; } /** @@ -129,8 +130,8 @@ public class SwitchClosure implements Closure, Serializable { * @param closures matching array of closures, cloned, no nulls * @param defaultClosure the closure to use if no match, null means nop */ - public SwitchClosure(final Predicate[] predicates, final Closure[] closures, - final Closure defaultClosure) { + public SwitchClosure(final Predicate[] predicates, final Closure[] closures, + final Closure defaultClosure) { this(true, predicates, closures, defaultClosure); } @@ -140,7 +141,7 @@ public class SwitchClosure implements Closure, Serializable { * @param input the input object */ @Override - public void execute(final E input) { + public void execute(final T input) { for (int i = 0; i < iPredicates.length; i++) { if (iPredicates[i].test(input)) { iClosures[i].accept(input); @@ -156,7 +157,7 @@ public class SwitchClosure implements Closure, Serializable { * @return a copy of the closures * @since 3.1 */ - public Closure[] getClosures() { + public Closure[] getClosures() { return FunctorUtils.copy(iClosures); } @@ -166,7 +167,7 @@ public class SwitchClosure implements Closure, Serializable { * @return the default closure * @since 3.1 */ - public Closure getDefaultClosure() { + public Closure getDefaultClosure() { return iDefault; } @@ -176,7 +177,7 @@ public class SwitchClosure implements Closure, Serializable { * @return a copy of the predicates * @since 3.1 */ - public Predicate[] getPredicates() { + public Predicate[] getPredicates() { return FunctorUtils.copy(iPredicates); } diff --git a/src/main/java/org/apache/commons/collections4/functors/TransformerClosure.java b/src/main/java/org/apache/commons/collections4/functors/TransformerClosure.java index bcc03eee9..8a528030f 100644 --- a/src/main/java/org/apache/commons/collections4/functors/TransformerClosure.java +++ b/src/main/java/org/apache/commons/collections4/functors/TransformerClosure.java @@ -25,9 +25,10 @@ import org.apache.commons.collections4.Transformer; * Closure implementation that calls a Transformer using the input object * and ignore the result. * + * @param the type of the input to the operation. * @since 3.0 */ -public class TransformerClosure implements Closure, Serializable { +public class TransformerClosure implements Closure, Serializable { /** Serial version UID */ private static final long serialVersionUID = -5194992589193388969L; @@ -49,7 +50,7 @@ public class TransformerClosure implements Closure, Serializable { } /** The transformer to wrap */ - private final Transformer iTransformer; + private final Transformer iTransformer; /** * Constructor that performs no validation. @@ -57,7 +58,7 @@ public class TransformerClosure implements Closure, Serializable { * * @param transformer the transformer to call, not null */ - public TransformerClosure(final Transformer transformer) { + public TransformerClosure(final Transformer transformer) { iTransformer = transformer; } @@ -67,7 +68,7 @@ public class TransformerClosure implements Closure, Serializable { * @param input the input object */ @Override - public void execute(final E input) { + public void execute(final T input) { iTransformer.transform(input); } @@ -77,7 +78,7 @@ public class TransformerClosure implements Closure, Serializable { * @return the transformer * @since 3.1 */ - public Transformer getTransformer() { + public Transformer getTransformer() { return iTransformer; } diff --git a/src/main/java/org/apache/commons/collections4/functors/WhileClosure.java b/src/main/java/org/apache/commons/collections4/functors/WhileClosure.java index 39a52c01e..c4bbea5b8 100644 --- a/src/main/java/org/apache/commons/collections4/functors/WhileClosure.java +++ b/src/main/java/org/apache/commons/collections4/functors/WhileClosure.java @@ -31,9 +31,10 @@ import org.apache.commons.collections4.Predicate; * for more details. *

* + * @param the type of the input to the operation. * @since 3.0 */ -public class WhileClosure implements Closure { +public class WhileClosure implements Closure { /** * Factory method that performs validation. @@ -51,9 +52,9 @@ public class WhileClosure implements Closure { Objects.requireNonNull(closure, "closure"), doLoop); } /** The test condition */ - private final Predicate iPredicate; + private final Predicate iPredicate; /** The closure to call */ - private final Closure iClosure; + private final Closure iClosure; /** The flag, true is a do loop, false is a while */ private final boolean iDoLoop; @@ -66,7 +67,7 @@ public class WhileClosure implements Closure { * @param closure the closure to execute, not null * @param doLoop true to act as a do-while loop, always executing the closure once */ - public WhileClosure(final Predicate predicate, final Closure closure, final boolean doLoop) { + public WhileClosure(final Predicate predicate, final Closure closure, final boolean doLoop) { iPredicate = predicate; iClosure = closure; iDoLoop = doLoop; @@ -78,7 +79,7 @@ public class WhileClosure implements Closure { * @param input the input object */ @Override - public void execute(final E input) { + public void execute(final T input) { if (iDoLoop) { iClosure.accept(input); } @@ -93,7 +94,7 @@ public class WhileClosure implements Closure { * @return the closure * @since 3.1 */ - public Closure getClosure() { + public Closure getClosure() { return iClosure; } @@ -103,7 +104,7 @@ public class WhileClosure implements Closure { * @return the predicate * @since 3.1 */ - public Predicate getPredicate() { + public Predicate getPredicate() { return iPredicate; }