From 53e58ad41babd88b249a16e1566e6e8eceb26000 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 12 Jul 2024 10:13:48 -0400 Subject: [PATCH] Javadoc Use genaric parameter names that match the JRE --- .../commons/collections4/Transformer.java | 4 +-- .../comparators/TransformingComparator.java | 4 +-- .../functors/ChainedTransformer.java | 1 + .../functors/CloneTransformer.java | 1 + .../functors/ClosureTransformer.java | 1 + .../functors/ConstantTransformer.java | 12 ++++--- .../functors/ExceptionTransformer.java | 6 ++-- .../functors/FactoryTransformer.java | 12 ++++--- .../collections4/functors/IfTransformer.java | 27 ++++++++-------- .../functors/InstantiateTransformer.java | 1 + .../functors/InvokerTransformer.java | 8 +++-- .../collections4/functors/MapTransformer.java | 12 ++++--- .../collections4/functors/NOPTransformer.java | 1 + .../functors/PredicateTransformer.java | 1 + .../functors/StringValueTransformer.java | 1 + .../functors/SwitchTransformer.java | 32 ++++++++++--------- .../iterators/TransformIterator.java | 2 ++ 17 files changed, 73 insertions(+), 53 deletions(-) diff --git a/src/main/java/org/apache/commons/collections4/Transformer.java b/src/main/java/org/apache/commons/collections4/Transformer.java index 52bb97c10b..fada2391ee 100644 --- a/src/main/java/org/apache/commons/collections4/Transformer.java +++ b/src/main/java/org/apache/commons/collections4/Transformer.java @@ -33,8 +33,8 @@ * cloning and returning the string value. *

* - * @param the input type to the transformer - * @param the output type from the transformer + * @param the type of the input to the function. + * @param the type of the result of the function. * * @since 1.0 * @deprecated Use {@link Function}. diff --git a/src/main/java/org/apache/commons/collections4/comparators/TransformingComparator.java b/src/main/java/org/apache/commons/collections4/comparators/TransformingComparator.java index 74adfdb7e9..b8dbe4f0ec 100644 --- a/src/main/java/org/apache/commons/collections4/comparators/TransformingComparator.java +++ b/src/main/java/org/apache/commons/collections4/comparators/TransformingComparator.java @@ -31,8 +31,8 @@ * This class is Serializable from Commons Collections 4.0. *

* - * @param the input type to the transformer - * @param the output type from the transformer + * @param the type of the input to the function + * @param the type of the result of the function * * @since 2.1 * diff --git a/src/main/java/org/apache/commons/collections4/functors/ChainedTransformer.java b/src/main/java/org/apache/commons/collections4/functors/ChainedTransformer.java index 444f5bf919..b66da6a702 100644 --- a/src/main/java/org/apache/commons/collections4/functors/ChainedTransformer.java +++ b/src/main/java/org/apache/commons/collections4/functors/ChainedTransformer.java @@ -29,6 +29,7 @@ * is passed to the second transformer and so on. *

* + * @param the type of the input and result to the function. * @since 3.0 */ public class ChainedTransformer implements Transformer, Serializable { diff --git a/src/main/java/org/apache/commons/collections4/functors/CloneTransformer.java b/src/main/java/org/apache/commons/collections4/functors/CloneTransformer.java index ca1d3f28df..80eb586738 100644 --- a/src/main/java/org/apache/commons/collections4/functors/CloneTransformer.java +++ b/src/main/java/org/apache/commons/collections4/functors/CloneTransformer.java @@ -30,6 +30,7 @@ * for more details. *

* + * @param the type of the input and result to the function. * @since 3.0 */ public class CloneTransformer implements Transformer { diff --git a/src/main/java/org/apache/commons/collections4/functors/ClosureTransformer.java b/src/main/java/org/apache/commons/collections4/functors/ClosureTransformer.java index f329e5e871..411ab1fd16 100644 --- a/src/main/java/org/apache/commons/collections4/functors/ClosureTransformer.java +++ b/src/main/java/org/apache/commons/collections4/functors/ClosureTransformer.java @@ -26,6 +26,7 @@ * Transformer implementation that calls a Closure using the input object * and then returns the input. * + * @param the type of the input and result to the function. * @since 3.0 */ public class ClosureTransformer implements Transformer, Serializable { diff --git a/src/main/java/org/apache/commons/collections4/functors/ConstantTransformer.java b/src/main/java/org/apache/commons/collections4/functors/ConstantTransformer.java index 602ac38304..8db424086e 100644 --- a/src/main/java/org/apache/commons/collections4/functors/ConstantTransformer.java +++ b/src/main/java/org/apache/commons/collections4/functors/ConstantTransformer.java @@ -28,9 +28,11 @@ * use the prototype factory. *

* + * @param the type of the input to the function. + * @param the type of the result of the function. * @since 3.0 */ -public class ConstantTransformer implements Transformer, Serializable { +public class ConstantTransformer implements Transformer, Serializable { /** Serial version UID */ private static final long serialVersionUID = 6374440726369055124L; @@ -66,7 +68,7 @@ public static Transformer nullTransformer() { } /** The closures to call in turn */ - private final O iConstant; + private final R iConstant; /** * Constructor that performs no validation. @@ -74,7 +76,7 @@ public static Transformer nullTransformer() { * * @param constantToReturn the constant to return each time */ - public ConstantTransformer(final O constantToReturn) { + public ConstantTransformer(final R constantToReturn) { iConstant = constantToReturn; } @@ -99,7 +101,7 @@ public boolean equals(final Object obj) { * @return the constant * @since 3.1 */ - public O getConstant() { + public R getConstant() { return iConstant; } @@ -122,7 +124,7 @@ public int hashCode() { * @return the stored constant */ @Override - public O transform(final I input) { + public R transform(final T input) { return iConstant; } } diff --git a/src/main/java/org/apache/commons/collections4/functors/ExceptionTransformer.java b/src/main/java/org/apache/commons/collections4/functors/ExceptionTransformer.java index b5978605ee..52429a0da0 100644 --- a/src/main/java/org/apache/commons/collections4/functors/ExceptionTransformer.java +++ b/src/main/java/org/apache/commons/collections4/functors/ExceptionTransformer.java @@ -24,9 +24,11 @@ /** * Transformer implementation that always throws an exception. * + * @param the type of the input to the function. + * @param the type of the result of the function. * @since 3.0 */ -public final class ExceptionTransformer implements Transformer, Serializable { +public final class ExceptionTransformer implements Transformer, Serializable { /** Serial version UID */ private static final long serialVersionUID = 7179106032121985545L; @@ -70,7 +72,7 @@ private Object readResolve() { * @throws FunctorException always */ @Override - public O transform(final I input) { + public R transform(final T input) { throw new FunctorException("ExceptionTransformer invoked"); } diff --git a/src/main/java/org/apache/commons/collections4/functors/FactoryTransformer.java b/src/main/java/org/apache/commons/collections4/functors/FactoryTransformer.java index 107bc96e1f..203c7e0906 100644 --- a/src/main/java/org/apache/commons/collections4/functors/FactoryTransformer.java +++ b/src/main/java/org/apache/commons/collections4/functors/FactoryTransformer.java @@ -25,9 +25,11 @@ /** * Transformer implementation that calls a Factory and returns the result. * + * @param the type of the input to the function. + * @param the type of the result of the function. * @since 3.0 */ -public class FactoryTransformer implements Transformer, Serializable { +public class FactoryTransformer implements Transformer, Serializable { /** Serial version UID */ private static final long serialVersionUID = -6817674502475353160L; @@ -46,7 +48,7 @@ public static Transformer factoryTransformer(final Factory iFactory; + private final Factory iFactory; /** * Constructor that performs no validation. @@ -54,7 +56,7 @@ public static Transformer factoryTransformer(final Factory factory) { + public FactoryTransformer(final Factory factory) { iFactory = factory; } @@ -64,7 +66,7 @@ public FactoryTransformer(final Factory factory) { * @return the factory * @since 3.1 */ - public Factory getFactory() { + public Factory getFactory() { return iFactory; } @@ -76,7 +78,7 @@ public Factory getFactory() { * @return the transformed result */ @Override - public O transform(final I input) { + public R transform(final T input) { return iFactory.get(); } diff --git a/src/main/java/org/apache/commons/collections4/functors/IfTransformer.java b/src/main/java/org/apache/commons/collections4/functors/IfTransformer.java index 787c43ae46..366753db3a 100644 --- a/src/main/java/org/apache/commons/collections4/functors/IfTransformer.java +++ b/src/main/java/org/apache/commons/collections4/functors/IfTransformer.java @@ -26,12 +26,11 @@ * Transformer implementation that will call one of two closures based on whether a predicate evaluates * as true or false. * - * @param The input type for the transformer - * @param The output type for the transformer - * + * @param the type of the input to the function. + * @param the type of the result of the function. * @since 4.1 */ -public class IfTransformer implements Transformer, Serializable { +public class IfTransformer implements Transformer, Serializable { /** Serial version UID */ private static final long serialVersionUID = 8069309411242014252L; @@ -73,13 +72,13 @@ public static Transformer ifTransformer( Objects.requireNonNull(trueTransformer, "trueTransformer"), NOPTransformer.nopTransformer()); } /** The test */ - private final Predicate iPredicate; + private final Predicate iPredicate; /** The transformer to use if true */ - private final Transformer iTrueTransformer; + private final Transformer iTrueTransformer; /** The transformer to use if false */ - private final Transformer iFalseTransformer; + private final Transformer iFalseTransformer; /** * Constructor that performs no validation. @@ -89,9 +88,9 @@ public static Transformer ifTransformer( * @param trueTransformer transformer used if true, not null * @param falseTransformer transformer used if false, not null */ - public IfTransformer(final Predicate predicate, - final Transformer trueTransformer, - final Transformer falseTransformer) { + public IfTransformer(final Predicate predicate, + final Transformer trueTransformer, + final Transformer falseTransformer) { iPredicate = predicate; iTrueTransformer = trueTransformer; @@ -103,7 +102,7 @@ public IfTransformer(final Predicate predicate, * * @return the transformer */ - public Transformer getFalseTransformer() { + public Transformer getFalseTransformer() { return iFalseTransformer; } @@ -112,7 +111,7 @@ public IfTransformer(final Predicate predicate, * * @return the predicate */ - public Predicate getPredicate() { + public Predicate getPredicate() { return iPredicate; } @@ -121,7 +120,7 @@ public Predicate getPredicate() { * * @return the transformer */ - public Transformer getTrueTransformer() { + public Transformer getTrueTransformer() { return iTrueTransformer; } @@ -132,7 +131,7 @@ public Predicate getPredicate() { * @return the transformed result */ @Override - public O transform(final I input) { + public R transform(final T input) { if (iPredicate.test(input)) { return iTrueTransformer.apply(input); } diff --git a/src/main/java/org/apache/commons/collections4/functors/InstantiateTransformer.java b/src/main/java/org/apache/commons/collections4/functors/InstantiateTransformer.java index a64c24b4e5..ed063feddb 100644 --- a/src/main/java/org/apache/commons/collections4/functors/InstantiateTransformer.java +++ b/src/main/java/org/apache/commons/collections4/functors/InstantiateTransformer.java @@ -31,6 +31,7 @@ * for more details. *

* + * @param the type of the input and result to the function. * @since 3.0 */ public class InstantiateTransformer implements Transformer, T> { diff --git a/src/main/java/org/apache/commons/collections4/functors/InvokerTransformer.java b/src/main/java/org/apache/commons/collections4/functors/InvokerTransformer.java index 5914bb30a7..353c6f8448 100644 --- a/src/main/java/org/apache/commons/collections4/functors/InvokerTransformer.java +++ b/src/main/java/org/apache/commons/collections4/functors/InvokerTransformer.java @@ -32,9 +32,11 @@ * for more details. *

* + * @param the type of the input to the function. + * @param the type of the result of the function. * @since 3.0 */ -public class InvokerTransformer implements Transformer { +public class InvokerTransformer implements Transformer { /** * Gets an instance of this transformer calling a specific method with no arguments. @@ -118,14 +120,14 @@ public InvokerTransformer(final String methodName, final Class[] paramTypes, */ @Override @SuppressWarnings("unchecked") - public O transform(final Object input) { + public R transform(final Object input) { if (input == null) { return null; } try { final Class cls = input.getClass(); final Method method = cls.getMethod(iMethodName, iParamTypes); - return (O) method.invoke(input, iArgs); + return (R) method.invoke(input, iArgs); } catch (final NoSuchMethodException ex) { throw new FunctorException("InvokerTransformer: The method '" + iMethodName + "' on '" + input.getClass() + "' does not exist"); diff --git a/src/main/java/org/apache/commons/collections4/functors/MapTransformer.java b/src/main/java/org/apache/commons/collections4/functors/MapTransformer.java index d84cdec1a0..47e545e2dc 100644 --- a/src/main/java/org/apache/commons/collections4/functors/MapTransformer.java +++ b/src/main/java/org/apache/commons/collections4/functors/MapTransformer.java @@ -25,9 +25,11 @@ * Transformer implementation that returns the value held in a specified map * using the input parameter as a key. * + * @param the type of the input to the function. + * @param the type of the result of the function. * @since 3.0 */ -public final class MapTransformer implements Transformer, Serializable { +public final class MapTransformer implements Transformer, Serializable { /** Serial version UID */ private static final long serialVersionUID = 862391807045468939L; @@ -50,7 +52,7 @@ public static Transformer mapTransformer(final Map iMap; + private final Map iMap; /** * Constructor that performs no validation. @@ -58,7 +60,7 @@ public static Transformer mapTransformer(final Map map) { + private MapTransformer(final Map map) { iMap = map; } @@ -68,7 +70,7 @@ private MapTransformer(final Map map) { * @return the map * @since 3.1 */ - public Map getMap() { + public Map getMap() { return iMap; } @@ -79,7 +81,7 @@ private MapTransformer(final Map map) { * @return the transformed result */ @Override - public O transform(final I input) { + public R transform(final T input) { return iMap.get(input); } diff --git a/src/main/java/org/apache/commons/collections4/functors/NOPTransformer.java b/src/main/java/org/apache/commons/collections4/functors/NOPTransformer.java index e025fc5531..29ab745225 100644 --- a/src/main/java/org/apache/commons/collections4/functors/NOPTransformer.java +++ b/src/main/java/org/apache/commons/collections4/functors/NOPTransformer.java @@ -23,6 +23,7 @@ /** * Transformer implementation that does nothing. * + * @param the type of the input and result to the function. * @since 3.0 */ public class NOPTransformer implements Transformer, Serializable { diff --git a/src/main/java/org/apache/commons/collections4/functors/PredicateTransformer.java b/src/main/java/org/apache/commons/collections4/functors/PredicateTransformer.java index 23319f976b..00fa8f0dc2 100644 --- a/src/main/java/org/apache/commons/collections4/functors/PredicateTransformer.java +++ b/src/main/java/org/apache/commons/collections4/functors/PredicateTransformer.java @@ -25,6 +25,7 @@ * Transformer implementation that calls a Predicate using the input object * and then returns the result. * + * @param the type of the input and result to the function. * @since 3.0 */ public class PredicateTransformer implements Transformer, Serializable { diff --git a/src/main/java/org/apache/commons/collections4/functors/StringValueTransformer.java b/src/main/java/org/apache/commons/collections4/functors/StringValueTransformer.java index e39caa6cff..31c3fa3aa5 100644 --- a/src/main/java/org/apache/commons/collections4/functors/StringValueTransformer.java +++ b/src/main/java/org/apache/commons/collections4/functors/StringValueTransformer.java @@ -24,6 +24,7 @@ * Transformer implementation that returns the result of calling * {@code String.valueOf} on the input object. * + * @param the type of the input and result to the function. * @since 3.0 */ public final class StringValueTransformer implements Transformer, Serializable { diff --git a/src/main/java/org/apache/commons/collections4/functors/SwitchTransformer.java b/src/main/java/org/apache/commons/collections4/functors/SwitchTransformer.java index eb3dbfa959..4262bf0ed5 100644 --- a/src/main/java/org/apache/commons/collections4/functors/SwitchTransformer.java +++ b/src/main/java/org/apache/commons/collections4/functors/SwitchTransformer.java @@ -27,9 +27,11 @@ * Transformer implementation calls the transformer whose predicate returns true, * like a switch statement. * + * @param the type of the input to the function. + * @param the type of the result of the function. * @since 3.0 */ -public class SwitchTransformer implements Transformer, Serializable { +public class SwitchTransformer implements Transformer, Serializable { /** Serial version UID */ private static final long serialVersionUID = -6404460890903469332L; @@ -108,13 +110,13 @@ public static Transformer switchTransformer(final Predicate(predicates, transformers, defaultTransformer); } /** The tests to consider */ - private final Predicate[] iPredicates; + private final Predicate[] iPredicates; /** The matching transformers to call */ - private final Transformer[] iTransformers; + private final Transformer[] iTransformers; /** The default transformer to call if no tests match */ - private final Transformer iDefault; + private final Transformer iDefault; /** * Hidden constructor for the use by the static factory methods. @@ -124,13 +126,13 @@ public static Transformer switchTransformer(final Predicate[] predicates, - final Transformer[] transformers, - final Transformer defaultTransformer) { + private SwitchTransformer(final boolean clone, final Predicate[] predicates, + final Transformer[] transformers, + final Transformer defaultTransformer) { iPredicates = clone ? FunctorUtils.copy(predicates) : predicates; iTransformers = clone ? FunctorUtils.copy(transformers) : transformers; iDefault = defaultTransformer == null ? - ConstantTransformer.nullTransformer() : defaultTransformer; + ConstantTransformer.nullTransformer() : defaultTransformer; } /** @@ -141,9 +143,9 @@ private SwitchTransformer(final boolean clone, final Predicate[] pred * @param transformers matching array of transformers, cloned, no nulls * @param defaultTransformer the transformer to use if no match, null means return null */ - public SwitchTransformer(final Predicate[] predicates, - final Transformer[] transformers, - final Transformer defaultTransformer) { + public SwitchTransformer(final Predicate[] predicates, + final Transformer[] transformers, + final Transformer defaultTransformer) { this(true, predicates, transformers, defaultTransformer); } @@ -153,7 +155,7 @@ public SwitchTransformer(final Predicate[] predicates, * @return the default transformer * @since 3.1 */ - public Transformer getDefaultTransformer() { + public Transformer getDefaultTransformer() { return iDefault; } @@ -163,7 +165,7 @@ public SwitchTransformer(final Predicate[] predicates, * @return a copy of the predicates * @since 3.1 */ - public Predicate[] getPredicates() { + public Predicate[] getPredicates() { return FunctorUtils.copy(iPredicates); } @@ -173,7 +175,7 @@ public Predicate[] getPredicates() { * @return a copy of the transformers * @since 3.1 */ - public Transformer[] getTransformers() { + public Transformer[] getTransformers() { return FunctorUtils.copy(iTransformers); } @@ -185,7 +187,7 @@ public Predicate[] getPredicates() { * @return the transformed result */ @Override - public O transform(final I input) { + public R transform(final T input) { for (int i = 0; i < iPredicates.length; i++) { if (iPredicates[i].test(input)) { return iTransformers[i].apply(input); diff --git a/src/main/java/org/apache/commons/collections4/iterators/TransformIterator.java b/src/main/java/org/apache/commons/collections4/iterators/TransformIterator.java index 03f1a02099..1b3d774aca 100644 --- a/src/main/java/org/apache/commons/collections4/iterators/TransformIterator.java +++ b/src/main/java/org/apache/commons/collections4/iterators/TransformIterator.java @@ -23,6 +23,8 @@ /** * Decorates an iterator such that each element returned is transformed. * + * @param the type of the input to the function. + * @param the type of the result of the function. * @since 1.0 */ public class TransformIterator implements Iterator {