commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r814997 [4/18] - in /commons/proper/collections/trunk/src: java/org/apache/commons/collections/ java/org/apache/commons/collections/bag/ java/org/apache/commons/collections/bidimap/ java/org/apache/commons/collections/buffer/ java/org/apach...
Date Tue, 15 Sep 2009 05:30:02 GMT
Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ChainedTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ChainedTransformer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ChainedTransformer.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ChainedTransformer.java Tue Sep 15 05:29:56 2009
@@ -18,7 +18,6 @@
 
 import java.io.Serializable;
 import java.util.Collection;
-import java.util.Iterator;
 
 import org.apache.commons.collections.Transformer;
 
@@ -33,13 +32,13 @@
  *
  * @author Stephen Colebourne
  */
-public class ChainedTransformer implements Transformer, Serializable {
+public class ChainedTransformer<T> implements Transformer<T, T>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 3514945074733160196L;
 
     /** The transformers to call in turn */
-    private final Transformer[] iTransformers;
+    private final Transformer<? super T, ? extends T>[] iTransformers;
 
     /**
      * Factory method that performs validation and copies the parameter array.
@@ -49,13 +48,13 @@
      * @throws IllegalArgumentException if the transformers array is null
      * @throws IllegalArgumentException if any transformer in the array is null
      */
-    public static Transformer getInstance(Transformer[] transformers) {
+    public static <T> Transformer<T, T> getInstance(Transformer<? super T, ? extends T>[] transformers) {
         FunctorUtils.validate(transformers);
         if (transformers.length == 0) {
-            return NOPTransformer.INSTANCE;
+            return NOPTransformer.<T>getInstance();
         }
         transformers = FunctorUtils.copy(transformers);
-        return new ChainedTransformer(transformers);
+        return new ChainedTransformer<T>(transformers);
     }
     
     /**
@@ -68,21 +67,18 @@
      * @throws IllegalArgumentException if the transformers collection is null
      * @throws IllegalArgumentException if any transformer in the collection is null
      */
-    public static Transformer getInstance(Collection transformers) {
+    @SuppressWarnings("unchecked")
+    public static <T> Transformer<T, T> getInstance(Collection<? extends Transformer<T, T>> transformers) {
         if (transformers == null) {
             throw new IllegalArgumentException("Transformer collection must not be null");
         }
         if (transformers.size() == 0) {
-            return NOPTransformer.INSTANCE;
+            return NOPTransformer.<T>getInstance();
         }
         // convert to array like this to guarantee iterator() ordering
-        Transformer[] cmds = new Transformer[transformers.size()];
-        int i = 0;
-        for (Iterator it = transformers.iterator(); it.hasNext();) {
-            cmds[i++] = (Transformer) it.next();
-        }
+        Transformer<T, T>[] cmds = transformers.toArray(new Transformer[transformers.size()]);
         FunctorUtils.validate(cmds);
-        return new ChainedTransformer(cmds);
+        return new ChainedTransformer<T>(cmds);
     }
 
     /**
@@ -93,12 +89,13 @@
      * @return the <code>chained</code> transformer
      * @throws IllegalArgumentException if either transformer is null
      */
-    public static Transformer getInstance(Transformer transformer1, Transformer transformer2) {
+    @SuppressWarnings("unchecked")
+    public static <T> Transformer<T, T> getInstance(Transformer<? super T, ? extends T> transformer1, Transformer<? super T, ? extends T> transformer2) {
         if (transformer1 == null || transformer2 == null) {
             throw new IllegalArgumentException("Transformers must not be null");
         }
-        Transformer[] transformers = new Transformer[] { transformer1, transformer2 };
-        return new ChainedTransformer(transformers);
+        Transformer<? super T, ? extends T>[] transformers = new Transformer[] { transformer1, transformer2 };
+        return new ChainedTransformer<T>(transformers);
     }
 
     /**
@@ -107,7 +104,7 @@
      * 
      * @param transformers  the transformers to chain, not copied, no nulls
      */
-    public ChainedTransformer(Transformer[] transformers) {
+    public ChainedTransformer(Transformer<? super T, ? extends T>[] transformers) {
         super();
         iTransformers = transformers;
     }
@@ -118,7 +115,7 @@
      * @param object  the input object passed to the first transformer
      * @return the transformed result
      */
-    public Object transform(Object object) {
+    public T transform(T object) {
         for (int i = 0; i < iTransformers.length; i++) {
             object = iTransformers[i].transform(object);
         }
@@ -130,7 +127,7 @@
      * @return the transformers
      * @since Commons Collections 3.1
      */
-    public Transformer[] getTransformers() {
+    public Transformer<? super T, ? extends T>[] getTransformers() {
         return iTransformers;
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/CloneTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/CloneTransformer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/CloneTransformer.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/CloneTransformer.java Tue Sep 15 05:29:56 2009
@@ -30,13 +30,13 @@
  *
  * @author Stephen Colebourne
  */
-public class CloneTransformer implements Transformer, Serializable {
+public class CloneTransformer<T> implements Transformer<T, T>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = -8188742709499652567L;
 
     /** Singleton predicate instance */
-    public static final Transformer INSTANCE = new CloneTransformer();
+    public static final Transformer<Object, Object> INSTANCE = new CloneTransformer<Object>();
 
     /**
      * Factory returning the singleton instance.
@@ -44,8 +44,9 @@
      * @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;
     }
 
     /**
@@ -61,7 +62,7 @@
      * @param input  the input object to transform
      * @return the transformed result
      */
-    public Object transform(Object input) {
+    public T transform(T input) {
         if (input == null) {
             return null;
         }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ClosureTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ClosureTransformer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ClosureTransformer.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ClosureTransformer.java Tue Sep 15 05:29:56 2009
@@ -30,13 +30,13 @@
  *
  * @author Stephen Colebourne
  */
-public class ClosureTransformer implements Transformer, Serializable {
+public class ClosureTransformer<T> implements Transformer<T, T>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 478466901448617286L;
 
     /** The closure to wrap */
-    private final Closure iClosure;
+    private final Closure<? super T> iClosure;
 
     /**
      * Factory method that performs validation.
@@ -45,11 +45,11 @@
      * @return the <code>closure</code> transformer
      * @throws IllegalArgumentException if the closure is null
      */
-    public static Transformer getInstance(Closure closure) {
+    public static <T> Transformer<T, T> getInstance(Closure<? super T> closure) {
         if (closure == null) {
             throw new IllegalArgumentException("Closure must not be null");
         }
-        return new ClosureTransformer(closure);
+        return new ClosureTransformer<T>(closure);
     }
 
     /**
@@ -58,7 +58,7 @@
      * 
      * @param closure  the closure to call, not null
      */
-    public ClosureTransformer(Closure closure) {
+    public ClosureTransformer(Closure<? super T> closure) {
         super();
         iClosure = closure;
     }
@@ -69,7 +69,7 @@
      * @param input  the input object to transform
      * @return the transformed result
      */
-    public Object transform(Object input) {
+    public T transform(T input) {
         iClosure.execute(input);
         return input;
     }
@@ -80,7 +80,7 @@
      * @return the closure
      * @since Commons Collections 3.1
      */
-    public Closure getClosure() {
+    public Closure<? super T> getClosure() {
         return iClosure;
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ConstantFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ConstantFactory.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ConstantFactory.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ConstantFactory.java Tue Sep 15 05:29:56 2009
@@ -32,16 +32,16 @@
  *
  * @author Stephen Colebourne
  */
-public class ConstantFactory implements Factory, Serializable {
+public class ConstantFactory<T> implements Factory<T>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = -3520677225766901240L;
     
     /** Returns null each time */
-    public static final Factory NULL_INSTANCE = new ConstantFactory(null);
+    public static final Factory<Object> NULL_INSTANCE = new ConstantFactory<Object>(null);
 
     /** The closures to call in turn */
-    private final Object iConstant;
+    private final T iConstant;
 
     /**
      * Factory method that performs validation.
@@ -49,11 +49,12 @@
      * @param constantToReturn  the constant object to return each time in the factory
      * @return the <code>constant</code> factory.
      */
-    public static Factory getInstance(Object constantToReturn) {
+    @SuppressWarnings("unchecked")
+    public static <T> Factory<T> getInstance(T constantToReturn) {
         if (constantToReturn == null) {
-            return NULL_INSTANCE;
+            return (Factory<T>) NULL_INSTANCE;
         }
-        return new ConstantFactory(constantToReturn);
+        return new ConstantFactory<T>(constantToReturn);
     }
     
     /**
@@ -62,7 +63,7 @@
      * 
      * @param constantToReturn  the constant to return each time
      */
-    public ConstantFactory(Object constantToReturn) {
+    public ConstantFactory(T constantToReturn) {
         super();
         iConstant = constantToReturn;
     }
@@ -72,7 +73,7 @@
      * 
      * @return the stored constant value
      */
-    public Object create() {
+    public T create() {
         return iConstant;
     }
 
@@ -82,7 +83,7 @@
      * @return the constant
      * @since Commons Collections 3.1
      */
-    public Object getConstant() {
+    public T getConstant() {
         return iConstant;
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ConstantTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ConstantTransformer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ConstantTransformer.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ConstantTransformer.java Tue Sep 15 05:29:56 2009
@@ -32,16 +32,27 @@
  *
  * @author Stephen Colebourne
  */
-public class ConstantTransformer implements Transformer, Serializable {
+public class ConstantTransformer<I, O> implements Transformer<I, O>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 6374440726369055124L;
     
     /** Returns null each time */
-    public static final Transformer NULL_INSTANCE = new ConstantTransformer(null);
+    public static final Transformer<Object, Object> NULL_INSTANCE = new ConstantTransformer<Object, Object>(null);
 
     /** The closures to call in turn */
-    private final Object iConstant;
+    private final O iConstant;
+
+    /**
+     * Get a typed null instance.
+     * @param <I>
+     * @param <O>
+     * @return Transformer<I, O> that always returns null.
+     */
+    @SuppressWarnings("unchecked")
+    public static <I, O> Transformer<I, O> getNullInstance() {
+        return (Transformer<I, O>) NULL_INSTANCE;
+    }
 
     /**
      * Transformer method that performs validation.
@@ -49,11 +60,11 @@
      * @param constantToReturn  the constant object to return each time in the factory
      * @return the <code>constant</code> factory.
      */
-    public static Transformer getInstance(Object constantToReturn) {
+    public static <I, O> Transformer<I, O> getInstance(O constantToReturn) {
         if (constantToReturn == null) {
-            return NULL_INSTANCE;
+            return getNullInstance();
         }
-        return new ConstantTransformer(constantToReturn);
+        return new ConstantTransformer<I, O>(constantToReturn);
     }
     
     /**
@@ -62,7 +73,7 @@
      * 
      * @param constantToReturn  the constant to return each time
      */
-    public ConstantTransformer(Object constantToReturn) {
+    public ConstantTransformer(O constantToReturn) {
         super();
         iConstant = constantToReturn;
     }
@@ -73,7 +84,7 @@
      * @param input  the input object which is ignored
      * @return the stored constant
      */
-    public Object transform(Object input) {
+    public O transform(I input) {
         return iConstant;
     }
 
@@ -83,8 +94,34 @@
      * @return the constant
      * @since Commons Collections 3.1
      */
-    public Object getConstant() {
+    public O getConstant() {
         return iConstant;
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        if (obj instanceof ConstantTransformer == false) {
+            return false;
+        }
+        Object otherConstant = ((ConstantTransformer<?, ?>) obj).getConstant();
+        return otherConstant == getConstant() || otherConstant != null && otherConstant.equals(getConstant());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode() {
+        int result = "ConstantTransformer".hashCode() << 2;
+        if (getConstant() != null) {
+            result |= getConstant().hashCode();
+        }
+        return result;
+    }
 }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ExceptionClosure.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ExceptionClosure.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ExceptionClosure.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ExceptionClosure.java Tue Sep 15 05:29:56 2009
@@ -29,14 +29,13 @@
  *
  * @author Stephen Colebourne
  */
-public final class ExceptionClosure implements Closure, Serializable {
+public final class ExceptionClosure<E> implements Closure<E>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 7179106032121985545L;
-    
 
     /** Singleton predicate instance */
-    public static final Closure INSTANCE = new ExceptionClosure();
+    public static final Closure<Object> INSTANCE = new ExceptionClosure<Object>();
 
     /**
      * Factory returning the singleton instance.
@@ -44,8 +43,9 @@
      * @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;
     }
 
     /**
@@ -61,7 +61,7 @@
      * @param input  the input object
      * @throws FunctorException always
      */
-    public void execute(Object input) {
+    public void execute(E input) {
         throw new FunctorException("ExceptionClosure invoked");
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ExceptionFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ExceptionFactory.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ExceptionFactory.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ExceptionFactory.java Tue Sep 15 05:29:56 2009
@@ -29,14 +29,13 @@
  *
  * @author Stephen Colebourne
  */
-public final class ExceptionFactory implements Factory, Serializable {
+public final class ExceptionFactory<T> implements Factory<T>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 7179106032121985545L;
-    
 
     /** Singleton predicate instance */
-    public static final Factory INSTANCE = new ExceptionFactory();
+    public static final Factory<Object> INSTANCE = new ExceptionFactory<Object>();
 
     /**
      * Factory returning the singleton instance.
@@ -44,8 +43,9 @@
      * @return the singleton instance
      * @since Commons Collections 3.1
      */
-    public static Factory getInstance() {
-        return INSTANCE;
+    @SuppressWarnings("unchecked")
+    public static <T> Factory<T> getInstance() {
+        return (Factory<T>) INSTANCE;
     }
 
     /**
@@ -61,7 +61,7 @@
      * @return never
      * @throws FunctorException always
      */
-    public Object create() {
+    public T create() {
         throw new FunctorException("ExceptionFactory invoked");
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ExceptionPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ExceptionPredicate.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ExceptionPredicate.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ExceptionPredicate.java Tue Sep 15 05:29:56 2009
@@ -29,22 +29,23 @@
  *
  * @author Stephen Colebourne
  */
-public final class ExceptionPredicate implements Predicate, Serializable {
+public final class ExceptionPredicate<T> implements Predicate<T>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 7179106032121985545L;
-    
+
     /** Singleton predicate instance */
-    public static final Predicate INSTANCE = new ExceptionPredicate();
+    public static final Predicate<Object> INSTANCE = new ExceptionPredicate<Object>();
 
     /**
      * Factory returning the singleton instance.
-     * 
+     *
      * @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;
     }
 
     /**
@@ -56,13 +57,13 @@
 
     /**
      * Evaluates the predicate always throwing an exception.
-     * 
+     *
      * @param object  the input object
      * @return never
      * @throws FunctorException always
      */
-    public boolean evaluate(Object object) {
+    public boolean evaluate(T object) {
         throw new FunctorException("ExceptionPredicate invoked");
     }
-    
+
 }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ExceptionTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ExceptionTransformer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ExceptionTransformer.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ExceptionTransformer.java Tue Sep 15 05:29:56 2009
@@ -29,23 +29,23 @@
  *
  * @author Stephen Colebourne
  */
-public final class ExceptionTransformer implements Transformer, Serializable {
+public final class ExceptionTransformer<I, O> implements Transformer<I, O>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 7179106032121985545L;
-    
 
     /** Singleton predicate instance */
-    public static final Transformer INSTANCE = new ExceptionTransformer();
+    public static final Transformer<Object, Object> INSTANCE = new ExceptionTransformer<Object, Object>();
 
     /**
      * Factory returning the singleton instance.
-     * 
+     *
      * @return the singleton instance
      * @since Commons Collections 3.1
      */
-    public static Transformer getInstance() {
-        return INSTANCE;
+    @SuppressWarnings("unchecked")
+    public static <I, O> Transformer<I, O> getInstance() {
+        return (Transformer<I, O>) INSTANCE;
     }
 
     /**
@@ -57,12 +57,12 @@
 
     /**
      * Transforms the input to result by cloning it.
-     * 
+     *
      * @param input  the input object to transform
      * @return never
      * @throws FunctorException always
      */
-    public Object transform(Object input) {
+    public O transform(I input) {
         throw new FunctorException("ExceptionTransformer invoked");
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/FactoryTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/FactoryTransformer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/FactoryTransformer.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/FactoryTransformer.java Tue Sep 15 05:29:56 2009
@@ -29,13 +29,13 @@
  *
  * @author Stephen Colebourne
  */
-public class FactoryTransformer implements Transformer, Serializable {
+public class FactoryTransformer<I, O> implements Transformer<I, O>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = -6817674502475353160L;
 
     /** The factory to wrap */
-    private final Factory iFactory;
+    private final Factory<? extends O> iFactory;
 
     /**
      * Factory method that performs validation.
@@ -44,11 +44,11 @@
      * @return the <code>factory</code> transformer
      * @throws IllegalArgumentException if the factory is null
      */
-    public static Transformer getInstance(Factory factory) {
+    public static <I, O> Transformer<I, O> getInstance(Factory<? extends O> factory) {
         if (factory == null) {
             throw new IllegalArgumentException("Factory must not be null");
         }
-        return new FactoryTransformer(factory);
+        return new FactoryTransformer<I, O>(factory);
     }
 
     /**
@@ -57,7 +57,7 @@
      * 
      * @param factory  the factory to call, not null
      */
-    public FactoryTransformer(Factory factory) {
+    public FactoryTransformer(Factory<? extends O> factory) {
         super();
         iFactory = factory;
     }
@@ -69,7 +69,7 @@
      * @param input  the input object to transform
      * @return the transformed result
      */
-    public Object transform(Object input) {
+    public O transform(I input) {
         return iFactory.create();
     }
 
@@ -79,7 +79,7 @@
      * @return the factory
      * @since Commons Collections 3.1
      */
-    public Factory getFactory() {
+    public Factory<? extends O> getFactory() {
         return iFactory;
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/FalsePredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/FalsePredicate.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/FalsePredicate.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/FalsePredicate.java Tue Sep 15 05:29:56 2009
@@ -28,22 +28,34 @@
  *
  * @author Stephen Colebourne
  */
-public final class FalsePredicate implements Predicate, Serializable {
+public final class FalsePredicate<T> implements Predicate<T>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 7533784454832764388L;
-    
+
     /** Singleton predicate instance */
-    public static final Predicate INSTANCE = new FalsePredicate();
+    public static final Predicate<Object> INSTANCE = new FalsePredicate<Object>();
 
     /**
-     * Factory returning the singleton instance.
-     * 
+     * Get a typed instance.
+     *
      * @return the singleton instance
      * @since Commons Collections 3.1
+     * @deprecated use {@link #falsePredicate()} instead.
+     */
+    public static <T> Predicate<T> getInstance() {
+        return FalsePredicate.<T>falsePredicate();
+    }
+
+    /**
+     * Get a typed instance.
+     *
+     * @return the singleton instance
+     * @since Commons Collections 5
      */
-    public static Predicate getInstance() {
-        return INSTANCE;
+    @SuppressWarnings("unchecked")
+    public static <T> Predicate<T> falsePredicate() {
+        return (Predicate<T>) INSTANCE;
     }
 
     /**
@@ -55,11 +67,11 @@
 
     /**
      * Evaluates the predicate returning false always.
-     * 
+     *
      * @param object  the input object
      * @return false always
      */
-    public boolean evaluate(Object object) {
+    public boolean evaluate(T object) {
         return false;
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ForClosure.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ForClosure.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ForClosure.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ForClosure.java Tue Sep 15 05:29:56 2009
@@ -28,7 +28,7 @@
  *
  * @author Stephen Colebourne
  */
-public class ForClosure implements Closure, Serializable {
+public class ForClosure<E> implements Closure<E>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = -1190120533393621674L;
@@ -36,7 +36,7 @@
     /** The number of times to loop */
     private final int iCount;
     /** The closure to call */
-    private final Closure iClosure;
+    private final Closure<? super E> iClosure;
 
     /**
      * Factory method that performs validation.
@@ -48,14 +48,15 @@
      * @param closure  the closure to execute, not null
      * @return the <code>for</code> closure
      */
-    public static Closure getInstance(int count, Closure closure) {
+    @SuppressWarnings("unchecked")
+    public static <E> Closure<E> getInstance(int count, Closure<? super E> closure) {
         if (count <= 0 || closure == null) {
-            return NOPClosure.INSTANCE;
+            return NOPClosure.<E>getInstance();
         }
         if (count == 1) {
-            return closure;
+            return (Closure<E>) closure;
         }
-        return new ForClosure(count, closure);
+        return new ForClosure<E>(count, closure);
     }
 
     /**
@@ -65,7 +66,7 @@
      * @param count  the number of times to execute the closure
      * @param closure  the closure to execute, not null
      */
-    public ForClosure(int count, Closure closure) {
+    public ForClosure(int count, Closure<? super E> closure) {
         super();
         iCount = count;
         iClosure = closure;
@@ -76,7 +77,7 @@
      * 
      * @param input  the input object
      */
-    public void execute(Object input) {
+    public void execute(E input) {
         for (int i = 0; i < iCount; i++) {
             iClosure.execute(input);
         }
@@ -88,7 +89,7 @@
      * @return the closure
      * @since Commons Collections 3.1
      */
-    public Closure getClosure() {
+    public Closure<? super E> getClosure() {
         return iClosure;
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/IdentityPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/IdentityPredicate.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/IdentityPredicate.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/IdentityPredicate.java Tue Sep 15 05:29:56 2009
@@ -29,36 +29,35 @@
  *
  * @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 @@
     /**
      * 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;
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/IfClosure.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/IfClosure.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/IfClosure.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/IfClosure.java Tue Sep 15 05:29:56 2009
@@ -31,17 +31,17 @@
  * @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 @@
      * @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 @@
      * @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 @@
      * @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 @@
      * @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 @@
      * 
      * @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 @@
      * @return the predicate
      * @since Commons Collections 3.1
      */
-    public Predicate getPredicate() {
+    public Predicate<? super E> getPredicate() {
         return iPredicate;
     }
 
@@ -137,7 +137,7 @@
      * @return the closure
      * @since Commons Collections 3.1
      */
-    public Closure getTrueClosure() {
+    public Closure<? super E> getTrueClosure() {
         return iTrueClosure;
     }
 
@@ -147,7 +147,7 @@
      * @return the closure
      * @since Commons Collections 3.1
      */
-    public Closure getFalseClosure() {
+    public Closure<? super E> getFalseClosure() {
         return iFalseClosure;
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/InstanceofPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/InstanceofPredicate.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/InstanceofPredicate.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/InstanceofPredicate.java Tue Sep 15 05:29:56 2009
@@ -29,22 +29,22 @@
  *
  * @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 @@
     /**
      * 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 @@
 
     /**
      * Gets the type to compare to.
-     * 
+     *
      * @return the type
      * @since Commons Collections 3.1
      */
-    public Class getType() {
+    public Class<?> getType() {
         return iType;
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/InstantiateTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/InstantiateTransformer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/InstantiateTransformer.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/InstantiateTransformer.java Tue Sep 15 05:29:56 2009
@@ -31,27 +31,36 @@
  *
  * @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 @@
         }
 
         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 @@
     /**
      * 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 @@
 
     /**
      * 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) {

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/InvokerTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/InvokerTransformer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/InvokerTransformer.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/InvokerTransformer.java Tue Sep 15 05:29:56 2009
@@ -31,7 +31,7 @@
  *
  * @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 @@
     /** 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 @@
      * @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 @@
      * @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 @@
             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 @@
      * @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 @@
      * @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) {

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/MapTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/MapTransformer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/MapTransformer.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/MapTransformer.java Tue Sep 15 05:29:56 2009
@@ -30,57 +30,57 @@
  *
  * @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;
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPClosure.java Tue Sep 15 05:29:56 2009
@@ -28,13 +28,13 @@
  *
  * @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 @@
      * @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 @@
      * 
      * @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);
+    }
 }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPTransformer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPTransformer.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NOPTransformer.java Tue Sep 15 05:29:56 2009
@@ -28,13 +28,13 @@
  *
  * @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 @@
      * @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 @@
      * @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;
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NonePredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NonePredicate.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NonePredicate.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NonePredicate.java Tue Sep 15 05:29:56 2009
@@ -35,14 +35,14 @@
  * @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 @@
      * @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 @@
      * @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 @@
 
     /**
      * 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;
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NotNullPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NotNullPredicate.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NotNullPredicate.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NotNullPredicate.java Tue Sep 15 05:29:56 2009
@@ -28,13 +28,13 @@
  *
  * @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 @@
      * @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 @@
      * @param object  the object to evaluate
      * @return true if not null
      */
-    public boolean evaluate(Object object) {
+    public boolean evaluate(T object) {
         return (object != null);
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NotPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NotPredicate.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NotPredicate.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NotPredicate.java Tue Sep 15 05:29:56 2009
@@ -28,13 +28,13 @@
  *
  * @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 @@
      * @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 @@
      * 
      * @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 @@
      * @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 @@
      * @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};
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NullIsExceptionPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NullIsExceptionPredicate.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NullIsExceptionPredicate.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NullIsExceptionPredicate.java Tue Sep 15 05:29:56 2009
@@ -29,13 +29,13 @@
  *
  * @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 @@
      * @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 @@
      * 
      * @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 @@
      * @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 @@
      * @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 };
     }
 
 }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NullIsFalsePredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NullIsFalsePredicate.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NullIsFalsePredicate.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NullIsFalsePredicate.java Tue Sep 15 05:29:56 2009
@@ -28,35 +28,35 @@
  *
  * @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 @@
     /**
      * 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 @@
 
     /**
      * 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 };
     }
 
 }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NullIsTruePredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NullIsTruePredicate.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NullIsTruePredicate.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/NullIsTruePredicate.java Tue Sep 15 05:29:56 2009
@@ -28,13 +28,13 @@
  *
  * @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 @@
      * @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 @@
      * 
      * @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 @@
      * @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 @@
      * @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 };
     }
 
 }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/OnePredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/OnePredicate.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/OnePredicate.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/OnePredicate.java Tue Sep 15 05:29:56 2009
@@ -35,13 +35,13 @@
  * @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 @@
      * @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 @@
      * @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 @@
      * 
      * @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 @@
      * @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 @@
      * @return the predicates
      * @since Commons Collections 3.1
      */
-    public Predicate[] getPredicates() {
+    public Predicate<? super T>[] getPredicates() {
         return iPredicates;
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/OrPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/OrPredicate.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/OrPredicate.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/OrPredicate.java Tue Sep 15 05:29:56 2009
@@ -28,39 +28,39 @@
  *
  * @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 @@
 
     /**
      * 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};
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/PredicateTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/PredicateTransformer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/PredicateTransformer.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/PredicateTransformer.java Tue Sep 15 05:29:56 2009
@@ -30,13 +30,13 @@
  *
  * @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 @@
      * @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 @@
      * 
      * @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 @@
      * @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 @@
      * @return the predicate
      * @since Commons Collections 3.1
      */
-    public Predicate getPredicate() {
+    public Predicate<? super T> getPredicate() {
         return iPredicate;
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/PrototypeFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/PrototypeFactory.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/PrototypeFactory.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/PrototypeFactory.java Tue Sep 15 05:29:56 2009
@@ -55,22 +55,22 @@
      * @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 @@
     /**
      * 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 @@
         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 @@
          * 
          * @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 @@
     /**
      * 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 @@
          * 
          * @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 @@
 
                 bais = new ByteArrayInputStream(baos.toByteArray());
                 ObjectInputStream in = new ObjectInputStream(bais);
-                return in.readObject();
+                return (T) in.readObject();
 
             } catch (ClassNotFoundException ex) {
                 throw new FunctorException(ex);

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/StringValueTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/StringValueTransformer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/StringValueTransformer.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/StringValueTransformer.java Tue Sep 15 05:29:56 2009
@@ -29,13 +29,13 @@
  *
  * @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 @@
      * @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 @@
      * @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);
     }
 



Mime
View raw message