commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chtom...@apache.org
Subject [27/77] [abbrv] commons-collections git commit: finish generics (minus one class)
Date Tue, 11 Jul 2017 17:55:12 GMT
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/FunctorUtils.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/FunctorUtils.java b/src/java/org/apache/commons/collections/functors/FunctorUtils.java
index d52ba01..3585558 100644
--- a/src/java/org/apache/commons/collections/functors/FunctorUtils.java
+++ b/src/java/org/apache/commons/collections/functors/FunctorUtils.java
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,7 +24,7 @@ import org.apache.commons.collections.Transformer;
 
 /**
  * Internal utilities for functors.
- * 
+ *
  * @since Commons Collections 3.0
  * @version $Revision$ $Date$
  *
@@ -32,38 +32,38 @@ import org.apache.commons.collections.Transformer;
  * @author Matt Benson
  */
 class FunctorUtils {
-    
+
     /**
      * Restricted constructor.
      */
     private FunctorUtils() {
         super();
     }
-    
+
     /**
      * Clone the predicates to ensure that the internal reference can't be messed with.
      * Due to the {@link Predicate#evaluate(T)} method, Predicate<? super T> is
-     * able to be coerced to Predicate<T> without casting issues. 
-     * 
+     * able to be coerced to Predicate<T> without casting issues.
+     *
      * @param predicates  the predicates to copy
      * @return the cloned predicates
      */
     @SuppressWarnings("unchecked")
-    static <T> Predicate<? super T>[] copy(Predicate<? super T>[] predicates) {
+    static <T> Predicate<T>[] copy(Predicate<? super T>[] predicates) {
         if (predicates == null) {
             return null;
         }
-        return predicates.clone();
+        return (Predicate<T>[]) predicates.clone();
     }
-    
+
     /**
      * A very simple method that coerces Predicate<? super T> to Predicate<T>.
      * Due to the {@link Predicate#evaluate(T)} method, Predicate<? super T> is
-     * able to be coerced to Predicate<T> without casting issues. 
+     * able to be coerced to Predicate<T> without casting issues.
      * <p>This method exists
      * simply as centralised documentation and atomic unchecked warning
      * suppression.
-     * 
+     *
      * @param <T> the type of object the returned predicate should "accept"
      * @param predicate the predicate to coerce.
      * @return the coerced predicate.
@@ -72,10 +72,10 @@ class FunctorUtils {
     static <T> Predicate<T> coerce(Predicate<? super T> predicate){
         return (Predicate<T>) predicate;
     }
-    
+
     /**
      * Validate the predicates to ensure that all is well.
-     * 
+     *
      * @param predicates  the predicates to validate
      */
     static void validate(Predicate<?>[] predicates) {
@@ -88,22 +88,22 @@ class FunctorUtils {
             }
         }
     }
-    
+
     /**
      * Validate the predicates to ensure that all is well.
-     * 
+     *
      * @param predicates  the predicates to validate
      * @return predicate array
      */
     @SuppressWarnings("unchecked")
-    static <T> Predicate<? super T>[] validate(Collection<Predicate<? super T>> predicates) {
+    static <T> Predicate<T>[] validate(Collection<? extends Predicate<T>> predicates) {
         if (predicates == null) {
             throw new IllegalArgumentException("The predicate collection must not be null");
         }
         // convert to array like this to guarantee iterator() ordering
-        Predicate<? super T>[] preds = new Predicate[predicates.size()];
+        Predicate<T>[] preds = new Predicate[predicates.size()];
         int i = 0;
-        for (Predicate<? super T> predicate : predicates) {
+        for (Predicate<T> predicate : predicates) {
             preds[i] = predicate;
             if (preds[i] == null) {
                 throw new IllegalArgumentException("The predicate collection must not contain a null predicate, index " + i + " was null");
@@ -112,26 +112,27 @@ class FunctorUtils {
         }
         return preds;
     }
-    
+
     /**
      * Clone the closures to ensure that the internal reference can't be messed with.
-     * 
+     *
      * @param closures  the closures to copy
      * @return the cloned closures
      */
-    static Closure[] copy(Closure[] closures) {
+    @SuppressWarnings("unchecked")
+    static <E> Closure<E>[] copy(Closure<? super E>[] closures) {
         if (closures == null) {
             return null;
         }
-        return (Closure[]) closures.clone();
+        return (Closure<E>[]) closures.clone();
     }
-    
+
     /**
      * Validate the closures to ensure that all is well.
-     * 
+     *
      * @param closures  the closures to validate
      */
-    static void validate(Closure[] closures) {
+    static void validate(Closure<?>[] closures) {
         if (closures == null) {
             throw new IllegalArgumentException("The closure array must not be null");
         }
@@ -143,24 +144,40 @@ class FunctorUtils {
     }
 
     /**
+     * A very simple method that coerces Closure<? super T> to Closure<T>.
+     * <p>This method exists
+     * simply as centralised documentation and atomic unchecked warning
+     * suppression.
+     *
+     * @param <T> the type of object the returned closure should "accept"
+     * @param closure the closure to coerce.
+     * @return the coerced closure.
+     */
+    @SuppressWarnings("unchecked")
+    static <T> Closure<T> coerce(Closure<? super T> closure){
+        return (Closure<T>) closure;
+    }
+
+    /**
      * Copy method
-     * 
+     *
      * @param transformers  the transformers to copy
      * @return a clone of the transformers
      */
-    static Transformer[] copy(Transformer[] transformers) {
+    @SuppressWarnings("unchecked")
+    static <I, O> Transformer<I, O>[] copy(Transformer<? super I, ? extends O>[] transformers) {
         if (transformers == null) {
             return null;
         }
-        return (Transformer[]) transformers.clone();
+        return (Transformer<I, O>[]) transformers.clone();
     }
-    
+
     /**
      * Validate method
-     * 
+     *
      * @param transformers  the transformers to validate
      */
-    static void validate(Transformer[] transformers) {
+    static void validate(Transformer<?, ?>[] transformers) {
         if (transformers == null) {
             throw new IllegalArgumentException("The transformer array must not be null");
         }
@@ -172,4 +189,19 @@ class FunctorUtils {
         }
     }
 
+    /**
+     * A very simple method that coerces Transformer<? super I, ? extends O> to Transformer<I, O>.
+     * <p>This method exists
+     * simply as centralised documentation and atomic unchecked warning
+     * suppression.
+     *
+     * @param <T> the type of object the returned transformer should "accept"
+     * @param transformer the transformer to coerce.
+     * @return the coerced transformer.
+     */
+    @SuppressWarnings("unchecked")
+    static <I, O> Transformer<I, O> coerce(Transformer<? super I, ? extends O> transformer) {
+        return (Transformer<I, O>) transformer;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/IdentityPredicate.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/IdentityPredicate.java b/src/java/org/apache/commons/collections/functors/IdentityPredicate.java
index 5175a15..5768259 100644
--- a/src/java/org/apache/commons/collections/functors/IdentityPredicate.java
+++ b/src/java/org/apache/commons/collections/functors/IdentityPredicate.java
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,42 +23,41 @@ import org.apache.commons.collections.Predicate;
 /**
  * Predicate implementation that returns true if the input is the same object
  * as the one stored in this predicate.
- * 
+ *
  * @since Commons Collections 3.0
  * @version $Revision$ $Date$
  *
  * @author Stephen Colebourne
  */
-public final class IdentityPredicate implements Predicate, Serializable {
+public final class IdentityPredicate<T> implements Predicate<T>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = -89901658494523293L;
 
-    
     /** The value to compare to */
-    private final Object iValue;
-    
+    private final T iValue;
+
     /**
      * Factory to create the identity predicate.
-     * 
+     *
      * @param object  the object to compare to
      * @return the predicate
      * @throws IllegalArgumentException if the predicate is null
      */
-    public static Predicate getInstance(Object object) {
+    public static <T> Predicate<T> getInstance(T object) {
         if (object == null) {
-            return NullPredicate.INSTANCE;
+            return NullPredicate.<T>nullPredicate();
         }
-        return new IdentityPredicate(object);
+        return new IdentityPredicate<T>(object);
     }
 
     /**
      * Constructor that performs no validation.
      * Use <code>getInstance</code> if you want that.
-     * 
+     *
      * @param object  the object to compare to
      */
-    public IdentityPredicate(Object object) {
+    public IdentityPredicate(T object) {
         super();
         iValue = object;
     }
@@ -66,21 +65,21 @@ public final class IdentityPredicate implements Predicate, Serializable {
     /**
      * Evaluates the predicate returning true if the input object is identical to
      * the stored object.
-     * 
+     *
      * @param object  the input object
      * @return true if input is the same object as the stored value
      */
-    public boolean evaluate(Object object) {
+    public boolean evaluate(T object) {
         return (iValue == object);
     }
 
     /**
      * Gets the value.
-     * 
+     *
      * @return the value
      * @since Commons Collections 3.1
      */
-    public Object getValue() {
+    public T getValue() {
         return iValue;
     }
 

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/IfClosure.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/IfClosure.java b/src/java/org/apache/commons/collections/functors/IfClosure.java
index 0f49a39..151874a 100644
--- a/src/java/org/apache/commons/collections/functors/IfClosure.java
+++ b/src/java/org/apache/commons/collections/functors/IfClosure.java
@@ -31,17 +31,17 @@ import org.apache.commons.collections.Predicate;
  * @author Stephen Colebourne
  * @author Matt Benson
  */
-public class IfClosure implements Closure, Serializable {
+public class IfClosure<E> implements Closure<E>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 3518477308466486130L;
 
     /** The test */
-    private final Predicate iPredicate;
+    private final Predicate<? super E> iPredicate;
     /** The closure to use if true */
-    private final Closure iTrueClosure;
+    private final Closure<? super E> iTrueClosure;
     /** The closure to use if false */
-    private final Closure iFalseClosure;
+    private final Closure<? super E> iFalseClosure;
 
     /**
      * Factory method that performs validation.
@@ -55,8 +55,8 @@ public class IfClosure implements Closure, Serializable {
      * @throws IllegalArgumentException if either argument is null
      * @since Commons Collections 3.2
      */
-    public static Closure getInstance(Predicate predicate, Closure trueClosure) {
-        return getInstance(predicate, trueClosure, NOPClosure.INSTANCE);
+    public static <E> Closure<E> getInstance(Predicate<? super E> predicate, Closure<? super E> trueClosure) {
+        return IfClosure.<E>getInstance(predicate, trueClosure, NOPClosure.<E>getInstance());
     }
 
     /**
@@ -68,14 +68,14 @@ public class IfClosure implements Closure, Serializable {
      * @return the <code>if</code> closure
      * @throws IllegalArgumentException if any argument is null
      */
-    public static Closure getInstance(Predicate predicate, Closure trueClosure, Closure falseClosure) {
+    public static <E> Closure<E> getInstance(Predicate<? super E> predicate, Closure<? super E> trueClosure, Closure<? super E> falseClosure) {
         if (predicate == null) {
             throw new IllegalArgumentException("Predicate must not be null");
         }
         if (trueClosure == null || falseClosure == null) {
             throw new IllegalArgumentException("Closures must not be null");
         }
-        return new IfClosure(predicate, trueClosure, falseClosure);
+        return new IfClosure<E>(predicate, trueClosure, falseClosure);
     }
 
     /**
@@ -89,7 +89,7 @@ public class IfClosure implements Closure, Serializable {
      * @param trueClosure  closure used if true, not null
      * @since Commons Collections 3.2
      */
-    public IfClosure(Predicate predicate, Closure trueClosure) {
+    public IfClosure(Predicate<? super E> predicate, Closure<? super E> trueClosure) {
         this(predicate, trueClosure, NOPClosure.INSTANCE);
     }
 
@@ -101,7 +101,7 @@ public class IfClosure implements Closure, Serializable {
      * @param trueClosure  closure used if true, not null
      * @param falseClosure  closure used if false, not null
      */
-    public IfClosure(Predicate predicate, Closure trueClosure, Closure falseClosure) {
+    public IfClosure(Predicate<? super E> predicate, Closure<? super E> trueClosure, Closure<? super E> falseClosure) {
         super();
         iPredicate = predicate;
         iTrueClosure = trueClosure;
@@ -113,8 +113,8 @@ public class IfClosure implements Closure, Serializable {
      * 
      * @param input  the input object
      */
-    public void execute(Object input) {
-        if (iPredicate.evaluate(input) == true) {
+    public void execute(E input) {
+        if (iPredicate.evaluate(input)) {
             iTrueClosure.execute(input);
         } else {
             iFalseClosure.execute(input);
@@ -127,7 +127,7 @@ public class IfClosure implements Closure, Serializable {
      * @return the predicate
      * @since Commons Collections 3.1
      */
-    public Predicate getPredicate() {
+    public Predicate<? super E> getPredicate() {
         return iPredicate;
     }
 
@@ -137,7 +137,7 @@ public class IfClosure implements Closure, Serializable {
      * @return the closure
      * @since Commons Collections 3.1
      */
-    public Closure getTrueClosure() {
+    public Closure<? super E> getTrueClosure() {
         return iTrueClosure;
     }
 
@@ -147,7 +147,7 @@ public class IfClosure implements Closure, Serializable {
      * @return the closure
      * @since Commons Collections 3.1
      */
-    public Closure getFalseClosure() {
+    public Closure<? super E> getFalseClosure() {
         return iFalseClosure;
     }
 

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/InstanceofPredicate.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/InstanceofPredicate.java b/src/java/org/apache/commons/collections/functors/InstanceofPredicate.java
index d97971e..58fbe86 100644
--- a/src/java/org/apache/commons/collections/functors/InstanceofPredicate.java
+++ b/src/java/org/apache/commons/collections/functors/InstanceofPredicate.java
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,28 +23,28 @@ import org.apache.commons.collections.Predicate;
 /**
  * Predicate implementation that returns true if the input is an instanceof
  * the type stored in this predicate.
- * 
+ *
  * @since Commons Collections 3.0
  * @version $Revision$ $Date$
  *
  * @author Stephen Colebourne
  */
-public final class InstanceofPredicate implements Predicate, Serializable {
+public final class InstanceofPredicate implements Predicate<Object>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = -6682656911025165584L;
 
     /** The type to compare to */
-    private final Class iType;
-    
+    private final Class<?> iType;
+
     /**
      * Factory to create the identity predicate.
-     * 
+     *
      * @param type  the type to check for, may not be null
      * @return the predicate
      * @throws IllegalArgumentException if the class is null
      */
-    public static Predicate getInstance(Class type) {
+    public static Predicate<Object> getInstance(Class<?> type) {
         if (type == null) {
             throw new IllegalArgumentException("The type to check instanceof must not be null");
         }
@@ -54,17 +54,17 @@ public final class InstanceofPredicate implements Predicate, Serializable {
     /**
      * Constructor that performs no validation.
      * Use <code>getInstance</code> if you want that.
-     * 
+     *
      * @param type  the type to check for
      */
-    public InstanceofPredicate(Class type) {
+    public InstanceofPredicate(Class<?> type) {
         super();
         iType = type;
     }
 
     /**
      * Evaluates the predicate returning true if the input object is of the correct type.
-     * 
+     *
      * @param object  the input object
      * @return true if input is of stored type
      */
@@ -74,11 +74,11 @@ public final class InstanceofPredicate implements Predicate, Serializable {
 
     /**
      * Gets the type to compare to.
-     * 
+     *
      * @return the type
      * @since Commons Collections 3.1
      */
-    public Class getType() {
+    public Class<?> getType() {
         return iType;
     }
 

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/InstantiateFactory.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/InstantiateFactory.java b/src/java/org/apache/commons/collections/functors/InstantiateFactory.java
index f6e11df..a09c580 100644
--- a/src/java/org/apache/commons/collections/functors/InstantiateFactory.java
+++ b/src/java/org/apache/commons/collections/functors/InstantiateFactory.java
@@ -39,7 +39,7 @@ public class InstantiateFactory<T> implements Factory<T>, Serializable {
     /** The class to create */
     private final Class<T> iClassToInstantiate;
     /** The constructor parameter types */
-    private final Class[] iParamTypes;
+    private final Class<?>[] iParamTypes;
     /** The constructor arguments */
     private final Object[] iArgs;
     /** The constructor */
@@ -53,7 +53,7 @@ public class InstantiateFactory<T> implements Factory<T>, Serializable {
      * @param args  the constructor arguments
      * @return a new instantiate factory
      */
-    public static <T> Factory<T> getInstance(Class<T> classToInstantiate, Class[] paramTypes, Object[] args) {
+    public static <T> Factory<T> getInstance(Class<T> classToInstantiate, Class<?>[] paramTypes, Object[] args) {
         if (classToInstantiate == null) {
             throw new IllegalArgumentException("Class to instantiate must not be null");
         }
@@ -93,7 +93,7 @@ public class InstantiateFactory<T> implements Factory<T>, Serializable {
      * @param paramTypes  the constructor parameter types, not cloned
      * @param args  the constructor arguments, not cloned
      */
-    public InstantiateFactory(Class<T> classToInstantiate, Class[] paramTypes, Object[] args) {
+    public InstantiateFactory(Class<T> classToInstantiate, Class<?>[] paramTypes, Object[] args) {
         super();
         iClassToInstantiate = classToInstantiate;
         iParamTypes = paramTypes;
@@ -126,7 +126,6 @@ public class InstantiateFactory<T> implements Factory<T>, Serializable {
 
         try {
             return iConstructor.newInstance(iArgs);
-
         } catch (InstantiationException ex) {
             throw new FunctorException("InstantiateFactory: InstantiationException", ex);
         } catch (IllegalAccessException ex) {

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/InstantiateTransformer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/InstantiateTransformer.java b/src/java/org/apache/commons/collections/functors/InstantiateTransformer.java
index 61af4a8..ab1d098 100644
--- a/src/java/org/apache/commons/collections/functors/InstantiateTransformer.java
+++ b/src/java/org/apache/commons/collections/functors/InstantiateTransformer.java
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,33 +25,42 @@ import org.apache.commons.collections.Transformer;
 
 /**
  * Transformer implementation that creates a new object instance by reflection.
- * 
+ *
  * @since Commons Collections 3.0
  * @version $Revision$ $Date$
  *
  * @author Stephen Colebourne
  */
-public class InstantiateTransformer implements Transformer, Serializable {
+public class InstantiateTransformer<T> implements Transformer<Class<? extends T>, T>, Serializable {
 
     /** The serial version */
     private static final long serialVersionUID = 3786388740793356347L;
-    
+
     /** Singleton instance that uses the no arg constructor */
-    public static final Transformer NO_ARG_INSTANCE = new InstantiateTransformer();
+    public static final Transformer<Class<?>, ?> NO_ARG_INSTANCE = new InstantiateTransformer<Object>();
 
     /** The constructor parameter types */
-    private final Class[] iParamTypes;
+    private final Class<?>[] iParamTypes;
     /** The constructor arguments */
     private final Object[] iArgs;
 
     /**
+     * Get a typed no-arg instance.
+     * @param <T>
+     * @return Transformer<Class<? extends T>, T>
+     */
+    public static <T> Transformer<Class<? extends T>, T> getInstance() {
+        return new InstantiateTransformer<T>();
+    }
+
+    /**
      * Transformer method that performs validation.
-     * 
+     *
      * @param paramTypes  the constructor parameter types
      * @param args  the constructor arguments
      * @return an instantiate transformer
      */
-    public static Transformer getInstance(Class[] paramTypes, Object[] args) {
+    public static <T> Transformer<Class<? extends T>, T> getInstance(Class<?>[] paramTypes, Object[] args) {
         if (((paramTypes == null) && (args != null))
             || ((paramTypes != null) && (args == null))
             || ((paramTypes != null) && (args != null) && (paramTypes.length != args.length))) {
@@ -59,12 +68,11 @@ public class InstantiateTransformer implements Transformer, Serializable {
         }
 
         if (paramTypes == null || paramTypes.length == 0) {
-            return NO_ARG_INSTANCE;
-        } else {
-            paramTypes = (Class[]) paramTypes.clone();
-            args = (Object[]) args.clone();
+            return new InstantiateTransformer<T>();
         }
-        return new InstantiateTransformer(paramTypes, args);
+        paramTypes = (Class[]) paramTypes.clone();
+        args = (Object[]) args.clone();
+        return new InstantiateTransformer<T>(paramTypes, args);
     }
 
     /**
@@ -79,11 +87,11 @@ public class InstantiateTransformer implements Transformer, Serializable {
     /**
      * Constructor that performs no validation.
      * Use <code>getInstance</code> if you want that.
-     * 
+     *
      * @param paramTypes  the constructor parameter types, not cloned
      * @param args  the constructor arguments, not cloned
      */
-    public InstantiateTransformer(Class[] paramTypes, Object[] args) {
+    public InstantiateTransformer(Class<?>[] paramTypes, Object[] args) {
         super();
         iParamTypes = paramTypes;
         iArgs = args;
@@ -91,20 +99,19 @@ public class InstantiateTransformer implements Transformer, Serializable {
 
     /**
      * Transforms the input Class object to a result by instantiation.
-     * 
+     *
      * @param input  the input object to transform
      * @return the transformed result
      */
-    public Object transform(Object input) {
+    public T transform(Class<? extends T> input) {
         try {
             if (input instanceof Class == false) {
                 throw new FunctorException(
                     "InstantiateTransformer: Input object was not an instanceof Class, it was a "
                         + (input == null ? "null object" : input.getClass().getName()));
             }
-            Constructor con = ((Class) input).getConstructor(iParamTypes);
+            Constructor<? extends T> con = input.getConstructor(iParamTypes);
             return con.newInstance(iArgs);
-
         } catch (NoSuchMethodException ex) {
             throw new FunctorException("InstantiateTransformer: The constructor must exist and be public ");
         } catch (InstantiationException ex) {

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/InvokerTransformer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/InvokerTransformer.java b/src/java/org/apache/commons/collections/functors/InvokerTransformer.java
index fdb4502..0ab3dbb 100644
--- a/src/java/org/apache/commons/collections/functors/InvokerTransformer.java
+++ b/src/java/org/apache/commons/collections/functors/InvokerTransformer.java
@@ -31,7 +31,7 @@ import org.apache.commons.collections.Transformer;
  *
  * @author Stephen Colebourne
  */
-public class InvokerTransformer implements Transformer, Serializable {
+public class InvokerTransformer<I, O> implements Transformer<I, O>, Serializable {
 
     /** The serial version */
     private static final long serialVersionUID = -8653385846894047688L;
@@ -39,7 +39,7 @@ public class InvokerTransformer implements Transformer, Serializable {
     /** The method name to call */
     private final String iMethodName;
     /** The array of reflection parameter types */
-    private final Class[] iParamTypes;
+    private final Class<?>[] iParamTypes;
     /** The array of reflection arguments */
     private final Object[] iArgs;
 
@@ -50,11 +50,11 @@ public class InvokerTransformer implements Transformer, Serializable {
      * @return an invoker transformer
      * @since Commons Collections 3.1
      */
-    public static Transformer getInstance(String methodName) {
+    public static <I, O> Transformer<I, O> getInstance(String methodName) {
         if (methodName == null) {
             throw new IllegalArgumentException("The method to invoke must not be null");
         }
-        return new InvokerTransformer(methodName);
+        return new InvokerTransformer<I, O>(methodName);
     }
 
     /**
@@ -65,7 +65,7 @@ public class InvokerTransformer implements Transformer, Serializable {
      * @param args  the arguments to pass to the method
      * @return an invoker transformer
      */
-    public static Transformer getInstance(String methodName, Class[] paramTypes, Object[] args) {
+    public static <I, O> Transformer<I, O> getInstance(String methodName, Class<?>[] paramTypes, Object[] args) {
         if (methodName == null) {
             throw new IllegalArgumentException("The method to invoke must not be null");
         }
@@ -75,11 +75,11 @@ public class InvokerTransformer implements Transformer, Serializable {
             throw new IllegalArgumentException("The parameter types must match the arguments");
         }
         if (paramTypes == null || paramTypes.length == 0) {
-            return new InvokerTransformer(methodName);
+            return new InvokerTransformer<I, O>(methodName);
         } else {
             paramTypes = (Class[]) paramTypes.clone();
             args = (Object[]) args.clone();
-            return new InvokerTransformer(methodName, paramTypes, args);
+            return new InvokerTransformer<I, O>(methodName, paramTypes, args);
         }
     }
 
@@ -103,7 +103,7 @@ public class InvokerTransformer implements Transformer, Serializable {
      * @param paramTypes  the constructor parameter types, not cloned
      * @param args  the constructor arguments, not cloned
      */
-    public InvokerTransformer(String methodName, Class[] paramTypes, Object[] args) {
+    public InvokerTransformer(String methodName, Class<?>[] paramTypes, Object[] args) {
         super();
         iMethodName = methodName;
         iParamTypes = paramTypes;
@@ -116,15 +116,15 @@ public class InvokerTransformer implements Transformer, Serializable {
      * @param input  the input object to transform
      * @return the transformed result, null if null input
      */
-    public Object transform(Object input) {
+    @SuppressWarnings("unchecked")
+    public O transform(Object input) {
         if (input == null) {
             return null;
         }
         try {
-            Class cls = input.getClass();
+            Class<?> cls = input.getClass();
             Method method = cls.getMethod(iMethodName, iParamTypes);
-            return method.invoke(input, iArgs);
-                
+            return (O) method.invoke(input, iArgs);
         } catch (NoSuchMethodException ex) {
             throw new FunctorException("InvokerTransformer: The method '" + iMethodName + "' on '" + input.getClass() + "' does not exist");
         } catch (IllegalAccessException ex) {

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/MapTransformer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/MapTransformer.java b/src/java/org/apache/commons/collections/functors/MapTransformer.java
index 573762b..2bdaa98 100644
--- a/src/java/org/apache/commons/collections/functors/MapTransformer.java
+++ b/src/java/org/apache/commons/collections/functors/MapTransformer.java
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,63 +24,63 @@ import org.apache.commons.collections.Transformer;
 /**
  * Transformer implementation that returns the value held in a specified map
  * using the input parameter as a key.
- * 
+ *
  * @since Commons Collections 3.0
  * @version $Revision$ $Date$
  *
  * @author Stephen Colebourne
  */
-public final class MapTransformer implements Transformer, Serializable {
+public final class MapTransformer<I, O> implements Transformer<I, O>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 862391807045468939L;
-    
+
     /** The map of data to lookup in */
-    private final Map iMap;
+    private final Map<? super I, ? extends O> iMap;
 
     /**
      * Factory to create the transformer.
      * <p>
      * If the map is null, a transformer that always returns null is returned.
-     * 
+     *
      * @param map the map, not cloned
      * @return the transformer
      */
-    public static Transformer getInstance(Map map) {
+    public static <I, O> Transformer<I, O> getInstance(Map<? super I, ? extends O> map) {
         if (map == null) {
-            return ConstantTransformer.NULL_INSTANCE;
+            return ConstantTransformer.<I, O>getNullInstance();
         }
-        return new MapTransformer(map);
+        return new MapTransformer<I, O>(map);
     }
 
     /**
      * Constructor that performs no validation.
      * Use <code>getInstance</code> if you want that.
-     * 
+     *
      * @param map  the map to use for lookup, not cloned
      */
-    private MapTransformer(Map map) {
+    private MapTransformer(Map<? super I, ? extends O> map) {
         super();
         iMap = map;
     }
 
     /**
      * Transforms the input to result by looking it up in a <code>Map</code>.
-     * 
+     *
      * @param input  the input object to transform
      * @return the transformed result
      */
-    public Object transform(Object input) {
+    public O transform(I input) {
         return iMap.get(input);
     }
 
     /**
      * Gets the map to lookup in.
-     * 
+     *
      * @return the map
      * @since Commons Collections 3.1
      */
-    public Map getMap() {
+    public Map<? super I, ? extends O> getMap() {
         return iMap;
     }
 

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/NOPClosure.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/NOPClosure.java b/src/java/org/apache/commons/collections/functors/NOPClosure.java
index 3bfee9e..3fa08c2 100644
--- a/src/java/org/apache/commons/collections/functors/NOPClosure.java
+++ b/src/java/org/apache/commons/collections/functors/NOPClosure.java
@@ -28,13 +28,13 @@ import org.apache.commons.collections.Closure;
  *
  * @author Stephen Colebourne
  */
-public class NOPClosure implements Closure, Serializable {
+public class NOPClosure<E> implements Closure<E>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 3518477308466486130L;
 
     /** Singleton predicate instance */
-    public static final Closure INSTANCE = new NOPClosure();
+    public static final Closure<Object> INSTANCE = new NOPClosure<Object>();
 
     /**
      * Factory returning the singleton instance.
@@ -42,8 +42,9 @@ public class NOPClosure implements Closure, Serializable {
      * @return the singleton instance
      * @since Commons Collections 3.1
      */
-    public static Closure getInstance() {
-        return INSTANCE;
+    @SuppressWarnings("unchecked")
+    public static <E> Closure<E> getInstance() {
+        return (Closure<E>) INSTANCE;
     }
 
     /**
@@ -58,8 +59,23 @@ public class NOPClosure implements Closure, Serializable {
      * 
      * @param input  the input object
      */
-    public void execute(Object input) {
+    public void execute(E input) {
         // do nothing
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals(Object arg0) {
+        return arg0.hashCode() == this.hashCode();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode() {
+        return System.identityHashCode(INSTANCE);
+    }
 }

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/NOPTransformer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/NOPTransformer.java b/src/java/org/apache/commons/collections/functors/NOPTransformer.java
index 6c018c8..a21e44a 100644
--- a/src/java/org/apache/commons/collections/functors/NOPTransformer.java
+++ b/src/java/org/apache/commons/collections/functors/NOPTransformer.java
@@ -28,13 +28,13 @@ import org.apache.commons.collections.Transformer;
  *
  * @author Stephen Colebourne
  */
-public class NOPTransformer implements Transformer, Serializable {
+public class NOPTransformer<T> implements Transformer<T, T>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 2133891748318574490L;
 
     /** Singleton predicate instance */
-    public static final Transformer INSTANCE = new NOPTransformer();
+    public static final Transformer<Object, Object> INSTANCE = new NOPTransformer<Object>();
 
     /**
      * Factory returning the singleton instance.
@@ -42,8 +42,9 @@ public class NOPTransformer implements Transformer, Serializable {
      * @return the singleton instance
      * @since Commons Collections 3.1
      */
-    public static Transformer getInstance() {
-        return INSTANCE;
+    @SuppressWarnings("unchecked")
+    public static <T> Transformer<T, T> getInstance() {
+        return (Transformer<T, T>) INSTANCE;
     }
 
     /**
@@ -59,7 +60,7 @@ public class NOPTransformer implements Transformer, Serializable {
      * @param input  the input object to transform
      * @return the transformed result which is the input
      */
-    public Object transform(Object input) {
+    public T transform(T input) {
         return input;
     }
 

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/NonePredicate.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/NonePredicate.java b/src/java/org/apache/commons/collections/functors/NonePredicate.java
index f3cf062..11b07a1 100644
--- a/src/java/org/apache/commons/collections/functors/NonePredicate.java
+++ b/src/java/org/apache/commons/collections/functors/NonePredicate.java
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -35,14 +35,14 @@ import org.apache.commons.collections.Predicate;
  * @author Stephen Colebourne
  * @author Matt Benson
  */
-public final class NonePredicate implements Predicate, PredicateDecorator, Serializable {
+public final class NonePredicate<T> implements Predicate<T>, PredicateDecorator<T>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 2007613066565892961L;
-    
+
     /** The array of predicates to call */
-    private final Predicate[] iPredicates;
-    
+    private final Predicate<? super T>[] iPredicates;
+
     /**
      * Factory to create the predicate.
      * <p>
@@ -53,13 +53,13 @@ public final class NonePredicate implements Predicate, PredicateDecorator, Seria
      * @throws IllegalArgumentException if the predicates array is null
      * @throws IllegalArgumentException if any predicate in the array is null
      */
-    public static Predicate getInstance(Predicate[] predicates) {
+    public static <T> Predicate<T> getInstance(Predicate<? super T>[] predicates) {
         FunctorUtils.validate(predicates);
         if (predicates.length == 0) {
-            return TruePredicate.INSTANCE;
+            return TruePredicate.<T>truePredicate();
         }
         predicates = FunctorUtils.copy(predicates);
-        return new NonePredicate(predicates);
+        return new NonePredicate<T>(predicates);
     }
 
     /**
@@ -72,32 +72,32 @@ public final class NonePredicate implements Predicate, PredicateDecorator, Seria
      * @throws IllegalArgumentException if the predicates array is null
      * @throws IllegalArgumentException if any predicate in the array is null
      */
-    public static Predicate getInstance(Collection predicates) {
-        Predicate[] preds = FunctorUtils.validate(predicates);
+    public static <T> Predicate<T> getInstance(Collection<? extends Predicate<T>> predicates) {
+        Predicate<? super T>[] preds = FunctorUtils.validate(predicates);
         if (preds.length == 0) {
-            return TruePredicate.INSTANCE;
+            return TruePredicate.<T>truePredicate();
         }
-        return new NonePredicate(preds);
+        return new NonePredicate<T>(preds);
     }
 
     /**
      * Constructor that performs no validation.
      * Use <code>getInstance</code> if you want that.
-     * 
+     *
      * @param predicates  the predicates to check, not cloned, not null
      */
-    public NonePredicate(Predicate[] predicates) {
+    public NonePredicate(Predicate<? super T>[] predicates) {
         super();
         iPredicates = predicates;
     }
 
     /**
      * Evaluates the predicate returning false if any stored predicate returns false.
-     * 
+     *
      * @param object  the input object
      * @return true if none of decorated predicates return true
      */
-    public boolean evaluate(Object object) {
+    public boolean evaluate(T object) {
         for (int i = 0; i < iPredicates.length; i++) {
             if (iPredicates[i].evaluate(object)) {
                 return false;
@@ -108,11 +108,11 @@ public final class NonePredicate implements Predicate, PredicateDecorator, Seria
 
     /**
      * Gets the predicates, do not modify the array.
-     * 
+     *
      * @return the predicates
      * @since Commons Collections 3.1
      */
-    public Predicate[] getPredicates() {
+    public Predicate<? super T>[] getPredicates() {
         return iPredicates;
     }
 

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/NotNullPredicate.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/NotNullPredicate.java b/src/java/org/apache/commons/collections/functors/NotNullPredicate.java
index c68d0cf..218ad82 100644
--- a/src/java/org/apache/commons/collections/functors/NotNullPredicate.java
+++ b/src/java/org/apache/commons/collections/functors/NotNullPredicate.java
@@ -28,13 +28,13 @@ import org.apache.commons.collections.Predicate;
  *
  * @author Stephen Colebourne
  */
-public final class NotNullPredicate implements Predicate, Serializable {
+public final class NotNullPredicate<T> implements Predicate<T>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 7533784454832764388L;
     
     /** Singleton predicate instance */
-    public static final Predicate INSTANCE = new NotNullPredicate();
+    public static final Predicate<Object> INSTANCE = new NotNullPredicate<Object>();
 
     /**
      * Factory returning the singleton instance.
@@ -42,8 +42,9 @@ public final class NotNullPredicate implements Predicate, Serializable {
      * @return the singleton instance
      * @since Commons Collections 3.1
      */
-    public static Predicate getInstance() {
-        return INSTANCE;
+    @SuppressWarnings("unchecked")
+    public static <T> Predicate<T> getInstance() {
+        return (Predicate<T>) INSTANCE;
     }
 
     /**
@@ -59,7 +60,7 @@ public final class NotNullPredicate implements Predicate, Serializable {
      * @param object  the object to evaluate
      * @return true if not null
      */
-    public boolean evaluate(Object object) {
+    public boolean evaluate(T object) {
         return (object != null);
     }
 

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/NotPredicate.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/NotPredicate.java b/src/java/org/apache/commons/collections/functors/NotPredicate.java
index 7096683..5bc171b 100644
--- a/src/java/org/apache/commons/collections/functors/NotPredicate.java
+++ b/src/java/org/apache/commons/collections/functors/NotPredicate.java
@@ -28,13 +28,13 @@ import org.apache.commons.collections.Predicate;
  *
  * @author Stephen Colebourne
  */
-public final class NotPredicate implements Predicate, PredicateDecorator, Serializable {
+public final class NotPredicate<T> implements Predicate<T>, PredicateDecorator<T>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = -2654603322338049674L;
     
     /** The predicate to decorate */
-    private final Predicate iPredicate;
+    private final Predicate<? super T> iPredicate;
     
     /**
      * Factory to create the not predicate.
@@ -43,11 +43,11 @@ public final class NotPredicate implements Predicate, PredicateDecorator, Serial
      * @return the predicate
      * @throws IllegalArgumentException if the predicate is null
      */
-    public static Predicate getInstance(Predicate predicate) {
+    public static <T> Predicate<T> getInstance(Predicate<? super T> predicate) {
         if (predicate == null) {
             throw new IllegalArgumentException("Predicate must not be null");
         }
-        return new NotPredicate(predicate);
+        return new NotPredicate<T>(predicate);
     }
 
     /**
@@ -56,7 +56,7 @@ public final class NotPredicate implements Predicate, PredicateDecorator, Serial
      * 
      * @param predicate  the predicate to call after the null check
      */
-    public NotPredicate(Predicate predicate) {
+    public NotPredicate(Predicate<? super T> predicate) {
         super();
         iPredicate = predicate;
     }
@@ -67,7 +67,7 @@ public final class NotPredicate implements Predicate, PredicateDecorator, Serial
      * @param object  the input object
      * @return true if predicate returns false
      */
-    public boolean evaluate(Object object) {
+    public boolean evaluate(T object) {
         return !(iPredicate.evaluate(object));
     }
 
@@ -77,7 +77,8 @@ public final class NotPredicate implements Predicate, PredicateDecorator, Serial
      * @return the predicate as the only element in an array
      * @since Commons Collections 3.1
      */
-    public Predicate[] getPredicates() {
+    @SuppressWarnings("unchecked")
+    public Predicate<? super T>[] getPredicates() {
         return new Predicate[] {iPredicate};
     }
 

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/NullIsExceptionPredicate.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/NullIsExceptionPredicate.java b/src/java/org/apache/commons/collections/functors/NullIsExceptionPredicate.java
index 8e6728c..d8269fa 100644
--- a/src/java/org/apache/commons/collections/functors/NullIsExceptionPredicate.java
+++ b/src/java/org/apache/commons/collections/functors/NullIsExceptionPredicate.java
@@ -29,13 +29,13 @@ import org.apache.commons.collections.Predicate;
  *
  * @author Stephen Colebourne
  */
-public final class NullIsExceptionPredicate implements Predicate, PredicateDecorator, Serializable {
+public final class NullIsExceptionPredicate<T> implements Predicate<T>, PredicateDecorator<T>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 3243449850504576071L;
     
     /** The predicate to decorate */
-    private final Predicate iPredicate;
+    private final Predicate<? super T> iPredicate;
     
     /**
      * Factory to create the null exception predicate.
@@ -44,11 +44,11 @@ public final class NullIsExceptionPredicate implements Predicate, PredicateDecor
      * @return the predicate
      * @throws IllegalArgumentException if the predicate is null
      */
-    public static Predicate getInstance(Predicate predicate) {
+    public static <T> Predicate<T> getInstance(Predicate<? super T> predicate) {
         if (predicate == null) {
             throw new IllegalArgumentException("Predicate must not be null");
         }
-        return new NullIsExceptionPredicate(predicate);
+        return new NullIsExceptionPredicate<T>(predicate);
     }
 
     /**
@@ -57,7 +57,7 @@ public final class NullIsExceptionPredicate implements Predicate, PredicateDecor
      * 
      * @param predicate  the predicate to call after the null check
      */
-    public NullIsExceptionPredicate(Predicate predicate) {
+    public NullIsExceptionPredicate(Predicate<? super T> predicate) {
         super();
         iPredicate = predicate;
     }
@@ -70,7 +70,7 @@ public final class NullIsExceptionPredicate implements Predicate, PredicateDecor
      * @return true if decorated predicate returns true
      * @throws FunctorException if input is null
      */
-    public boolean evaluate(Object object) {
+    public boolean evaluate(T object) {
         if (object == null) {
             throw new FunctorException("Input Object must not be null");
         }
@@ -83,8 +83,9 @@ public final class NullIsExceptionPredicate implements Predicate, PredicateDecor
      * @return the predicate as the only element in an array
      * @since Commons Collections 3.1
      */
-    public Predicate[] getPredicates() {
-        return new Predicate[] {iPredicate};
+    @SuppressWarnings("unchecked")
+    public Predicate<? super T>[] getPredicates() {
+        return new Predicate[] { iPredicate };
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/NullIsFalsePredicate.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/NullIsFalsePredicate.java b/src/java/org/apache/commons/collections/functors/NullIsFalsePredicate.java
index a60a277..217422c 100644
--- a/src/java/org/apache/commons/collections/functors/NullIsFalsePredicate.java
+++ b/src/java/org/apache/commons/collections/functors/NullIsFalsePredicate.java
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,41 +22,41 @@ import org.apache.commons.collections.Predicate;
 
 /**
  * Predicate implementation that returns false if the input is null.
- * 
+ *
  * @since Commons Collections 3.0
  * @version $Revision$ $Date$
  *
  * @author Stephen Colebourne
  */
-public final class NullIsFalsePredicate implements Predicate, PredicateDecorator, Serializable {
+public final class NullIsFalsePredicate<T> implements Predicate<T>, PredicateDecorator<T>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = -2997501534564735525L;
-    
+
     /** The predicate to decorate */
-    private final Predicate iPredicate;
-    
+    private final Predicate<? super T> iPredicate;
+
     /**
      * Factory to create the null false predicate.
-     * 
+     *
      * @param predicate  the predicate to decorate, not null
      * @return the predicate
      * @throws IllegalArgumentException if the predicate is null
      */
-    public static Predicate getInstance(Predicate predicate) {
+    public static <T> Predicate<T> getInstance(Predicate<? super T> predicate) {
         if (predicate == null) {
             throw new IllegalArgumentException("Predicate must not be null");
         }
-        return new NullIsFalsePredicate(predicate);
+        return new NullIsFalsePredicate<T>(predicate);
     }
 
     /**
      * Constructor that performs no validation.
      * Use <code>getInstance</code> if you want that.
-     * 
+     *
      * @param predicate  the predicate to call after the null check
      */
-    public NullIsFalsePredicate(Predicate predicate) {
+    public NullIsFalsePredicate(Predicate<? super T> predicate) {
         super();
         iPredicate = predicate;
     }
@@ -64,11 +64,11 @@ public final class NullIsFalsePredicate implements Predicate, PredicateDecorator
     /**
      * Evaluates the predicate returning the result of the decorated predicate
      * once a null check is performed.
-     * 
+     *
      * @param object  the input object
      * @return true if decorated predicate returns true, false if input is null
      */
-    public boolean evaluate(Object object) {
+    public boolean evaluate(T object) {
         if (object == null) {
             return false;
         }
@@ -77,12 +77,13 @@ public final class NullIsFalsePredicate implements Predicate, PredicateDecorator
 
     /**
      * Gets the predicate being decorated.
-     * 
+     *
      * @return the predicate as the only element in an array
      * @since Commons Collections 3.1
      */
-    public Predicate[] getPredicates() {
-        return new Predicate[] {iPredicate};
+    @SuppressWarnings("unchecked")
+    public Predicate<? super T>[] getPredicates() {
+        return new Predicate[] { iPredicate };
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/NullIsTruePredicate.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/NullIsTruePredicate.java b/src/java/org/apache/commons/collections/functors/NullIsTruePredicate.java
index e75fc23..0ba668f 100644
--- a/src/java/org/apache/commons/collections/functors/NullIsTruePredicate.java
+++ b/src/java/org/apache/commons/collections/functors/NullIsTruePredicate.java
@@ -28,13 +28,13 @@ import org.apache.commons.collections.Predicate;
  *
  * @author Stephen Colebourne
  */
-public final class NullIsTruePredicate implements Predicate, PredicateDecorator, Serializable {
+public final class NullIsTruePredicate<T> implements Predicate<T>, PredicateDecorator<T>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = -7625133768987126273L;
     
     /** The predicate to decorate */
-    private final Predicate iPredicate;
+    private final Predicate<? super T> iPredicate;
     
     /**
      * Factory to create the null true predicate.
@@ -43,11 +43,11 @@ public final class NullIsTruePredicate implements Predicate, PredicateDecorator,
      * @return the predicate
      * @throws IllegalArgumentException if the predicate is null
      */
-    public static Predicate getInstance(Predicate predicate) {
+    public static <T> Predicate<T> getInstance(Predicate<? super T> predicate) {
         if (predicate == null) {
             throw new IllegalArgumentException("Predicate must not be null");
         }
-        return new NullIsTruePredicate(predicate);
+        return new NullIsTruePredicate<T>(predicate);
     }
 
     /**
@@ -56,7 +56,7 @@ public final class NullIsTruePredicate implements Predicate, PredicateDecorator,
      * 
      * @param predicate  the predicate to call after the null check
      */
-    public NullIsTruePredicate(Predicate predicate) {
+    public NullIsTruePredicate(Predicate<? super T> predicate) {
         super();
         iPredicate = predicate;
     }
@@ -68,7 +68,7 @@ public final class NullIsTruePredicate implements Predicate, PredicateDecorator,
      * @param object  the input object
      * @return true if decorated predicate returns true or input is null
      */
-    public boolean evaluate(Object object) {
+    public boolean evaluate(T object) {
         if (object == null) {
             return true;
         }
@@ -81,8 +81,9 @@ public final class NullIsTruePredicate implements Predicate, PredicateDecorator,
      * @return the predicate as the only element in an array
      * @since Commons Collections 3.1
      */
-    public Predicate[] getPredicates() {
-        return new Predicate[] {iPredicate};
+    @SuppressWarnings("unchecked")
+    public Predicate<? super T>[] getPredicates() {
+        return new Predicate[] { iPredicate };
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/OnePredicate.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/OnePredicate.java b/src/java/org/apache/commons/collections/functors/OnePredicate.java
index 425f9b6..5f3252e 100644
--- a/src/java/org/apache/commons/collections/functors/OnePredicate.java
+++ b/src/java/org/apache/commons/collections/functors/OnePredicate.java
@@ -35,13 +35,13 @@ import org.apache.commons.collections.Predicate;
  * @author Stephen Colebourne
  * @author Matt Benson
  */
-public final class OnePredicate implements Predicate, PredicateDecorator, Serializable {
+public final class OnePredicate<T> implements Predicate<T>, PredicateDecorator<T>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = -8125389089924745785L;
     
     /** The array of predicates to call */
-    private final Predicate[] iPredicates;
+    private final Predicate<? super T>[] iPredicates;
     
     /**
      * Factory to create the predicate.
@@ -54,16 +54,17 @@ public final class OnePredicate implements Predicate, PredicateDecorator, Serial
      * @throws IllegalArgumentException if the predicates array is null
      * @throws IllegalArgumentException if any predicate in the array is null
      */
-    public static Predicate getInstance(Predicate[] predicates) {
+    @SuppressWarnings("unchecked")
+    public static <T> Predicate<T> getInstance(Predicate<? super T>[] predicates) {
         FunctorUtils.validate(predicates);
         if (predicates.length == 0) {
-            return FalsePredicate.INSTANCE;
+            return FalsePredicate.<T>falsePredicate();
         }
         if (predicates.length == 1) {
-            return predicates[0];
+            return (Predicate<T>) predicates[0];
         }
         predicates = FunctorUtils.copy(predicates);
-        return new OnePredicate(predicates);
+        return new OnePredicate<T>(predicates);
     }
 
     /**
@@ -74,9 +75,9 @@ public final class OnePredicate implements Predicate, PredicateDecorator, Serial
      * @throws IllegalArgumentException if the predicates array is null
      * @throws IllegalArgumentException if any predicate in the array is null
      */
-    public static Predicate getInstance(Collection predicates) {
-        Predicate[] preds = FunctorUtils.validate(predicates);
-        return new OnePredicate(preds);
+    public static <T> Predicate<T> getInstance(Collection<? extends Predicate<T>> predicates) {
+        Predicate<? super T>[] preds = FunctorUtils.validate(predicates);
+        return new OnePredicate<T>(preds);
     }
 
     /**
@@ -85,7 +86,7 @@ public final class OnePredicate implements Predicate, PredicateDecorator, Serial
      * 
      * @param predicates  the predicates to check, not cloned, not null
      */
-    public OnePredicate(Predicate[] predicates) {
+    public OnePredicate(Predicate<? super T>[] predicates) {
         super();
         iPredicates = predicates;
     }
@@ -97,7 +98,7 @@ public final class OnePredicate implements Predicate, PredicateDecorator, Serial
      * @param object  the input object
      * @return true if only one decorated predicate returns true
      */
-    public boolean evaluate(Object object) {
+    public boolean evaluate(T object) {
         boolean match = false;
         for (int i = 0; i < iPredicates.length; i++) {
             if (iPredicates[i].evaluate(object)) {
@@ -116,7 +117,7 @@ public final class OnePredicate implements Predicate, PredicateDecorator, Serial
      * @return the predicates
      * @since Commons Collections 3.1
      */
-    public Predicate[] getPredicates() {
+    public Predicate<? super T>[] getPredicates() {
         return iPredicates;
     }
 

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/OrPredicate.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/OrPredicate.java b/src/java/org/apache/commons/collections/functors/OrPredicate.java
index ea7f0fd..e87edbd 100644
--- a/src/java/org/apache/commons/collections/functors/OrPredicate.java
+++ b/src/java/org/apache/commons/collections/functors/OrPredicate.java
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,45 +22,45 @@ import org.apache.commons.collections.Predicate;
 
 /**
  * Predicate implementation that returns true if either of the predicates return true.
- * 
+ *
  * @since Commons Collections 3.0
  * @version $Revision$ $Date$
  *
  * @author Stephen Colebourne
  */
-public final class OrPredicate implements Predicate, PredicateDecorator, Serializable {
+public final class OrPredicate<T> implements Predicate<T>, PredicateDecorator<T>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = -8791518325735182855L;
-    
+
     /** The array of predicates to call */
-    private final Predicate iPredicate1;
+    private final Predicate<? super T> iPredicate1;
     /** The array of predicates to call */
-    private final Predicate iPredicate2;
-    
+    private final Predicate<? super T> iPredicate2;
+
     /**
      * Factory to create the predicate.
-     * 
+     *
      * @param predicate1  the first predicate to check, not null
      * @param predicate2  the second predicate to check, not null
      * @return the <code>and</code> predicate
      * @throws IllegalArgumentException if either predicate is null
      */
-    public static Predicate getInstance(Predicate predicate1, Predicate predicate2) {
+    public static <T> Predicate<T> getInstance(Predicate<? super T> predicate1, Predicate<? super T> predicate2) {
         if (predicate1 == null || predicate2 == null) {
             throw new IllegalArgumentException("Predicate must not be null");
         }
-        return new OrPredicate(predicate1, predicate2);
+        return new OrPredicate<T>(predicate1, predicate2);
     }
 
     /**
      * Constructor that performs no validation.
      * Use <code>getInstance</code> if you want that.
-     * 
+     *
      * @param predicate1  the first predicate to check, not null
      * @param predicate2  the second predicate to check, not null
      */
-    public OrPredicate(Predicate predicate1, Predicate predicate2) {
+    public OrPredicate(Predicate<? super T> predicate1, Predicate<? super T> predicate2) {
         super();
         iPredicate1 = predicate1;
         iPredicate2 = predicate2;
@@ -68,21 +68,22 @@ public final class OrPredicate implements Predicate, PredicateDecorator, Seriali
 
     /**
      * Evaluates the predicate returning true if either predicate returns true.
-     * 
+     *
      * @param object  the input object
      * @return true if either decorated predicate returns true
      */
-    public boolean evaluate(Object object) {
+    public boolean evaluate(T object) {
        return (iPredicate1.evaluate(object) || iPredicate2.evaluate(object));
     }
 
     /**
      * Gets the two predicates being decorated as an array.
-     * 
+     *
      * @return the predicates
      * @since Commons Collections 3.1
      */
-    public Predicate[] getPredicates() {
+    @SuppressWarnings("unchecked")
+    public Predicate<? super T>[] getPredicates() {
         return new Predicate[] {iPredicate1, iPredicate2};
     }
 

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/PredicateTransformer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/PredicateTransformer.java b/src/java/org/apache/commons/collections/functors/PredicateTransformer.java
index a0a83d9..ca8c93b 100644
--- a/src/java/org/apache/commons/collections/functors/PredicateTransformer.java
+++ b/src/java/org/apache/commons/collections/functors/PredicateTransformer.java
@@ -23,20 +23,20 @@ import org.apache.commons.collections.Transformer;
 
 /**
  * Transformer implementation that calls a Predicate using the input object
- * and then returns the input.
+ * and then returns the result.
  * 
  * @since Commons Collections 3.0
  * @version $Revision$ $Date$
  *
  * @author Stephen Colebourne
  */
-public class PredicateTransformer implements Transformer, Serializable {
+public class PredicateTransformer<T> implements Transformer<T, Boolean>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 5278818408044349346L;
 
     /** The closure to wrap */
-    private final Predicate iPredicate;
+    private final Predicate<? super T> iPredicate;
 
     /**
      * Factory method that performs validation.
@@ -45,11 +45,11 @@ public class PredicateTransformer implements Transformer, Serializable {
      * @return the <code>predicate</code> transformer
      * @throws IllegalArgumentException if the predicate is null
      */
-    public static Transformer getInstance(Predicate predicate) {
+    public static <T> Transformer<T, Boolean> getInstance(Predicate<? super T> predicate) {
         if (predicate == null) {
             throw new IllegalArgumentException("Predicate must not be null");
         }
-        return new PredicateTransformer(predicate);
+        return new PredicateTransformer<T>(predicate);
     }
 
     /**
@@ -58,7 +58,7 @@ public class PredicateTransformer implements Transformer, Serializable {
      * 
      * @param predicate  the predicate to call, not null
      */
-    public PredicateTransformer(Predicate predicate) {
+    public PredicateTransformer(Predicate<? super T> predicate) {
         super();
         iPredicate = predicate;
     }
@@ -69,8 +69,8 @@ public class PredicateTransformer implements Transformer, Serializable {
      * @param input  the input object to transform
      * @return the transformed result
      */
-    public Object transform(Object input) {
-        return (iPredicate.evaluate(input) ? Boolean.TRUE : Boolean.FALSE);
+    public Boolean transform(T input) {
+        return iPredicate.evaluate(input);
     }
 
     /**
@@ -79,7 +79,7 @@ public class PredicateTransformer implements Transformer, Serializable {
      * @return the predicate
      * @since Commons Collections 3.1
      */
-    public Predicate getPredicate() {
+    public Predicate<? super T> getPredicate() {
         return iPredicate;
     }
 

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/PrototypeFactory.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/PrototypeFactory.java b/src/java/org/apache/commons/collections/functors/PrototypeFactory.java
index d3b2ed0..c23d584 100644
--- a/src/java/org/apache/commons/collections/functors/PrototypeFactory.java
+++ b/src/java/org/apache/commons/collections/functors/PrototypeFactory.java
@@ -55,22 +55,22 @@ public class PrototypeFactory {
      * @throws IllegalArgumentException if the prototype is null
      * @throws IllegalArgumentException if the prototype cannot be cloned
      */
-    public static Factory getInstance(Object prototype) {
+    @SuppressWarnings("unchecked")
+    public static <T> Factory<T> getInstance(T prototype) {
         if (prototype == null) {
-            return ConstantFactory.NULL_INSTANCE;
+            return ConstantFactory.<T>getInstance(null);
         }
         try {
             Method method = prototype.getClass().getMethod("clone", (Class[]) null);
-            return new PrototypeCloneFactory(prototype, method);
+            return new PrototypeCloneFactory<T>(prototype, method);
 
         } catch (NoSuchMethodException ex) {
             try {
-                prototype.getClass().getConstructor(new Class[] { prototype.getClass()});
-                return new InstantiateFactory(
-                    prototype.getClass(),
-                    new Class[] { prototype.getClass()},
+                prototype.getClass().getConstructor(new Class<?>[] { prototype.getClass() });
+                return new InstantiateFactory<T>(
+                    (Class<T>) prototype.getClass(),
+                    new Class<?>[] { prototype.getClass() },
                     new Object[] { prototype });
-
             } catch (NoSuchMethodException ex2) {
                 if (prototype instanceof Serializable) {
                     return new PrototypeSerializationFactory((Serializable) prototype);
@@ -93,20 +93,20 @@ public class PrototypeFactory {
     /**
      * PrototypeCloneFactory creates objects by copying a prototype using the clone method.
      */
-    static class PrototypeCloneFactory implements Factory, Serializable {
+    static class PrototypeCloneFactory<T> implements Factory<T>, Serializable {
         
         /** The serial version */
         private static final long serialVersionUID = 5604271422565175555L;
         
         /** The object to clone each time */
-        private final Object iPrototype;
+        private final T iPrototype;
         /** The method used to clone */
         private transient Method iCloneMethod;
 
         /**
          * Constructor to store prototype.
          */
-        private PrototypeCloneFactory(Object prototype, Method method) {
+        private PrototypeCloneFactory(T prototype, Method method) {
             super();
             iPrototype = prototype;
             iCloneMethod = method;
@@ -118,7 +118,6 @@ public class PrototypeFactory {
         private void findCloneMethod() {
             try {
                 iCloneMethod = iPrototype.getClass().getMethod("clone", (Class[]) null);
-
             } catch (NoSuchMethodException ex) {
                 throw new IllegalArgumentException("PrototypeCloneFactory: The clone method must exist and be public ");
             }
@@ -129,15 +128,15 @@ public class PrototypeFactory {
          * 
          * @return the new object
          */
-        public Object create() {
+        @SuppressWarnings("unchecked")
+        public T create() {
             // needed for post-serialization
             if (iCloneMethod == null) {
                 findCloneMethod();
             }
 
             try {
-                return iCloneMethod.invoke(iPrototype, (Object[])null);
-
+                return (T) iCloneMethod.invoke(iPrototype, (Object[]) null);
             } catch (IllegalAccessException ex) {
                 throw new FunctorException("PrototypeCloneFactory: Clone method must be public", ex);
             } catch (InvocationTargetException ex) {
@@ -151,18 +150,18 @@ public class PrototypeFactory {
     /**
      * PrototypeSerializationFactory creates objects by cloning a prototype using serialization.
      */
-    static class PrototypeSerializationFactory implements Factory, Serializable {
+    static class PrototypeSerializationFactory<T extends Serializable> implements Factory<T>, Serializable {
         
         /** The serial version */
         private static final long serialVersionUID = -8704966966139178833L;
         
         /** The object to clone via serialization each time */
-        private final Serializable iPrototype;
+        private final T iPrototype;
 
         /**
          * Constructor to store prototype
          */
-        private PrototypeSerializationFactory(Serializable prototype) {
+        private PrototypeSerializationFactory(T prototype) {
             super();
             iPrototype = prototype;
         }
@@ -172,7 +171,8 @@ public class PrototypeFactory {
          * 
          * @return the new object
          */
-        public Object create() {
+        @SuppressWarnings("unchecked")
+        public T create() {
             ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
             ByteArrayInputStream bais = null;
             try {
@@ -181,7 +181,7 @@ public class PrototypeFactory {
 
                 bais = new ByteArrayInputStream(baos.toByteArray());
                 ObjectInputStream in = new ObjectInputStream(bais);
-                return in.readObject();
+                return (T) in.readObject();
 
             } catch (ClassNotFoundException ex) {
                 throw new FunctorException(ex);

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/StringValueTransformer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/StringValueTransformer.java b/src/java/org/apache/commons/collections/functors/StringValueTransformer.java
index 8e75c82..3e54967 100644
--- a/src/java/org/apache/commons/collections/functors/StringValueTransformer.java
+++ b/src/java/org/apache/commons/collections/functors/StringValueTransformer.java
@@ -29,13 +29,13 @@ import org.apache.commons.collections.Transformer;
  *
  * @author Stephen Colebourne
  */
-public final class StringValueTransformer implements Transformer, Serializable {
+public final class StringValueTransformer<T> implements Transformer<T, String>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 7511110693171758606L;
 
     /** Singleton predicate instance */
-    public static final Transformer INSTANCE = new StringValueTransformer();
+    public static final Transformer<Object, String> INSTANCE = new StringValueTransformer<Object>();
 
     /**
      * Factory returning the singleton instance.
@@ -43,8 +43,9 @@ public final class StringValueTransformer implements Transformer, Serializable {
      * @return the singleton instance
      * @since Commons Collections 3.1
      */
-    public static Transformer getInstance() {
-        return INSTANCE;
+    @SuppressWarnings("unchecked")
+    public static <T> Transformer<T, String> getInstance() {
+        return (Transformer<T, String>) INSTANCE;
     }
 
     /**
@@ -60,7 +61,7 @@ public final class StringValueTransformer implements Transformer, Serializable {
      * @param input  the input object to transform
      * @return the transformed result
      */
-    public Object transform(Object input) {
+    public String transform(T input) {
         return String.valueOf(input);
     }
 

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/java/org/apache/commons/collections/functors/SwitchClosure.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/functors/SwitchClosure.java b/src/java/org/apache/commons/collections/functors/SwitchClosure.java
index be64369..1ee7806 100644
--- a/src/java/org/apache/commons/collections/functors/SwitchClosure.java
+++ b/src/java/org/apache/commons/collections/functors/SwitchClosure.java
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,7 +17,6 @@
 package org.apache.commons.collections.functors;
 
 import java.io.Serializable;
-import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.commons.collections.Closure;
@@ -26,27 +25,27 @@ import org.apache.commons.collections.Predicate;
 /**
  * Closure implementation calls the closure whose predicate returns true,
  * like a switch statement.
- * 
+ *
  * @since Commons Collections 3.0
  * @version $Revision$ $Date$
  *
  * @author Stephen Colebourne
  */
-public class SwitchClosure implements Closure, Serializable {
+public class SwitchClosure<E> implements Closure<E>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 3518477308466486130L;
 
     /** The tests to consider */
-    private final Predicate[] iPredicates;
+    private final Predicate<? super E>[] iPredicates;
     /** The matching closures to call */
-    private final Closure[] iClosures;
+    private final Closure<? super E>[] iClosures;
     /** The default closure to call if no tests match */
-    private final Closure iDefault;
+    private final Closure<? super E> iDefault;
 
     /**
      * Factory method that performs validation and copies the parameter arrays.
-     * 
+     *
      * @param predicates  array of predicates, cloned, no nulls
      * @param closures  matching array of closures, cloned, no nulls
      * @param defaultClosure  the closure to use if no match, null means nop
@@ -54,85 +53,82 @@ public class SwitchClosure implements Closure, Serializable {
      * @throws IllegalArgumentException if array is null
      * @throws IllegalArgumentException if any element in the array is null
      */
-    public static Closure getInstance(Predicate[] predicates, Closure[] closures, Closure defaultClosure) {
+    @SuppressWarnings("unchecked")
+    public static <E> Closure<E> getInstance(Predicate<? super E>[] predicates, Closure<? super E>[] closures, Closure<? super E> defaultClosure) {
         FunctorUtils.validate(predicates);
         FunctorUtils.validate(closures);
         if (predicates.length != closures.length) {
             throw new IllegalArgumentException("The predicate and closure arrays must be the same size");
         }
         if (predicates.length == 0) {
-            return (defaultClosure == null ? NOPClosure.INSTANCE : defaultClosure);
+            return (Closure<E>) (defaultClosure == null ? NOPClosure.<E>getInstance(): defaultClosure);
         }
         predicates = FunctorUtils.copy(predicates);
         closures = FunctorUtils.copy(closures);
-        return new SwitchClosure(predicates, closures, defaultClosure);
+        return new SwitchClosure<E>(predicates, closures, defaultClosure);
     }
 
     /**
-     * Create a new Closure that calls one of the closures depending 
-     * on the predicates. 
+     * Create a new Closure that calls one of the closures depending
+     * on the predicates.
      * <p>
-     * The Map consists of Predicate keys and Closure values. A closure 
+     * The Map consists of Predicate keys and Closure values. A closure
      * is called if its matching predicate returns true. Each predicate is evaluated
      * until one returns true. If no predicates evaluate to true, the default
-     * closure is called. The default closure is set in the map with a 
-     * null key. The ordering is that of the iterator() method on the entryset 
+     * closure is called. The default closure is set in the map with a
+     * null key. The ordering is that of the iterator() method on the entryset
      * collection of the map.
-     * 
+     *
      * @param predicatesAndClosures  a map of predicates to closures
      * @return the <code>switch</code> closure
      * @throws IllegalArgumentException if the map is null
      * @throws IllegalArgumentException if any closure in the map is null
      * @throws ClassCastException  if the map elements are of the wrong type
      */
-    public static Closure getInstance(Map predicatesAndClosures) {
-        Closure[] closures = null;
-        Predicate[] preds = null;
+    @SuppressWarnings("unchecked")
+    public static <E> Closure<E> getInstance(Map<Predicate<E>, Closure<E>> predicatesAndClosures) {
         if (predicatesAndClosures == null) {
             throw new IllegalArgumentException("The predicate and closure map must not be null");
         }
-        if (predicatesAndClosures.size() == 0) {
-            return NOPClosure.INSTANCE;
-        }
         // convert to array like this to guarantee iterator() ordering
-        Closure defaultClosure = (Closure) predicatesAndClosures.remove(null);
+        Closure<? super E> defaultClosure = predicatesAndClosures.remove(null);
         int size = predicatesAndClosures.size();
         if (size == 0) {
-            return (defaultClosure == null ? NOPClosure.INSTANCE : defaultClosure);
+            return (Closure<E>) (defaultClosure == null ? NOPClosure.<E>getInstance() : defaultClosure);
         }
-        closures = new Closure[size];
-        preds = new Predicate[size];
+        Closure<E>[] closures = new Closure[size];
+        Predicate<E>[] preds = new Predicate[size];
         int i = 0;
-        for (Iterator it = predicatesAndClosures.entrySet().iterator(); it.hasNext();) {
-            Map.Entry entry = (Map.Entry) it.next();
-            preds[i] = (Predicate) entry.getKey();
-            closures[i] = (Closure) entry.getValue();
+        for (Map.Entry<Predicate<E>, Closure<E>> entry : predicatesAndClosures.entrySet()) {
+            preds[i] = entry.getKey();
+            closures[i] = entry.getValue();
             i++;
         }
-        return new SwitchClosure(preds, closures, defaultClosure);
+        return new SwitchClosure<E>(preds, closures, defaultClosure);
     }
-    
+
     /**
      * Constructor that performs no validation.
      * Use <code>getInstance</code> if you want that.
-     * 
+     *
      * @param predicates  array of predicates, not cloned, no nulls
      * @param closures  matching array of closures, not cloned, no nulls
      * @param defaultClosure  the closure to use if no match, null means nop
      */
-    public SwitchClosure(Predicate[] predicates, Closure[] closures, Closure defaultClosure) {
+    @SuppressWarnings("unchecked")
+    public SwitchClosure(Predicate<? super E>[] predicates, Closure<? super E>[] closures, Closure<? super E> defaultClosure) {
         super();
         iPredicates = predicates;
         iClosures = closures;
-        iDefault = (defaultClosure == null ? NOPClosure.INSTANCE : defaultClosure);
+        iDefault = (Closure<? super E>) (defaultClosure == null ? NOPClosure.<E>getInstance() : defaultClosure);
     }
 
     /**
      * Executes the closure whose matching predicate returns true
-     * 
+     *
      * @param input  the input object
      */
-    public void execute(Object input) {
+    public void execute(E input) {
         for (int i = 0; i < iPredicates.length; i++) {
             if (iPredicates[i].evaluate(input) == true) {
                 iClosures[i].execute(input);
@@ -144,32 +140,32 @@ public class SwitchClosure implements Closure, Serializable {
 
     /**
      * Gets the predicates, do not modify the array.
-     * 
+     *
      * @return the predicates
      * @since Commons Collections 3.1
      */
-    public Predicate[] getPredicates() {
+    public Predicate<? super E>[] getPredicates() {
         return iPredicates;
     }
 
     /**
      * Gets the closures, do not modify the array.
-     * 
+     *
      * @return the closures
      * @since Commons Collections 3.1
      */
-    public Closure[] getClosures() {
+    public Closure<? super E>[] getClosures() {
         return iClosures;
     }
 
     /**
      * Gets the default closure.
-     * 
+     *
      * @return the default closure
      * @since Commons Collections 3.1
      */
-    public Closure getDefaultClosure() {
+    public Closure<? super E> getDefaultClosure() {
         return iDefault;
     }
-    
+
 }


Mime
View raw message