parent
7e96acbf58
commit
53e58ad41b
|
@ -33,8 +33,8 @@ import java.util.function.Function;
|
||||||
* cloning and returning the string value.
|
* cloning and returning the string value.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param <T> the input type to the transformer
|
* @param <T> the type of the input to the function.
|
||||||
* @param <R> the output type from the transformer
|
* @param <R> the type of the result of the function.
|
||||||
*
|
*
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
* @deprecated Use {@link Function}.
|
* @deprecated Use {@link Function}.
|
||||||
|
|
|
@ -31,8 +31,8 @@ import org.apache.commons.collections4.Transformer;
|
||||||
* This class is Serializable from Commons Collections 4.0.
|
* This class is Serializable from Commons Collections 4.0.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param <I> the input type to the transformer
|
* @param <I> the type of the input to the function
|
||||||
* @param <O> the output type from the transformer
|
* @param <O> the type of the result of the function
|
||||||
*
|
*
|
||||||
* @since 2.1
|
* @since 2.1
|
||||||
*
|
*
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.apache.commons.collections4.Transformer;
|
||||||
* is passed to the second transformer and so on.
|
* is passed to the second transformer and so on.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input and result to the function.
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class ChainedTransformer<T> implements Transformer<T, T>, Serializable {
|
public class ChainedTransformer<T> implements Transformer<T, T>, Serializable {
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.apache.commons.collections4.Transformer;
|
||||||
* for more details.
|
* for more details.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input and result to the function.
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class CloneTransformer<T> implements Transformer<T, T> {
|
public class CloneTransformer<T> implements Transformer<T, T> {
|
||||||
|
|
|
@ -26,6 +26,7 @@ import org.apache.commons.collections4.Transformer;
|
||||||
* Transformer implementation that calls a Closure using the input object
|
* Transformer implementation that calls a Closure using the input object
|
||||||
* and then returns the input.
|
* and then returns the input.
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input and result to the function.
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class ClosureTransformer<T> implements Transformer<T, T>, Serializable {
|
public class ClosureTransformer<T> implements Transformer<T, T>, Serializable {
|
||||||
|
|
|
@ -28,9 +28,11 @@ import org.apache.commons.collections4.Transformer;
|
||||||
* use the prototype factory.
|
* use the prototype factory.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input to the function.
|
||||||
|
* @param <R> the type of the result of the function.
|
||||||
* @since 3.0
|
* @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 */
|
/** Serial version UID */
|
||||||
private static final long serialVersionUID = 6374440726369055124L;
|
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 */
|
/** The closures to call in turn */
|
||||||
private final O iConstant;
|
private final R iConstant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor that performs no validation.
|
* 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
|
* @param constantToReturn the constant to return each time
|
||||||
*/
|
*/
|
||||||
public ConstantTransformer(final O constantToReturn) {
|
public ConstantTransformer(final R constantToReturn) {
|
||||||
iConstant = constantToReturn;
|
iConstant = constantToReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +101,7 @@ public class ConstantTransformer<I, O> implements Transformer<I, O>, Serializabl
|
||||||
* @return the constant
|
* @return the constant
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
public O getConstant() {
|
public R getConstant() {
|
||||||
return iConstant;
|
return iConstant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +124,7 @@ public class ConstantTransformer<I, O> implements Transformer<I, O>, Serializabl
|
||||||
* @return the stored constant
|
* @return the stored constant
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public O transform(final I input) {
|
public R transform(final T input) {
|
||||||
return iConstant;
|
return iConstant;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,11 @@ import org.apache.commons.collections4.Transformer;
|
||||||
/**
|
/**
|
||||||
* Transformer implementation that always throws an exception.
|
* 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
|
* @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 */
|
/** Serial version UID */
|
||||||
private static final long serialVersionUID = 7179106032121985545L;
|
private static final long serialVersionUID = 7179106032121985545L;
|
||||||
|
@ -70,7 +72,7 @@ public final class ExceptionTransformer<I, O> implements Transformer<I, O>, Seri
|
||||||
* @throws FunctorException always
|
* @throws FunctorException always
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public O transform(final I input) {
|
public R transform(final T input) {
|
||||||
throw new FunctorException("ExceptionTransformer invoked");
|
throw new FunctorException("ExceptionTransformer invoked");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,11 @@ import org.apache.commons.collections4.Transformer;
|
||||||
/**
|
/**
|
||||||
* Transformer implementation that calls a Factory and returns the result.
|
* 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
|
* @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 */
|
/** Serial version UID */
|
||||||
private static final long serialVersionUID = -6817674502475353160L;
|
private static final long serialVersionUID = -6817674502475353160L;
|
||||||
|
@ -46,7 +48,7 @@ public class FactoryTransformer<I, O> implements Transformer<I, O>, Serializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The factory to wrap */
|
/** The factory to wrap */
|
||||||
private final Factory<? extends O> iFactory;
|
private final Factory<? extends R> iFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor that performs no validation.
|
* 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
|
* @param factory the factory to call, not null
|
||||||
*/
|
*/
|
||||||
public FactoryTransformer(final Factory<? extends O> factory) {
|
public FactoryTransformer(final Factory<? extends R> factory) {
|
||||||
iFactory = factory;
|
iFactory = factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +66,7 @@ public class FactoryTransformer<I, O> implements Transformer<I, O>, Serializable
|
||||||
* @return the factory
|
* @return the factory
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
public Factory<? extends O> getFactory() {
|
public Factory<? extends R> getFactory() {
|
||||||
return iFactory;
|
return iFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +78,7 @@ public class FactoryTransformer<I, O> implements Transformer<I, O>, Serializable
|
||||||
* @return the transformed result
|
* @return the transformed result
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public O transform(final I input) {
|
public R transform(final T input) {
|
||||||
return iFactory.get();
|
return iFactory.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
* Transformer implementation that will call one of two closures based on whether a predicate evaluates
|
||||||
* as true or false.
|
* as true or false.
|
||||||
*
|
*
|
||||||
* @param <I> The input type for the transformer
|
* @param <T> the type of the input to the function.
|
||||||
* @param <O> The output type for the transformer
|
* @param <R> the type of the result of the function.
|
||||||
*
|
|
||||||
* @since 4.1
|
* @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 */
|
/** Serial version UID */
|
||||||
private static final long serialVersionUID = 8069309411242014252L;
|
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());
|
Objects.requireNonNull(trueTransformer, "trueTransformer"), NOPTransformer.<T>nopTransformer());
|
||||||
}
|
}
|
||||||
/** The test */
|
/** The test */
|
||||||
private final Predicate<? super I> iPredicate;
|
private final Predicate<? super T> iPredicate;
|
||||||
|
|
||||||
/** The transformer to use if true */
|
/** 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 */
|
/** 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.
|
* 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 trueTransformer transformer used if true, not null
|
||||||
* @param falseTransformer transformer used if false, not null
|
* @param falseTransformer transformer used if false, not null
|
||||||
*/
|
*/
|
||||||
public IfTransformer(final Predicate<? super I> predicate,
|
public IfTransformer(final Predicate<? super T> predicate,
|
||||||
final Transformer<? super I, ? extends O> trueTransformer,
|
final Transformer<? super T, ? extends R> trueTransformer,
|
||||||
final Transformer<? super I, ? extends O> falseTransformer) {
|
final Transformer<? super T, ? extends R> falseTransformer) {
|
||||||
|
|
||||||
iPredicate = predicate;
|
iPredicate = predicate;
|
||||||
iTrueTransformer = trueTransformer;
|
iTrueTransformer = trueTransformer;
|
||||||
|
@ -103,7 +102,7 @@ public class IfTransformer<I, O> implements Transformer<I, O>, Serializable {
|
||||||
*
|
*
|
||||||
* @return the transformer
|
* @return the transformer
|
||||||
*/
|
*/
|
||||||
public Transformer<? super I, ? extends O> getFalseTransformer() {
|
public Transformer<? super T, ? extends R> getFalseTransformer() {
|
||||||
return iFalseTransformer;
|
return iFalseTransformer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +111,7 @@ public class IfTransformer<I, O> implements Transformer<I, O>, Serializable {
|
||||||
*
|
*
|
||||||
* @return the predicate
|
* @return the predicate
|
||||||
*/
|
*/
|
||||||
public Predicate<? super I> getPredicate() {
|
public Predicate<? super T> getPredicate() {
|
||||||
return iPredicate;
|
return iPredicate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +120,7 @@ public class IfTransformer<I, O> implements Transformer<I, O>, Serializable {
|
||||||
*
|
*
|
||||||
* @return the transformer
|
* @return the transformer
|
||||||
*/
|
*/
|
||||||
public Transformer<? super I, ? extends O> getTrueTransformer() {
|
public Transformer<? super T, ? extends R> getTrueTransformer() {
|
||||||
return iTrueTransformer;
|
return iTrueTransformer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +131,7 @@ public class IfTransformer<I, O> implements Transformer<I, O>, Serializable {
|
||||||
* @return the transformed result
|
* @return the transformed result
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public O transform(final I input) {
|
public R transform(final T input) {
|
||||||
if (iPredicate.test(input)) {
|
if (iPredicate.test(input)) {
|
||||||
return iTrueTransformer.apply(input);
|
return iTrueTransformer.apply(input);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.apache.commons.collections4.Transformer;
|
||||||
* for more details.
|
* for more details.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input and result to the function.
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class InstantiateTransformer<T> implements Transformer<Class<? extends T>, T> {
|
public class InstantiateTransformer<T> implements Transformer<Class<? extends T>, T> {
|
||||||
|
|
|
@ -32,9 +32,11 @@ import org.apache.commons.collections4.Transformer;
|
||||||
* for more details.
|
* for more details.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input to the function.
|
||||||
|
* @param <R> the type of the result of the function.
|
||||||
* @since 3.0
|
* @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.
|
* 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
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public O transform(final Object input) {
|
public R transform(final Object input) {
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final Class<?> cls = input.getClass();
|
final Class<?> cls = input.getClass();
|
||||||
final Method method = cls.getMethod(iMethodName, iParamTypes);
|
final Method method = cls.getMethod(iMethodName, iParamTypes);
|
||||||
return (O) method.invoke(input, iArgs);
|
return (R) method.invoke(input, iArgs);
|
||||||
} catch (final NoSuchMethodException ex) {
|
} catch (final NoSuchMethodException ex) {
|
||||||
throw new FunctorException("InvokerTransformer: The method '" + iMethodName + "' on '" +
|
throw new FunctorException("InvokerTransformer: The method '" + iMethodName + "' on '" +
|
||||||
input.getClass() + "' does not exist");
|
input.getClass() + "' does not exist");
|
||||||
|
|
|
@ -25,9 +25,11 @@ import org.apache.commons.collections4.Transformer;
|
||||||
* Transformer implementation that returns the value held in a specified map
|
* Transformer implementation that returns the value held in a specified map
|
||||||
* using the input parameter as a key.
|
* 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
|
* @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 */
|
/** Serial version UID */
|
||||||
private static final long serialVersionUID = 862391807045468939L;
|
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 */
|
/** 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.
|
* 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
|
* @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;
|
iMap = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +70,7 @@ public final class MapTransformer<I, O> implements Transformer<I, O>, Serializab
|
||||||
* @return the map
|
* @return the map
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
public Map<? super I, ? extends O> getMap() {
|
public Map<? super T, ? extends R> getMap() {
|
||||||
return iMap;
|
return iMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +81,7 @@ public final class MapTransformer<I, O> implements Transformer<I, O>, Serializab
|
||||||
* @return the transformed result
|
* @return the transformed result
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public O transform(final I input) {
|
public R transform(final T input) {
|
||||||
return iMap.get(input);
|
return iMap.get(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.commons.collections4.Transformer;
|
||||||
/**
|
/**
|
||||||
* Transformer implementation that does nothing.
|
* Transformer implementation that does nothing.
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input and result to the function.
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class NOPTransformer<T> implements Transformer<T, T>, Serializable {
|
public class NOPTransformer<T> implements Transformer<T, T>, Serializable {
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.commons.collections4.Transformer;
|
||||||
* Transformer implementation that calls a Predicate using the input object
|
* Transformer implementation that calls a Predicate using the input object
|
||||||
* and then returns the result.
|
* and then returns the result.
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input and result to the function.
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class PredicateTransformer<T> implements Transformer<T, Boolean>, Serializable {
|
public class PredicateTransformer<T> implements Transformer<T, Boolean>, Serializable {
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.commons.collections4.Transformer;
|
||||||
* Transformer implementation that returns the result of calling
|
* Transformer implementation that returns the result of calling
|
||||||
* {@code String.valueOf} on the input object.
|
* {@code String.valueOf} on the input object.
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input and result to the function.
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public final class StringValueTransformer<T> implements Transformer<T, String>, Serializable {
|
public final class StringValueTransformer<T> implements Transformer<T, String>, Serializable {
|
||||||
|
|
|
@ -27,9 +27,11 @@ import org.apache.commons.collections4.Transformer;
|
||||||
* Transformer implementation calls the transformer whose predicate returns true,
|
* Transformer implementation calls the transformer whose predicate returns true,
|
||||||
* like a switch statement.
|
* 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
|
* @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 */
|
/** Serial version UID */
|
||||||
private static final long serialVersionUID = -6404460890903469332L;
|
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);
|
return new SwitchTransformer<>(predicates, transformers, defaultTransformer);
|
||||||
}
|
}
|
||||||
/** The tests to consider */
|
/** The tests to consider */
|
||||||
private final Predicate<? super I>[] iPredicates;
|
private final Predicate<? super T>[] iPredicates;
|
||||||
|
|
||||||
/** The matching transformers to call */
|
/** 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 */
|
/** 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.
|
* 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 transformers matching array of transformers, no nulls
|
||||||
* @param defaultTransformer the transformer to use if no match, null means return null
|
* @param defaultTransformer the transformer to use if no match, null means return null
|
||||||
*/
|
*/
|
||||||
private SwitchTransformer(final boolean clone, final Predicate<? super I>[] predicates,
|
private SwitchTransformer(final boolean clone, final Predicate<? super T>[] predicates,
|
||||||
final Transformer<? super I, ? extends O>[] transformers,
|
final Transformer<? super T, ? extends R>[] transformers,
|
||||||
final Transformer<? super I, ? extends O> defaultTransformer) {
|
final Transformer<? super T, ? extends R> defaultTransformer) {
|
||||||
iPredicates = clone ? FunctorUtils.copy(predicates) : predicates;
|
iPredicates = clone ? FunctorUtils.copy(predicates) : predicates;
|
||||||
iTransformers = clone ? FunctorUtils.copy(transformers) : transformers;
|
iTransformers = clone ? FunctorUtils.copy(transformers) : transformers;
|
||||||
iDefault = defaultTransformer == null ?
|
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 transformers matching array of transformers, cloned, no nulls
|
||||||
* @param defaultTransformer the transformer to use if no match, null means return null
|
* @param defaultTransformer the transformer to use if no match, null means return null
|
||||||
*/
|
*/
|
||||||
public SwitchTransformer(final Predicate<? super I>[] predicates,
|
public SwitchTransformer(final Predicate<? super T>[] predicates,
|
||||||
final Transformer<? super I, ? extends O>[] transformers,
|
final Transformer<? super T, ? extends R>[] transformers,
|
||||||
final Transformer<? super I, ? extends O> defaultTransformer) {
|
final Transformer<? super T, ? extends R> defaultTransformer) {
|
||||||
this(true, predicates, transformers, defaultTransformer);
|
this(true, predicates, transformers, defaultTransformer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +155,7 @@ public class SwitchTransformer<I, O> implements Transformer<I, O>, Serializable
|
||||||
* @return the default transformer
|
* @return the default transformer
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
public Transformer<? super I, ? extends O> getDefaultTransformer() {
|
public Transformer<? super T, ? extends R> getDefaultTransformer() {
|
||||||
return iDefault;
|
return iDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +165,7 @@ public class SwitchTransformer<I, O> implements Transformer<I, O>, Serializable
|
||||||
* @return a copy of the predicates
|
* @return a copy of the predicates
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
public Predicate<? super I>[] getPredicates() {
|
public Predicate<? super T>[] getPredicates() {
|
||||||
return FunctorUtils.copy(iPredicates);
|
return FunctorUtils.copy(iPredicates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,7 +175,7 @@ public class SwitchTransformer<I, O> implements Transformer<I, O>, Serializable
|
||||||
* @return a copy of the transformers
|
* @return a copy of the transformers
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
public Transformer<? super I, ? extends O>[] getTransformers() {
|
public Transformer<? super T, ? extends R>[] getTransformers() {
|
||||||
return FunctorUtils.copy(iTransformers);
|
return FunctorUtils.copy(iTransformers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +187,7 @@ public class SwitchTransformer<I, O> implements Transformer<I, O>, Serializable
|
||||||
* @return the transformed result
|
* @return the transformed result
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public O transform(final I input) {
|
public R transform(final T input) {
|
||||||
for (int i = 0; i < iPredicates.length; i++) {
|
for (int i = 0; i < iPredicates.length; i++) {
|
||||||
if (iPredicates[i].test(input)) {
|
if (iPredicates[i].test(input)) {
|
||||||
return iTransformers[i].apply(input);
|
return iTransformers[i].apply(input);
|
||||||
|
|
|
@ -23,6 +23,8 @@ import org.apache.commons.collections4.Transformer;
|
||||||
/**
|
/**
|
||||||
* Decorates an iterator such that each element returned is transformed.
|
* 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
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public class TransformIterator<I, O> implements Iterator<O> {
|
public class TransformIterator<I, O> implements Iterator<O> {
|
||||||
|
|
Loading…
Reference in New Issue