Use genaric parameter names that match the JRE
This commit is contained in:
Gary Gregory 2024-07-12 10:13:48 -04:00
parent 7e96acbf58
commit 53e58ad41b
17 changed files with 73 additions and 53 deletions

View File

@ -33,8 +33,8 @@ import java.util.function.Function;
* cloning and returning the string value.
* </p>
*
* @param <T> the input type to the transformer
* @param <R> the output type from the transformer
* @param <T> the type of the input to the function.
* @param <R> the type of the result of the function.
*
* @since 1.0
* @deprecated Use {@link Function}.

View File

@ -31,8 +31,8 @@ import org.apache.commons.collections4.Transformer;
* This class is Serializable from Commons Collections 4.0.
* </p>
*
* @param <I> the input type to the transformer
* @param <O> the output type from the transformer
* @param <I> the type of the input to the function
* @param <O> the type of the result of the function
*
* @since 2.1
*

View File

@ -29,6 +29,7 @@ import org.apache.commons.collections4.Transformer;
* is passed to the second transformer and so on.
* </p>
*
* @param <T> the type of the input and result to the function.
* @since 3.0
*/
public class ChainedTransformer<T> implements Transformer<T, T>, Serializable {

View File

@ -30,6 +30,7 @@ import org.apache.commons.collections4.Transformer;
* for more details.
* </p>
*
* @param <T> the type of the input and result to the function.
* @since 3.0
*/
public class CloneTransformer<T> implements Transformer<T, T> {

View File

@ -26,6 +26,7 @@ import org.apache.commons.collections4.Transformer;
* Transformer implementation that calls a Closure using the input object
* and then returns the input.
*
* @param <T> the type of the input and result to the function.
* @since 3.0
*/
public class ClosureTransformer<T> implements Transformer<T, T>, Serializable {

View File

@ -28,9 +28,11 @@ import org.apache.commons.collections4.Transformer;
* use the prototype factory.
* </p>
*
* @param <T> the type of the input to the function.
* @param <R> the type of the result of the function.
* @since 3.0
*/
public class ConstantTransformer<I, O> implements Transformer<I, O>, Serializable {
public class ConstantTransformer<T, R> implements Transformer<T, R>, Serializable {
/** Serial version UID */
private static final long serialVersionUID = 6374440726369055124L;
@ -66,7 +68,7 @@ public class ConstantTransformer<I, O> implements Transformer<I, O>, Serializabl
}
/** The closures to call in turn */
private final O iConstant;
private final R iConstant;
/**
* Constructor that performs no validation.
@ -74,7 +76,7 @@ public class ConstantTransformer<I, O> implements Transformer<I, O>, Serializabl
*
* @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 class ConstantTransformer<I, O> implements Transformer<I, O>, Serializabl
* @return the constant
* @since 3.1
*/
public O getConstant() {
public R getConstant() {
return iConstant;
}
@ -122,7 +124,7 @@ public class ConstantTransformer<I, O> implements Transformer<I, O>, Serializabl
* @return the stored constant
*/
@Override
public O transform(final I input) {
public R transform(final T input) {
return iConstant;
}
}

View File

@ -24,9 +24,11 @@ import org.apache.commons.collections4.Transformer;
/**
* Transformer implementation that always throws an exception.
*
* @param <T> the type of the input to the function.
* @param <R> the type of the result of the function.
* @since 3.0
*/
public final class ExceptionTransformer<I, O> implements Transformer<I, O>, Serializable {
public final class ExceptionTransformer<T, R> implements Transformer<T, R>, Serializable {
/** Serial version UID */
private static final long serialVersionUID = 7179106032121985545L;
@ -70,7 +72,7 @@ public final class ExceptionTransformer<I, O> implements Transformer<I, O>, Seri
* @throws FunctorException always
*/
@Override
public O transform(final I input) {
public R transform(final T input) {
throw new FunctorException("ExceptionTransformer invoked");
}

View File

@ -25,9 +25,11 @@ import org.apache.commons.collections4.Transformer;
/**
* Transformer implementation that calls a Factory and returns the result.
*
* @param <T> the type of the input to the function.
* @param <R> the type of the result of the function.
* @since 3.0
*/
public class FactoryTransformer<I, O> implements Transformer<I, O>, Serializable {
public class FactoryTransformer<T, R> implements Transformer<T, R>, Serializable {
/** Serial version UID */
private static final long serialVersionUID = -6817674502475353160L;
@ -46,7 +48,7 @@ public class FactoryTransformer<I, O> implements Transformer<I, O>, Serializable
}
/** The factory to wrap */
private final Factory<? extends O> iFactory;
private final Factory<? extends R> iFactory;
/**
* Constructor that performs no validation.
@ -54,7 +56,7 @@ public class FactoryTransformer<I, O> implements Transformer<I, O>, Serializable
*
* @param factory the factory to call, not null
*/
public FactoryTransformer(final Factory<? extends O> factory) {
public FactoryTransformer(final Factory<? extends R> factory) {
iFactory = factory;
}
@ -64,7 +66,7 @@ public class FactoryTransformer<I, O> implements Transformer<I, O>, Serializable
* @return the factory
* @since 3.1
*/
public Factory<? extends O> getFactory() {
public Factory<? extends R> getFactory() {
return iFactory;
}
@ -76,7 +78,7 @@ public class FactoryTransformer<I, O> implements Transformer<I, O>, Serializable
* @return the transformed result
*/
@Override
public O transform(final I input) {
public R transform(final T input) {
return iFactory.get();
}

View File

@ -26,12 +26,11 @@ import org.apache.commons.collections4.Transformer;
* Transformer implementation that will call one of two closures based on whether a predicate evaluates
* as true or false.
*
* @param <I> The input type for the transformer
* @param <O> The output type for the transformer
*
* @param <T> the type of the input to the function.
* @param <R> the type of the result of the function.
* @since 4.1
*/
public class IfTransformer<I, O> implements Transformer<I, O>, Serializable {
public class IfTransformer<T, R> implements Transformer<T, R>, Serializable {
/** Serial version UID */
private static final long serialVersionUID = 8069309411242014252L;
@ -73,13 +72,13 @@ public class IfTransformer<I, O> implements Transformer<I, O>, Serializable {
Objects.requireNonNull(trueTransformer, "trueTransformer"), NOPTransformer.<T>nopTransformer());
}
/** The test */
private final Predicate<? super I> iPredicate;
private final Predicate<? super T> iPredicate;
/** The transformer to use if true */
private final Transformer<? super I, ? extends O> iTrueTransformer;
private final Transformer<? super T, ? extends R> iTrueTransformer;
/** The transformer to use if false */
private final Transformer<? super I, ? extends O> iFalseTransformer;
private final Transformer<? super T, ? extends R> iFalseTransformer;
/**
* Constructor that performs no validation.
@ -89,9 +88,9 @@ public class IfTransformer<I, O> implements Transformer<I, O>, Serializable {
* @param trueTransformer transformer used if true, not null
* @param falseTransformer transformer used if false, not null
*/
public IfTransformer(final Predicate<? super I> predicate,
final Transformer<? super I, ? extends O> trueTransformer,
final Transformer<? super I, ? extends O> falseTransformer) {
public IfTransformer(final Predicate<? super T> predicate,
final Transformer<? super T, ? extends R> trueTransformer,
final Transformer<? super T, ? extends R> falseTransformer) {
iPredicate = predicate;
iTrueTransformer = trueTransformer;
@ -103,7 +102,7 @@ public class IfTransformer<I, O> implements Transformer<I, O>, Serializable {
*
* @return the transformer
*/
public Transformer<? super I, ? extends O> getFalseTransformer() {
public Transformer<? super T, ? extends R> getFalseTransformer() {
return iFalseTransformer;
}
@ -112,7 +111,7 @@ public class IfTransformer<I, O> implements Transformer<I, O>, Serializable {
*
* @return the predicate
*/
public Predicate<? super I> getPredicate() {
public Predicate<? super T> getPredicate() {
return iPredicate;
}
@ -121,7 +120,7 @@ public class IfTransformer<I, O> implements Transformer<I, O>, Serializable {
*
* @return the transformer
*/
public Transformer<? super I, ? extends O> getTrueTransformer() {
public Transformer<? super T, ? extends R> getTrueTransformer() {
return iTrueTransformer;
}
@ -132,7 +131,7 @@ public class IfTransformer<I, O> implements Transformer<I, O>, Serializable {
* @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);
}

View File

@ -31,6 +31,7 @@ import org.apache.commons.collections4.Transformer;
* for more details.
* </p>
*
* @param <T> the type of the input and result to the function.
* @since 3.0
*/
public class InstantiateTransformer<T> implements Transformer<Class<? extends T>, T> {

View File

@ -32,9 +32,11 @@ import org.apache.commons.collections4.Transformer;
* for more details.
* </p>
*
* @param <T> the type of the input to the function.
* @param <R> the type of the result of the function.
* @since 3.0
*/
public class InvokerTransformer<I, O> implements Transformer<I, O> {
public class InvokerTransformer<T, R> implements Transformer<T, R> {
/**
* Gets an instance of this transformer calling a specific method with no arguments.
@ -118,14 +120,14 @@ public class InvokerTransformer<I, O> implements Transformer<I, O> {
*/
@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");

View File

@ -25,9 +25,11 @@ import org.apache.commons.collections4.Transformer;
* Transformer implementation that returns the value held in a specified map
* using the input parameter as a key.
*
* @param <T> the type of the input to the function.
* @param <R> the type of the result of the function.
* @since 3.0
*/
public final class MapTransformer<I, O> implements Transformer<I, O>, Serializable {
public final class MapTransformer<T, R> implements Transformer<T, R>, Serializable {
/** Serial version UID */
private static final long serialVersionUID = 862391807045468939L;
@ -50,7 +52,7 @@ public final class MapTransformer<I, O> implements Transformer<I, O>, Serializab
}
/** The map of data to lookup in */
private final Map<? super I, ? extends O> iMap;
private final Map<? super T, ? extends R> iMap;
/**
* Constructor that performs no validation.
@ -58,7 +60,7 @@ public final class MapTransformer<I, O> implements Transformer<I, O>, Serializab
*
* @param map the map to use for lookup, not cloned
*/
private MapTransformer(final Map<? super I, ? extends O> map) {
private MapTransformer(final Map<? super T, ? extends R> map) {
iMap = map;
}
@ -68,7 +70,7 @@ public final class MapTransformer<I, O> implements Transformer<I, O>, Serializab
* @return the map
* @since 3.1
*/
public Map<? super I, ? extends O> getMap() {
public Map<? super T, ? extends R> getMap() {
return iMap;
}
@ -79,7 +81,7 @@ public final class MapTransformer<I, O> implements Transformer<I, O>, Serializab
* @return the transformed result
*/
@Override
public O transform(final I input) {
public R transform(final T input) {
return iMap.get(input);
}

View File

@ -23,6 +23,7 @@ import org.apache.commons.collections4.Transformer;
/**
* Transformer implementation that does nothing.
*
* @param <T> the type of the input and result to the function.
* @since 3.0
*/
public class NOPTransformer<T> implements Transformer<T, T>, Serializable {

View File

@ -25,6 +25,7 @@ import org.apache.commons.collections4.Transformer;
* Transformer implementation that calls a Predicate using the input object
* and then returns the result.
*
* @param <T> the type of the input and result to the function.
* @since 3.0
*/
public class PredicateTransformer<T> implements Transformer<T, Boolean>, Serializable {

View File

@ -24,6 +24,7 @@ import org.apache.commons.collections4.Transformer;
* Transformer implementation that returns the result of calling
* {@code String.valueOf} on the input object.
*
* @param <T> the type of the input and result to the function.
* @since 3.0
*/
public final class StringValueTransformer<T> implements Transformer<T, String>, Serializable {

View File

@ -27,9 +27,11 @@ import org.apache.commons.collections4.Transformer;
* Transformer implementation calls the transformer whose predicate returns true,
* like a switch statement.
*
* @param <T> the type of the input to the function.
* @param <R> the type of the result of the function.
* @since 3.0
*/
public class SwitchTransformer<I, O> implements Transformer<I, O>, Serializable {
public class SwitchTransformer<T, R> implements Transformer<T, R>, Serializable {
/** Serial version UID */
private static final long serialVersionUID = -6404460890903469332L;
@ -108,13 +110,13 @@ public class SwitchTransformer<I, O> implements Transformer<I, O>, Serializable
return new SwitchTransformer<>(predicates, transformers, defaultTransformer);
}
/** The tests to consider */
private final Predicate<? super I>[] iPredicates;
private final Predicate<? super T>[] iPredicates;
/** The matching transformers to call */
private final Transformer<? super I, ? extends O>[] iTransformers;
private final Transformer<? super T, ? extends R>[] iTransformers;
/** The default transformer to call if no tests match */
private final Transformer<? super I, ? extends O> iDefault;
private final Transformer<? super T, ? extends R> iDefault;
/**
* Hidden constructor for the use by the static factory methods.
@ -124,13 +126,13 @@ public class SwitchTransformer<I, O> implements Transformer<I, O>, Serializable
* @param transformers matching array of transformers, no nulls
* @param defaultTransformer the transformer to use if no match, null means return null
*/
private SwitchTransformer(final boolean clone, final Predicate<? super I>[] predicates,
final Transformer<? super I, ? extends O>[] transformers,
final Transformer<? super I, ? extends O> defaultTransformer) {
private SwitchTransformer(final boolean clone, final Predicate<? super T>[] predicates,
final Transformer<? super T, ? extends R>[] transformers,
final Transformer<? super T, ? extends R> defaultTransformer) {
iPredicates = clone ? FunctorUtils.copy(predicates) : predicates;
iTransformers = clone ? FunctorUtils.copy(transformers) : transformers;
iDefault = defaultTransformer == null ?
ConstantTransformer.<I, O>nullTransformer() : defaultTransformer;
ConstantTransformer.<T, R>nullTransformer() : defaultTransformer;
}
/**
@ -141,9 +143,9 @@ public class SwitchTransformer<I, O> implements Transformer<I, O>, Serializable
* @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<? super I>[] predicates,
final Transformer<? super I, ? extends O>[] transformers,
final Transformer<? super I, ? extends O> defaultTransformer) {
public SwitchTransformer(final Predicate<? super T>[] predicates,
final Transformer<? super T, ? extends R>[] transformers,
final Transformer<? super T, ? extends R> defaultTransformer) {
this(true, predicates, transformers, defaultTransformer);
}
@ -153,7 +155,7 @@ public class SwitchTransformer<I, O> implements Transformer<I, O>, Serializable
* @return the default transformer
* @since 3.1
*/
public Transformer<? super I, ? extends O> getDefaultTransformer() {
public Transformer<? super T, ? extends R> getDefaultTransformer() {
return iDefault;
}
@ -163,7 +165,7 @@ public class SwitchTransformer<I, O> implements Transformer<I, O>, Serializable
* @return a copy of the predicates
* @since 3.1
*/
public Predicate<? super I>[] getPredicates() {
public Predicate<? super T>[] getPredicates() {
return FunctorUtils.copy(iPredicates);
}
@ -173,7 +175,7 @@ public class SwitchTransformer<I, O> implements Transformer<I, O>, Serializable
* @return a copy of the transformers
* @since 3.1
*/
public Transformer<? super I, ? extends O>[] getTransformers() {
public Transformer<? super T, ? extends R>[] getTransformers() {
return FunctorUtils.copy(iTransformers);
}
@ -185,7 +187,7 @@ public class SwitchTransformer<I, O> implements Transformer<I, O>, Serializable
* @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);

View File

@ -23,6 +23,8 @@ import org.apache.commons.collections4.Transformer;
/**
* Decorates an iterator such that each element returned is transformed.
*
* @param <I> the type of the input to the function.
* @param <O> the type of the result of the function.
* @since 1.0
*/
public class TransformIterator<I, O> implements Iterator<O> {