commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r665786 [3/6] - in /commons/sandbox/functor/trunk/src: main/java/org/apache/commons/functor/adapter/ main/java/org/apache/commons/functor/core/ main/java/org/apache/commons/functor/core/algorithm/ main/java/org/apache/commons/functor/core/c...
Date Mon, 09 Jun 2008 17:17:43 GMT
Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/ComparatorFunction.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/ComparatorFunction.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/ComparatorFunction.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/ComparatorFunction.java Mon Jun  9 10:17:39 2008
@@ -28,28 +28,27 @@
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
-public final class ComparatorFunction implements BinaryFunction, Serializable {
-    private Comparator comparator = null;
+public final class ComparatorFunction<T> implements BinaryFunction<T, T, Integer>, Serializable {
+    private static final ComparatorFunction<Comparable<?>> INSTANCE = new ComparatorFunction<Comparable<?>>(
+            ComparableComparator.instance());
 
-    /**
-     * Create a new ComparatorFunction.
-     */
-    public ComparatorFunction() {
-        this(null);
-    }
+    private Comparator<? super T> comparator = null;
 
     /**
      * Create a new ComparatorFunction.
      * @param comparator to wrap
      */
-    public ComparatorFunction(Comparator comparator) {
-        this.comparator = null == comparator ? ComparableComparator.instance() : comparator;
+    public ComparatorFunction(Comparator<? super T> comparator) {
+        if (comparator == null) {
+            throw new IllegalArgumentException("Comparator must not be null");
+        }
+        this.comparator = comparator;
     }
 
     /**
      * {@inheritDoc}
      */
-    public Object evaluate(Object left, Object right) {
+    public Integer evaluate(T left, T right) {
         return new Integer(comparator.compare(left, right));
     }
 
@@ -57,7 +56,7 @@
      * {@inheritDoc}
      */
     public boolean equals(Object that) {
-        return that == this || (that instanceof ComparatorFunction && equals((ComparatorFunction) that));
+        return that == this || (that instanceof ComparatorFunction && equals((ComparatorFunction<?>) that));
     }
 
     /**
@@ -65,7 +64,7 @@
      * @param that the ComparatorFunction to test
      * @return boolean
      */
-    public boolean equals(ComparatorFunction that) {
+    public boolean equals(ComparatorFunction<?> that) {
         return null != that && comparator.equals(that.comparator);
     }
 
@@ -83,4 +82,11 @@
         return "ComparatorFunction<" + comparator + ">";
     }
 
+    /**
+     * Get a basic ComparatorFunction instance.
+     * @return ComparatorFunction
+     */
+    public static ComparatorFunction<Comparable<?>> instance() {
+        return INSTANCE;
+    }
 }

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsEquivalent.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsEquivalent.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsEquivalent.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsEquivalent.java Mon Jun  9 10:17:39 2008
@@ -36,18 +36,11 @@
  * @author Rodney Waldhoff
  *
  */
-public final class IsEquivalent implements BinaryPredicate, Serializable {
-    private static final IsEquivalent COMPARABLE_INSTANCE = new IsEquivalent();
+public final class IsEquivalent<T> implements BinaryPredicate<T, T>, Serializable {
+    private static final IsEquivalent<Comparable<?>> COMPARABLE_INSTANCE = new IsEquivalent<Comparable<?>>(
+            ComparableComparator.instance());
 
-    private Comparator comparator = null;
-
-    /**
-     * Construct an <code>IsEquivalent</code> {@link BinaryPredicate predicate}
-     * for {@link Comparable Comparable}s.
-     */
-    public IsEquivalent() {
-        this(null);
-    }
+    private Comparator<? super T> comparator;
 
     /**
      * Construct an <code>IsEquivalent</code> {@link BinaryPredicate predicate}
@@ -57,8 +50,11 @@
      *        a <code>Comparator</code> for {@link Comparable Comparable}s will
      *        be used.
      */
-    public IsEquivalent(Comparator comparator) {
-        this.comparator = null == comparator ? ComparableComparator.instance() : comparator;
+    public IsEquivalent(Comparator<? super T> comparator) {
+        if (comparator == null) {
+            throw new IllegalArgumentException("Comparator must not be null");
+        }
+        this.comparator = comparator;
     }
 
     /**
@@ -67,7 +63,7 @@
      * {@link Comparator Comparator}.
      * {@inheritDoc}
      */
-    public boolean test(Object left, Object right) {
+    public boolean test(T left, T right) {
         return comparator.compare(left, right) == 0;
     }
 
@@ -75,7 +71,7 @@
      * {@inheritDoc}
      */
     public boolean equals(Object that) {
-        return that == this || (that instanceof IsEquivalent && equals((IsEquivalent) that));
+        return that == this || (that instanceof IsEquivalent && equals((IsEquivalent<?>) that));
     }
 
     /**
@@ -83,7 +79,7 @@
      * @param that IsEquivalent to test
      * @return boolean
      */
-    public boolean equals(IsEquivalent that) {
+    public boolean equals(IsEquivalent<?> that) {
         return null != that && null == comparator ? null == that.comparator : comparator.equals(that.comparator);
     }
 
@@ -108,7 +104,7 @@
      * Get a basic IsEquivalent instance.
      * @return IsEquivalent
      */
-    public static final IsEquivalent instance() {
+    public static final IsEquivalent<Comparable<?>> instance() {
         return COMPARABLE_INSTANCE;
     }
 
@@ -117,7 +113,7 @@
      * @param right argument
      * @return UnaryPredicate
      */
-    public static final UnaryPredicate instance(Comparable right) {
+    public static final UnaryPredicate<Comparable<?>> instance(Comparable<?> right) {
         return RightBoundPredicate.bind(instance(), right);
     }
 

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThan.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThan.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThan.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThan.java Mon Jun  9 10:17:39 2008
@@ -33,17 +33,21 @@
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
-public final class IsGreaterThan implements BinaryPredicate, Serializable {
-    private static final IsGreaterThan COMPARABLE_INSTANCE = new IsGreaterThan();
+public final class IsGreaterThan<T> implements BinaryPredicate<T, T>, Serializable {
+    /**
+     * Basic IsGreaterThan instance.
+     */
+    public static final IsGreaterThan<Comparable<?>> INSTANCE = IsGreaterThan.<Comparable<?>>instance();
 
-    private Comparator comparator = null;
+    private Comparator<? super T> comparator = null;
 
     /**
      * Construct a <code>IsGreaterThan</code> {@link BinaryPredicate predicate}
      * for {@link Comparable Comparable}s.
      */
+    @SuppressWarnings("unchecked")
     public IsGreaterThan() {
-        this(null);
+        this(ComparableComparator.INSTANCE);
     }
 
     /**
@@ -54,8 +58,11 @@
      *        a <code>Comparator</code> for {@link Comparable Comparable}s will
      *        be used.
      */
-    public IsGreaterThan(Comparator comparator) {
-        this.comparator = null == comparator ? ComparableComparator.instance() : comparator;
+    public IsGreaterThan(Comparator<? super T> comparator) {
+        if (comparator == null) {
+            throw new IllegalArgumentException("Comparator argument must not be null");
+        }
+        this.comparator = comparator;
     }
 
     /**
@@ -64,7 +71,7 @@
      * {@link Comparator Comparator}.
      * {@inheritDoc}
      */
-    public boolean test(Object left, Object right) {
+    public boolean test(T left, T right) {
         return comparator.compare(left, right) > 0;
     }
 
@@ -72,7 +79,7 @@
      * {@inheritDoc}
      */
     public boolean equals(Object that) {
-        return that == this || (that instanceof IsGreaterThan && equals((IsGreaterThan) that));
+        return that == this || (that instanceof IsGreaterThan && equals((IsGreaterThan<?>) that));
     }
 
     /**
@@ -80,7 +87,7 @@
      * @param that the IsGreaterThan to test
      * @return boolean
      */
-    public boolean equals(IsGreaterThan that) {
+    public boolean equals(IsGreaterThan<?> that) {
         return null != that && null == comparator ? null == that.comparator : comparator.equals(that.comparator);
     }
 
@@ -102,20 +109,21 @@
     }
 
     /**
-     * Get a basic IsGreaterThan instance.
-     * @return IsGreaterThan
+     * Get a typed IsGreaterThan instance.
+     * @param <T>
+     * @return IsGreaterThan<T>
      */
-    public static final IsGreaterThan instance() {
-        return COMPARABLE_INSTANCE;
+    public static final <T extends Comparable<?>> IsGreaterThan<T> instance() {
+        return new IsGreaterThan<T>();
     }
 
     /**
      * Get an IsGreaterThan UnaryPredicate.
      * @param right the right side object of the IsGreaterThan comparison
-     * @return UnaryPredicate
+     * @return UnaryPredicate<T>
      */
-    public static final UnaryPredicate instance(Comparable right) {
-        return RightBoundPredicate.bind(instance(), right);
+    public static final <T extends Comparable<?>> UnaryPredicate<T> instance(T right) {
+        return RightBoundPredicate.bind(new IsGreaterThan<T>(), right);
     }
 
 }

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThanOrEqual.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThanOrEqual.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThanOrEqual.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThanOrEqual.java Mon Jun  9 10:17:39 2008
@@ -33,17 +33,22 @@
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
-public final class IsGreaterThanOrEqual implements BinaryPredicate, Serializable {
-    private static final IsGreaterThanOrEqual COMPARABLE_INSTANCE = new IsGreaterThanOrEqual();
+public final class IsGreaterThanOrEqual<T> implements BinaryPredicate<T, T>, Serializable {
+    /**
+     * Basic IsGreaterThanOrEqual instance.
+     */
+    public static final IsGreaterThanOrEqual<Comparable<?>> INSTANCE = IsGreaterThanOrEqual
+            .<Comparable<?>> instance();
 
-    private Comparator comparator = null;
+    private Comparator<? super T> comparator = null;
 
     /**
      * Construct a <code>IsGreaterThanOrEqual</code> {@link BinaryPredicate predicate}
      * for {@link Comparable Comparable}s.
      */
+    @SuppressWarnings("unchecked")
     public IsGreaterThanOrEqual() {
-        this(null);
+        this(ComparableComparator.INSTANCE);
     }
 
     /**
@@ -54,8 +59,11 @@
      *        a <code>Comparator</code> for {@link Comparable Comparable}s will
      *        be used.
      */
-    public IsGreaterThanOrEqual(Comparator comparator) {
-        this.comparator = null == comparator ? ComparableComparator.instance() : comparator;
+    public IsGreaterThanOrEqual(Comparator<? super T> comparator) {
+        if (comparator == null) {
+            throw new IllegalArgumentException("Comparator argument must not be null");
+        }
+        this.comparator = comparator;
     }
 
     /**
@@ -64,7 +72,7 @@
      * {@link Comparator Comparator}.
      * {@inheritDoc}
      */
-    public boolean test(Object left, Object right) {
+    public boolean test(T left, T right) {
         return comparator.compare(left, right) >= 0;
     }
 
@@ -72,7 +80,7 @@
      * {@inheritDoc}
      */
     public boolean equals(Object that) {
-        return that == this || (that instanceof IsGreaterThanOrEqual && equals((IsGreaterThanOrEqual) that));
+        return that == this || (that instanceof IsGreaterThanOrEqual && equals((IsGreaterThanOrEqual<?>) that));
     }
 
     /**
@@ -80,7 +88,7 @@
      * @param that IsGreaterThanOrEqual to test
      * @return boolean
      */
-    public boolean equals(IsGreaterThanOrEqual that) {
+    public boolean equals(IsGreaterThanOrEqual<?> that) {
         return null != that && null == comparator ? null == that.comparator : comparator.equals(that.comparator);
     }
 
@@ -102,11 +110,12 @@
     }
 
     /**
-     * Get a basic IsGreaterThanOrEqual instance.
-     * @return IsGreaterThanOrEqual
+     * Get a typed IsGreaterThanOrEqual instance.
+     * @param <T>
+     * @return IsGreaterThanOrEqual<T>
      */
-    public static final IsGreaterThanOrEqual instance() {
-        return COMPARABLE_INSTANCE;
+    public static final <T extends Comparable<?>> IsGreaterThanOrEqual<T> instance() {
+        return new IsGreaterThanOrEqual<T>();
     }
 
     /**
@@ -114,8 +123,8 @@
      * @param right the right side object of the IsGreaterThanOrEqual comparison
      * @return UnaryPredicate
      */
-    public static final UnaryPredicate instance(Comparable right) {
-        return RightBoundPredicate.bind(instance(), right);
+    public static final <T extends Comparable<?>> UnaryPredicate<T> instance(T right) {
+        return RightBoundPredicate.bind(new IsGreaterThanOrEqual<T>(), right);
     }
 
 }

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsLessThan.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsLessThan.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsLessThan.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsLessThan.java Mon Jun  9 10:17:39 2008
@@ -33,17 +33,21 @@
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
-public final class IsLessThan implements BinaryPredicate, Serializable {
-    private static final IsLessThan COMPARABLE_INSTANCE = new IsLessThan();
+public final class IsLessThan<T> implements BinaryPredicate<T, T>, Serializable {
+    /**
+     * Basic IsLessThan instance.
+     */
+    public static final IsLessThan<Comparable<?>> INSTANCE = IsLessThan.<Comparable<?>>instance();
 
-    private Comparator comparator = null;
+    private Comparator<? super T> comparator = null;
 
     /**
      * Construct a <code>IsLessThan</code> {@link BinaryPredicate predicate}
      * for {@link Comparable Comparable}s.
      */
+    @SuppressWarnings("unchecked")
     public IsLessThan() {
-        this(null);
+        this(ComparableComparator.INSTANCE);
     }
 
     /**
@@ -54,8 +58,11 @@
      *        a <code>Comparator</code> for {@link Comparable Comparable}s will
      *        be used.
      */
-    public IsLessThan(Comparator comparator) {
-        this.comparator = null == comparator ? ComparableComparator.instance() : comparator;
+    public IsLessThan(Comparator<? super T> comparator) {
+        if (comparator == null) {
+            throw new IllegalArgumentException("Comparator argument must not be null");
+        }
+        this.comparator = comparator;
     }
 
     /**
@@ -64,7 +71,7 @@
      * {@link Comparator Comparator}.
      * {@inheritDoc}
      */
-    public boolean test(Object left, Object right) {
+    public boolean test(T left, T right) {
         return comparator.compare(left, right) < 0;
     }
 
@@ -72,7 +79,7 @@
      * {@inheritDoc}
      */
     public boolean equals(Object that) {
-        return that == this || (that instanceof IsLessThan && equals((IsLessThan) that));
+        return that == this || (that instanceof IsLessThan && equals((IsLessThan<?>) that));
     }
 
     /**
@@ -80,7 +87,7 @@
      * @param that IsLessThan to test
      * @return boolean
      */
-    public boolean equals(IsLessThan that) {
+    public boolean equals(IsLessThan<?> that) {
         return null != that && null == comparator ? null == that.comparator : comparator.equals(that.comparator);
     }
 
@@ -102,11 +109,12 @@
     }
 
     /**
-     * Get a basic IsLessThan instance.
-     * @return IsLessThan
+     * Get a typed IsLessThan instance.
+     * @param <T>
+     * @return IsLessThan<T>
      */
-    public static final IsLessThan instance() {
-        return COMPARABLE_INSTANCE;
+    public static final <T extends Comparable<?>> IsLessThan<T> instance() {
+        return new IsLessThan<T>();
     }
 
     /**
@@ -114,8 +122,8 @@
      * @param right the right side object of the comparison.
      * @return UnaryPredicate
      */
-    public static final UnaryPredicate instance(Comparable right) {
-        return RightBoundPredicate.bind(instance(), right);
+    public static final <T extends Comparable<?>> UnaryPredicate<T> instance(T right) {
+        return RightBoundPredicate.bind(new IsLessThan<T>(), right);
     }
 
 }

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsLessThanOrEqual.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsLessThanOrEqual.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsLessThanOrEqual.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsLessThanOrEqual.java Mon Jun  9 10:17:39 2008
@@ -33,17 +33,21 @@
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
-public final class IsLessThanOrEqual implements BinaryPredicate, Serializable {
-    private static final IsLessThanOrEqual COMPARABLE_INSTANCE = new IsLessThanOrEqual();
+public final class IsLessThanOrEqual<T> implements BinaryPredicate<T, T>, Serializable {
+    /**
+     * Basic IsLessThanOrEqual instance.
+     */
+    public static final IsLessThanOrEqual<Comparable<?>> INSTANCE = IsLessThanOrEqual.<Comparable<?>>instance();
 
-    private Comparator comparator = null;
+    private Comparator<? super T> comparator = null;
 
     /**
      * Construct a <code>IsLessThanOrEqual</code> {@link BinaryPredicate predicate}
      * for {@link Comparable Comparable}s.
      */
+    @SuppressWarnings("unchecked")
     public IsLessThanOrEqual() {
-        this(null);
+        this(ComparableComparator.INSTANCE);
     }
 
     /**
@@ -54,8 +58,11 @@
      *        a <code>Comparator</code> for {@link Comparable Comparable}s will
      *        be used.
      */
-    public IsLessThanOrEqual(Comparator comparator) {
-        this.comparator = null == comparator ? ComparableComparator.instance() : comparator;
+    public IsLessThanOrEqual(Comparator<? super T> comparator) {
+        if (comparator == null) {
+            throw new IllegalArgumentException("Comparator argument must not be null");
+        }
+        this.comparator = comparator;
     }
 
     /**
@@ -64,7 +71,7 @@
      * less than or equal to the <i>right</i> parameter under my current
      * {@link Comparator Comparator}.
      */
-    public boolean test(Object left, Object right) {
+    public boolean test(T left, T right) {
         return comparator.compare(left, right) <= 0;
     }
 
@@ -72,7 +79,7 @@
      * {@inheritDoc}
      */
     public boolean equals(Object that) {
-        return that == this || (that instanceof IsLessThanOrEqual && equals((IsLessThanOrEqual) that));
+        return that == this || (that instanceof IsLessThanOrEqual && equals((IsLessThanOrEqual<?>) that));
     }
 
     /**
@@ -80,7 +87,7 @@
      * @param that the IsLessThanOrEqual to test.
      * @return boolean
      */
-    public boolean equals(IsLessThanOrEqual that) {
+    public boolean equals(IsLessThanOrEqual<?> that) {
         return null != that && null == comparator ? null == that.comparator : comparator.equals(that.comparator);
     }
 
@@ -102,11 +109,12 @@
     }
 
     /**
-     * Get a basic IsLessThanOrEqual instance.
-     * @return IsLessThanOrEqual
+     * Get a typed IsLessThanOrEqual instance.
+     * @param <T>
+     * @return IsLessThanOrEqual<T>
      */
-    public static final IsLessThanOrEqual instance() {
-        return COMPARABLE_INSTANCE;
+    public static final <T extends Comparable<?>> IsLessThanOrEqual<T> instance() {
+        return new IsLessThanOrEqual<T>();
     }
 
     /**
@@ -114,8 +122,8 @@
      * @param right the right side object of the comparison.
      * @return UnaryPredicate
      */
-    public static final UnaryPredicate instance(Comparable right) {
-        return RightBoundPredicate.bind(instance(), right);
+    public static final <T extends Comparable<?>> UnaryPredicate<T> instance(T right) {
+        return RightBoundPredicate.bind(new IsLessThanOrEqual<T>(), right);
     }
 
 }

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsNotEquivalent.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsNotEquivalent.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsNotEquivalent.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsNotEquivalent.java Mon Jun  9 10:17:39 2008
@@ -36,17 +36,10 @@
  * @author Rodney Waldhoff
  *
  */
-public final class IsNotEquivalent implements BinaryPredicate, Serializable {
-    private static final IsNotEquivalent COMPARABLE_INSTANCE = new IsNotEquivalent();
+public final class IsNotEquivalent<T> implements BinaryPredicate<T, T>, Serializable {
+    private static final IsNotEquivalent<Comparable<?>> COMPARABLE_INSTANCE = new IsNotEquivalent<Comparable<?>>(ComparableComparator.instance());
 
-    private Comparator comparator = null;
-    /**
-     * Construct a <code>IsNotEquivalent</code> {@link BinaryPredicate predicate}
-     * for {@link Comparable Comparable}s.
-     */
-    public IsNotEquivalent() {
-        this(null);
-    }
+    private Comparator<? super T> comparator = null;
 
     /**
      * Construct a <code>IsNotEquivalent</code> {@link BinaryPredicate predicate}
@@ -56,8 +49,11 @@
      *        a <code>Comparator</code> for {@link Comparable Comparable}s will
      *        be used.
      */
-    public IsNotEquivalent(Comparator comparator) {
-        this.comparator = null == comparator ? ComparableComparator.instance() : comparator;
+    public IsNotEquivalent(Comparator<? super T> comparator) {
+        if (comparator == null) {
+            throw new IllegalArgumentException("Comparator must not be null");
+        }
+        this.comparator = comparator;
     }
 
     /**
@@ -66,7 +62,7 @@
      * not equal to the <i>right</i> parameter under my current
      * {@link Comparator Comparator}.
      */
-    public boolean test(Object left, Object right) {
+    public boolean test(T left, T right) {
         return comparator.compare(left, right) != 0;
     }
 
@@ -74,7 +70,7 @@
      * {@inheritDoc}
      */
     public boolean equals(Object that) {
-        return that == this || (that instanceof IsNotEquivalent && equals((IsNotEquivalent) that));
+        return that == this || (that instanceof IsNotEquivalent && equals((IsNotEquivalent<?>) that));
     }
 
     /**
@@ -82,7 +78,7 @@
      * @param that IsNotEquivalent to test
      * @return boolean
      */
-    public boolean equals(IsNotEquivalent that) {
+    public boolean equals(IsNotEquivalent<?> that) {
         return null != that && null == comparator ? null == that.comparator : comparator.equals(that.comparator);
     }
 
@@ -107,7 +103,7 @@
      * Get an IsNotEquivalent instance.
      * @return IsNotEquivalent
      */
-    public static final IsNotEquivalent instance() {
+    public static final IsNotEquivalent<Comparable<?>> instance() {
         return COMPARABLE_INSTANCE;
     }
 
@@ -116,7 +112,7 @@
      * @param right Comparable against which UnaryPredicate arguments will be compared.
      * @return UnaryPredicate
      */
-    public static final UnaryPredicate instance(Comparable right) {
+    public static final UnaryPredicate<Comparable<?>> instance(Comparable<?> right) {
         return RightBoundPredicate.bind(instance(), right);
     }
 

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsWithinRange.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsWithinRange.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsWithinRange.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsWithinRange.java Mon Jun  9 10:17:39 2008
@@ -28,7 +28,7 @@
  * @author  Jason Horman (jason@jhorman.org)
  */
 
-public class IsWithinRange implements UnaryPredicate, Serializable {
+public class IsWithinRange<A extends Comparable<A>> implements UnaryPredicate<A>, Serializable {
     /** Hashcode of the name of this Predicate. */
     private static final int nameHashCode = "IsWithinRange".hashCode();
 
@@ -37,9 +37,9 @@
      ***************************************************/
 
     /** The minimum value of the range. */
-    private Comparable min = null;
+    private A min = null;
     /** The maximum value of the range. */
-    private Comparable max = null;
+    private A max = null;
 
     /***************************************************
      *  Constructors
@@ -51,15 +51,13 @@
      * @param min Comparable
      * @param max Comparable
      */
-    public IsWithinRange(Comparable min, Comparable max) {
+    public IsWithinRange(A min, A max) {
         if (min == null || max == null) {
             throw new IllegalArgumentException("min and max must not be null");
         }
-
         if (min.compareTo(max) > 0) {
             throw new IllegalArgumentException("min must be <= max");
         }
-
         this.min = min;
         this.max = max;
     }
@@ -72,9 +70,8 @@
      * {@inheritDoc}
      * Test if the passed in object is within the specified range.
      */
-    public boolean test(Object o) {
-        Comparable c = (Comparable) o;
-        return c.compareTo(min) >= 0 && c.compareTo(max) <= 0;
+    public boolean test(A o) {
+        return o.compareTo(min) >= 0 && o.compareTo(max) <= 0;
     }
 
     /**
@@ -87,7 +84,7 @@
         if (!(o instanceof IsWithinRange)) {
             return false;
         }
-        final IsWithinRange isWithinRange = (IsWithinRange) o;
+        final IsWithinRange<?> isWithinRange = (IsWithinRange<?>) o;
         return max.equals(isWithinRange.max) && min.equals(isWithinRange.min);
     }
 

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/Max.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/Max.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/Max.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/Max.java Mon Jun  9 10:17:39 2008
@@ -20,6 +20,8 @@
 import java.util.Comparator;
 
 import org.apache.commons.functor.BinaryFunction;
+import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.adapter.RightBoundFunction;
 
 /**
  * Adapts a {@link Comparator Comparator} to the
@@ -28,30 +30,37 @@
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
-public final class Max implements BinaryFunction, Serializable {
-    private static final Max INSTANCE = new Max();
+public final class Max<T> implements BinaryFunction<T, T, T>, Serializable {
+    /**
+     * Basic Max instance.
+     */
+    public static final Max<Comparable<?>> INSTANCE = Max.<Comparable<?>>instance();
 
-    private Comparator comparator = null;
+    private Comparator<T> comparator = null;
 
     /**
      * Create a new Max.
      */
-    public Max() {
-        this(null);
+    @SuppressWarnings("unchecked")
+    public Max() { 
+        this(ComparableComparator.instance());
     }
 
     /**
      * Create a new Max.
      * @param comparator Comparator to use
      */
-    public Max(Comparator comparator) {
-        this.comparator = null == comparator ? ComparableComparator.instance() : comparator;
+    public Max(Comparator<T> comparator) {
+        if (comparator == null) {
+            throw new IllegalArgumentException("Comparator argument must not be null");
+        }
+        this.comparator = comparator;
     }
 
     /**
      * {@inheritDoc}
      */
-    public Object evaluate(Object left, Object right) {
+    public T evaluate(T left, T right) {
         return (comparator.compare(left, right) >= 0) ? left : right;
     }
 
@@ -59,7 +68,7 @@
      * {@inheritDoc}
      */
     public boolean equals(Object that) {
-        return that == this || (that instanceof Max && equals((Max) that));
+        return that == this || (that instanceof Max && equals((Max<?>) that));
     }
 
     /**
@@ -67,7 +76,7 @@
      * @param that Max to test
      * @return boolean
      */
-    public boolean equals(Max that) {
+    public boolean equals(Max<?> that) {
         return null != that && comparator.equals(that.comparator);
     }
 
@@ -89,8 +98,17 @@
      * Get a Max instance.
      * @return Max
      */
-    public static Max instance() {
-        return INSTANCE;
+    public static <T extends Comparable<?>> Max<T> instance() {
+        return new Max<T>();
+    }
+
+    /**
+     * Get a Max UnaryFunction.
+     * @param right the right side argument of the Max function
+     * @return UnaryFunction<T, T>
+     */
+    public static final <T extends Comparable<?>> UnaryFunction<T, T> instance(T right) {
+        return RightBoundFunction.bind(new Max<T>(), right);
     }
 
 }

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/Min.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/Min.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/Min.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/Min.java Mon Jun  9 10:17:39 2008
@@ -20,6 +20,8 @@
 import java.util.Comparator;
 
 import org.apache.commons.functor.BinaryFunction;
+import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.adapter.RightBoundFunction;
 
 /**
  * Adapts a {@link Comparator Comparator} to the
@@ -28,30 +30,37 @@
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
-public final class Min implements BinaryFunction, Serializable {
-    private static final Min INSTANCE = new Min();
+public final class Min<T> implements BinaryFunction<T, T, T>, Serializable {
+    /**
+     * Basic Min instance.
+     */
+    public static final Min<Comparable<?>> INSTANCE = Min.<Comparable<?>>instance();
 
-    private Comparator comparator = null;
+    private Comparator<T> comparator = null;
 
     /**
      * Create a new Min.
      */
+    @SuppressWarnings("unchecked")
     public Min() {
-        this(null);
+        this(ComparableComparator.instance());
     }
 
     /**
      * Create a new Min.
      * @param comparator to use
      */
-    public Min(Comparator comparator) {
-        this.comparator = null == comparator ? ComparableComparator.instance() : comparator;
+    public Min(Comparator<T> comparator) {
+        if (comparator == null) {
+            throw new IllegalArgumentException("Comparator argument must not be null");
+        }
+        this.comparator = comparator;
     }
 
     /**
      * {@inheritDoc}
      */
-    public Object evaluate(Object left, Object right) {
+    public T evaluate(T left, T right) {
         return (comparator.compare(left, right) <= 0) ? left : right;
     }
 
@@ -59,7 +68,7 @@
      * {@inheritDoc}
      */
     public boolean equals(Object that) {
-        return that == this || (that instanceof Min && equals((Min) that));
+        return that == this || (that instanceof Min && equals((Min<?>) that));
     }
 
     /**
@@ -67,7 +76,7 @@
      * @param that Min to test
      * @return boolean
      */
-    public boolean equals(Min that) {
+    public boolean equals(Min<?> that) {
         return null != that && comparator.equals(that.comparator);
     }
 
@@ -89,8 +98,17 @@
      * Get a basic Min instance.
      * @return Min
      */
-    public static Min instance() {
-        return INSTANCE;
+    public static <T extends Comparable<?>> Min<T> instance() {
+        return new Min<T>();
+    }
+
+    /**
+     * Get a Min UnaryFunction.
+     * @param right the right side argument of the Min function
+     * @return UnaryFunction<T, T>
+     */
+    public static final <T extends Comparable<?>> UnaryFunction<T, T> instance(T right) {
+        return RightBoundFunction.bind(new Min<T>(), right);
     }
 
 }

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BaseBinaryPredicateList.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BaseBinaryPredicateList.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BaseBinaryPredicateList.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BaseBinaryPredicateList.java Mon Jun  9 10:17:39 2008
@@ -37,11 +37,11 @@
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
-abstract class BaseBinaryPredicateList implements BinaryPredicate, Serializable {
+abstract class BaseBinaryPredicateList<L, R> implements BinaryPredicate<L, R>, Serializable {
 
     // attributes
     // ------------------------------------------------------------------------
-    private List list = new ArrayList();
+    private List<BinaryPredicate<? super L, ? super R>> list = new ArrayList<BinaryPredicate<? super L, ? super R>>();
 
     // constructor
     // ------------------------------------------------------------------------
@@ -55,7 +55,7 @@
      * Create a new BaseBinaryPredicateList.
      * @param p BinaryPredicate to add
      */
-    protected BaseBinaryPredicateList(BinaryPredicate p) {
+    protected BaseBinaryPredicateList(BinaryPredicate<? super L, ? super R> p) {
         addBinaryPredicate(p);
     }
 
@@ -64,7 +64,7 @@
      * @param p BinaryPredicate to add
      * @param q BinaryPredicate to add
      */
-    protected BaseBinaryPredicateList(BinaryPredicate p, BinaryPredicate q) {
+    protected BaseBinaryPredicateList(BinaryPredicate<? super L, ? super R> p, BinaryPredicate<? super L, ? super R> q) {
         addBinaryPredicate(p);
         addBinaryPredicate(q);
     }
@@ -75,7 +75,7 @@
      * @param q BinaryPredicate to add
      * @param r BinaryPredicate to add
      */
-    protected BaseBinaryPredicateList(BinaryPredicate p, BinaryPredicate q, BinaryPredicate r) {
+    protected BaseBinaryPredicateList(BinaryPredicate<? super L, ? super R> p, BinaryPredicate<? super L, ? super R> q, BinaryPredicate<? super L, ? super R> r) {
         addBinaryPredicate(p);
         addBinaryPredicate(q);
         addBinaryPredicate(r);
@@ -98,18 +98,13 @@
      */
     public abstract String toString();
 
-    /**
-     * {@inheritDoc}
-     */
-    public abstract boolean test(Object left, Object right);
-
     // modifiers
     // ------------------------------------------------------------------------
     /**
      * Add a BinaryPredicate to the list
      * @param p BinaryPredicate to add
      */
-    protected void addBinaryPredicate(BinaryPredicate p) {
+    protected void addBinaryPredicate(BinaryPredicate<? super L, ? super R> p) {
         list.add(p);
     }
 
@@ -119,7 +114,7 @@
      * Get an Iterator over the list contents.
      * @return Iterator
      */
-    protected Iterator getBinaryPredicateIterator() {
+    protected Iterator<BinaryPredicate<? super L, ? super R>> getBinaryPredicateIterator() {
         return list.iterator();
     }
 
@@ -128,7 +123,7 @@
      * @param that BaseBinaryPredicateList to test
      * @return boolean
      */
-    protected boolean getBinaryPredicateListEquals(BaseBinaryPredicateList that) {
+    protected boolean getBinaryPredicateListEquals(BaseBinaryPredicateList<?, ?> that) {
         return (null != that && this.list.equals(that.list));
     }
 

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BasePredicateList.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BasePredicateList.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BasePredicateList.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BasePredicateList.java Mon Jun  9 10:17:39 2008
@@ -40,7 +40,7 @@
 abstract class BasePredicateList implements Predicate, Serializable {
     // attributes
     // ------------------------------------------------------------------------
-    private List list = new ArrayList();
+    private List<Predicate> list = new ArrayList<Predicate>();
 
     // constructor
     // ------------------------------------------------------------------------
@@ -97,11 +97,6 @@
      */
     public abstract String toString();
 
-    /**
-     * {@inheritDoc}
-     */
-    public abstract boolean test();
-
     // modifiers
     // ------------------------------------------------------------------------
     /**
@@ -118,7 +113,7 @@
      * Get an Iterator over the contents of the list.
      * @return Iterator<Predicate>
      */
-    protected Iterator getPredicateIterator() {
+    protected Iterator<Predicate> getPredicateIterator() {
         return list.iterator();
     }
 

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BaseUnaryPredicateList.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BaseUnaryPredicateList.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BaseUnaryPredicateList.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BaseUnaryPredicateList.java Mon Jun  9 10:17:39 2008
@@ -37,11 +37,11 @@
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
-abstract class BaseUnaryPredicateList implements UnaryPredicate, Serializable {
+abstract class BaseUnaryPredicateList<A> implements UnaryPredicate<A>, Serializable {
 
     // attributes
     // ------------------------------------------------------------------------
-    private List list = new ArrayList();
+    private List<UnaryPredicate<? super A>> list = new ArrayList<UnaryPredicate<? super A>>();
 
     // constructor
     // ------------------------------------------------------------------------
@@ -55,7 +55,7 @@
      * Create a new BaseUnaryPredicateList.
      * @param p single Predicate to add
      */
-    protected BaseUnaryPredicateList(UnaryPredicate p) {
+    protected BaseUnaryPredicateList(UnaryPredicate<? super A> p) {
         addUnaryPredicate(p);
     }
 
@@ -64,7 +64,7 @@
      * @param p Predicate to add
      * @param q Predicate to add
      */
-    protected BaseUnaryPredicateList(UnaryPredicate p, UnaryPredicate q) {
+    protected BaseUnaryPredicateList(UnaryPredicate<? super A> p, UnaryPredicate<? super A> q) {
         addUnaryPredicate(p);
         addUnaryPredicate(q);
     }
@@ -75,7 +75,7 @@
      * @param q Predicate to add
      * @param r Predicate to add
      */
-    protected BaseUnaryPredicateList(UnaryPredicate p, UnaryPredicate q, UnaryPredicate r) {
+    protected BaseUnaryPredicateList(UnaryPredicate<? super A> p, UnaryPredicate<? super A> q, UnaryPredicate<? super A> r) {
         addUnaryPredicate(p);
         addUnaryPredicate(q);
         addUnaryPredicate(r);
@@ -98,18 +98,13 @@
      */
     public abstract String toString();
 
-    /**
-     * {@inheritDoc}
-     */
-    public abstract boolean test(Object obj);
-
     // modifiers
     // ------------------------------------------------------------------------
     /**
      * Add a UnaryPredicate to the list
      * @param p UnaryPredicate to add
      */
-    protected void addUnaryPredicate(UnaryPredicate p) {
+    protected void addUnaryPredicate(UnaryPredicate<? super A> p) {
         list.add(p);
     }
 
@@ -119,7 +114,7 @@
      * Get an Iterator over the contained UnaryPredicates.
      * @return Iterator
      */
-    protected Iterator getUnaryPredicateIterator() {
+    protected Iterator<UnaryPredicate<? super A>> getUnaryPredicateIterator() {
         return list.iterator();
     }
 
@@ -128,7 +123,7 @@
      * @param that the BaseUnaryPredicateList to test
      * @return boolean
      */
-    protected boolean getUnaryPredicateListEquals(BaseUnaryPredicateList that) {
+    protected boolean getUnaryPredicateListEquals(BaseUnaryPredicateList<?> that) {
         return (null != that && this.list.equals(that.list));
     }
 

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BinaryAnd.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BinaryAnd.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BinaryAnd.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BinaryAnd.java Mon Jun  9 10:17:39 2008
@@ -36,7 +36,7 @@
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
-public final class BinaryAnd extends BaseBinaryPredicateList {
+public final class BinaryAnd<L, R> extends BaseBinaryPredicateList<L, R> {
 
     // constructor
     // ------------------------------------------------------------------------
@@ -51,7 +51,7 @@
      * Create a new BinaryAnd.
      * @param p BinaryPredicate to add
      */
-    public BinaryAnd(BinaryPredicate p) {
+    public BinaryAnd(BinaryPredicate<? super L, ? super R> p) {
         super(p);
     }
 
@@ -60,7 +60,7 @@
      * @param p BinaryPredicate to add
      * @param q BinaryPredicate to add
      */
-    public BinaryAnd(BinaryPredicate p, BinaryPredicate q) {
+    public BinaryAnd(BinaryPredicate<? super L, ? super R> p, BinaryPredicate<? super L, ? super R> q) {
         super(p, q);
     }
 
@@ -70,7 +70,8 @@
      * @param q BinaryPredicate to add
      * @param r BinaryPredicate to add
      */
-    public BinaryAnd(BinaryPredicate p, BinaryPredicate q, BinaryPredicate r) {
+    public BinaryAnd(BinaryPredicate<? super L, ? super R> p, BinaryPredicate<? super L, ? super R> q,
+            BinaryPredicate<? super L, ? super R> r) {
         super(p, q, r);
     }
 
@@ -81,7 +82,7 @@
      * @param p BinaryPredicate to add
      * @return this
      */
-    public BinaryAnd and(BinaryPredicate p) {
+    public BinaryAnd<L, R> and(BinaryPredicate<? super L, ? super R> p) {
         super.addBinaryPredicate(p);
         return this;
     }
@@ -91,9 +92,9 @@
     /**
      * {@inheritDoc}
      */
-    public boolean test(Object a, Object b) {
-        for (Iterator iter = getBinaryPredicateIterator(); iter.hasNext();) {
-            if (!((BinaryPredicate) iter.next()).test(a, b)) {
+    public boolean test(L a, R b) {
+        for (Iterator<BinaryPredicate<? super L, ? super R>> iter = getBinaryPredicateIterator(); iter.hasNext();) {
+            if (!iter.next().test(a, b)) {
                 return false;
             }
         }
@@ -104,7 +105,7 @@
      * {@inheritDoc}
      */
     public boolean equals(Object that) {
-        return that == this || (that instanceof BinaryAnd && equals((BinaryAnd) that));
+        return that == this || (that instanceof BinaryAnd && equals((BinaryAnd<?, ?>) that));
     }
 
     /**
@@ -112,7 +113,7 @@
      * @param that the BinaryAnd to test
      * @return boolean
      */
-    public boolean equals(BinaryAnd that) {
+    public boolean equals(BinaryAnd<?, ?> that) {
         return getBinaryPredicateListEquals(that);
     }
 

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BinaryCompositeBinaryFunction.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BinaryCompositeBinaryFunction.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BinaryCompositeBinaryFunction.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BinaryCompositeBinaryFunction.java Mon Jun  9 10:17:39 2008
@@ -36,25 +36,56 @@
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
-public class BinaryCompositeBinaryFunction implements BinaryFunction, Serializable {
-    // attributes
-    // ------------------------------------------------------------------------
-    private BinaryFunction binary = null;
-    private BinaryFunction leftBinary = null;
-    private BinaryFunction rightBinary = null;
+public class BinaryCompositeBinaryFunction<L, R, T> implements BinaryFunction<L, R, T>, Serializable {
+
+    /**
+     * Type-remembering Helper
+     *
+     * @param <G>
+     * @param <H>
+     */
+    private class Helper<G, H> implements BinaryFunction<L, R, T>, Serializable {
+        private BinaryFunction<? super G, ? super H, ? extends T> f;
+        private BinaryFunction<? super L, ? super R, ? extends G> g;
+        private BinaryFunction<? super L, ? super R, ? extends H> h;
+
+        /**
+         * Create a new Helper.
+         * @param f final BinaryFunction to evaluate
+         * @param g left preceding BinaryFunction
+         * @param h right preceding BinaryFunction
+         */
+        public Helper(BinaryFunction<? super G, ? super H, ? extends T> f,
+                BinaryFunction<? super L, ? super R, ? extends G> g, BinaryFunction<? super L, ? super R, ? extends H> h) {
+            this.f = f;
+            this.g = g;
+            this.h = h;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public T evaluate(L left, R right) {
+            return f.evaluate(g.evaluate(left, right), h.evaluate(left, right));
+        }
+    }
+
+    private Helper<?, ?> helper;
 
     // constructor
     // ------------------------------------------------------------------------
     /**
      * Create a new BinaryCompositeBinaryFunction.
-     * @param f function
-     * @param g function
-     * @param h function
-     */
-    public BinaryCompositeBinaryFunction(BinaryFunction f, BinaryFunction g, BinaryFunction h) {
-        binary = f;
-        leftBinary = g;
-        rightBinary = h;
+     * @param f final BinaryFunction to evaluate
+     * @param g left preceding BinaryFunction
+     * @param h right preceding BinaryFunction
+     */
+    public <G, H> BinaryCompositeBinaryFunction(BinaryFunction<? super G, ? super H, ? extends T> f,
+            BinaryFunction<? super L, ? super R, ? extends G> g, BinaryFunction<? super L, ? super R, ? extends H> h) {
+        if (f == null || g == null || h == null) {
+            throw new IllegalArgumentException("BinaryFunction arguments may not be null");
+        }
+        this.helper = new Helper<G, H>(f, g, h);
     }
 
     // function interface
@@ -62,8 +93,8 @@
     /**
      * {@inheritDoc}
      */
-    public Object evaluate(Object left, Object right) {
-        return binary.evaluate(leftBinary.evaluate(left, right), rightBinary.evaluate(left, right));
+    public T evaluate(L left, R right) {
+        return helper.evaluate(left, right);
     }
 
     /**
@@ -71,7 +102,7 @@
      */
     public boolean equals(Object that) {
         return that == this
-                || (that instanceof BinaryCompositeBinaryFunction && equals((BinaryCompositeBinaryFunction) that));
+                || (that instanceof BinaryCompositeBinaryFunction && equals((BinaryCompositeBinaryFunction<?, ?, ?>) that));
     }
 
     /**
@@ -79,11 +110,11 @@
      * @param that BinaryCompositeBinaryFunction to test
      * @return boolean
      */
-    public boolean equals(BinaryCompositeBinaryFunction that) {
-        return (null != that)
-                && (null == binary ? null == that.binary : binary.equals(that.binary))
-                && (null == leftBinary ? null == that.leftBinary : leftBinary.equals(that.leftBinary))
-                && (null == rightBinary ? null == that.rightBinary : rightBinary.equals(that.rightBinary));
+    public boolean equals(BinaryCompositeBinaryFunction<?, ?, ?> that) {
+        return null != that
+                && helper.f.equals(that.helper.f)
+                && helper.g.equals(that.helper.g)
+                && helper.h.equals(that.helper.h);
     }
 
     /**
@@ -91,18 +122,12 @@
      */
     public int hashCode() {
         int hash = "BinaryCompositeBinaryFunction".hashCode();
-        if (null != binary) {
             hash <<= 4;
-            hash ^= binary.hashCode();
-        }
-        if (null != leftBinary) {
+            hash ^= helper.f.hashCode();
             hash <<= 4;
-            hash ^= leftBinary.hashCode();
-        }
-        if (null != rightBinary) {
+            hash ^= helper.g.hashCode();
             hash <<= 4;
-            hash ^= rightBinary.hashCode();
-        }
+            hash ^= helper.h.hashCode();
         return hash;
     }
 
@@ -110,7 +135,7 @@
      * {@inheritDoc}
      */
     public String toString() {
-        return "BinaryCompositeBinaryFunction<" + binary + ";" + leftBinary + ";" + rightBinary + ">";
+        return "BinaryCompositeBinaryFunction<" + helper.f + ";" + helper.g + ";" + helper.h + ">";
     }
 
 }

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BinaryNot.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BinaryNot.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BinaryNot.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BinaryNot.java Mon Jun  9 10:17:39 2008
@@ -34,10 +34,10 @@
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
-public final class BinaryNot implements BinaryPredicate, Serializable {
+public final class BinaryNot<L, R> implements BinaryPredicate<L, R>, Serializable {
     // attributes
     // ------------------------------------------------------------------------
-    private BinaryPredicate predicate = null;
+    private BinaryPredicate<? super L, ? super R> predicate = null;
 
     // constructor
     // ------------------------------------------------------------------------
@@ -45,7 +45,7 @@
      * Create a new BinaryNot.
      * @param p BinaryPredicate to negate
      */
-    public BinaryNot(BinaryPredicate p) {
+    public BinaryNot(BinaryPredicate<? super L, ? super R> p) {
         this.predicate = p;
     }
 
@@ -54,7 +54,7 @@
     /**
      * {@inheritDoc}
      */
-    public boolean test(Object left, Object right) {
+    public boolean test(L left, R right) {
         return !(predicate.test(left, right));
     }
 
@@ -62,7 +62,7 @@
      * {@inheritDoc}
      */
     public boolean equals(Object that) {
-        return that == this || (that instanceof BinaryNot && equals((BinaryNot) that));
+        return that == this || (that instanceof BinaryNot && equals((BinaryNot<?, ?>) that));
     }
 
     /**
@@ -70,7 +70,7 @@
      * @param that BinaryNot to test
      * @return boolean
      */
-    public boolean equals(BinaryNot that) {
+    public boolean equals(BinaryNot<?, ?> that) {
         return null != that && (null == predicate ? null == that.predicate : predicate.equals(that.predicate));
     }
 
@@ -99,8 +99,8 @@
      * @param that BinaryPredicate to negate
      * @return BinaryPredicate
      */
-    public static BinaryPredicate not(BinaryPredicate that) {
-        return null == that ? null : new BinaryNot(that);
+    public static <L, R> BinaryPredicate<L, R> not(BinaryPredicate<? super L, ? super R> that) {
+        return null == that ? null : new BinaryNot<L, R>(that);
     }
 
 }

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BinaryOr.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BinaryOr.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BinaryOr.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BinaryOr.java Mon Jun  9 10:17:39 2008
@@ -36,7 +36,7 @@
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
-public final class BinaryOr extends BaseBinaryPredicateList {
+public final class BinaryOr<L, R> extends BaseBinaryPredicateList<L, R> {
 
     // constructor
     // ------------------------------------------------------------------------
@@ -51,7 +51,7 @@
      * Create a new BinaryOr.
      * @param p BinaryPredicate to add
      */
-    public BinaryOr(BinaryPredicate p) {
+    public BinaryOr(BinaryPredicate<? super L, ? super R> p) {
         super(p);
     }
 
@@ -60,7 +60,7 @@
      * @param p BinaryPredicate to add
      * @param q BinaryPredicate to add
      */
-    public BinaryOr(BinaryPredicate p, BinaryPredicate q) {
+    public BinaryOr(BinaryPredicate<? super L, ? super R> p, BinaryPredicate<? super L, ? super R> q) {
         super(p, q);
     }
 
@@ -70,7 +70,8 @@
      * @param q BinaryPredicate to add
      * @param r BinaryPredicate to add
      */
-    public BinaryOr(BinaryPredicate p, BinaryPredicate q, BinaryPredicate r) {
+    public BinaryOr(BinaryPredicate<? super L, ? super R> p, BinaryPredicate<? super L, ? super R> q,
+            BinaryPredicate<? super L, ? super R> r) {
         super(p, q, r);
     }
 
@@ -81,7 +82,7 @@
      * @param p BinaryPredicate to add
      * @return this
      */
-    public BinaryOr or(BinaryPredicate p) {
+    public BinaryOr<L, R> or(BinaryPredicate<? super L, ? super R> p) {
         super.addBinaryPredicate(p);
         return this;
     }
@@ -91,9 +92,9 @@
     /**
      * {@inheritDoc}
      */
-    public boolean test(Object a, Object b) {
-        for (Iterator iter = getBinaryPredicateIterator(); iter.hasNext();) {
-            if (((BinaryPredicate) iter.next()).test(a, b)) {
+    public boolean test(L a, R b) {
+        for (Iterator<BinaryPredicate<? super L, ? super R>> iter = getBinaryPredicateIterator(); iter.hasNext();) {
+            if (iter.next().test(a, b)) {
                 return true;
             }
         }
@@ -104,7 +105,7 @@
      * {@inheritDoc}
      */
     public boolean equals(Object that) {
-        return that == this || (that instanceof BinaryOr && equals((BinaryOr) that));
+        return that == this || (that instanceof BinaryOr && equals((BinaryOr<?, ?>) that));
     }
 
     /**
@@ -112,7 +113,7 @@
      * @param that BinaryOr to test
      * @return boolean
      */
-    public boolean equals(BinaryOr that) {
+    public boolean equals(BinaryOr<?, ?> that) {
         return getBinaryPredicateListEquals(that);
     }
 

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BinarySequence.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BinarySequence.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BinarySequence.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/BinarySequence.java Mon Jun  9 10:17:39 2008
@@ -41,10 +41,10 @@
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
-public class BinarySequence implements BinaryProcedure, Serializable {
+public class BinarySequence<L, R> implements BinaryProcedure<L, R>, Serializable {
     // attributes
     // ------------------------------------------------------------------------
-    private List list = new ArrayList();
+    private List<BinaryProcedure<? super L, ? super R>> list = new ArrayList<BinaryProcedure<? super L, ? super R>>();
 
     // constructor
     // ------------------------------------------------------------------------
@@ -58,7 +58,7 @@
      * Create a new BinarySequence.
      * @param p BinaryProcedure to add
      */
-    public BinarySequence(BinaryProcedure p) {
+    public BinarySequence(BinaryProcedure<? super L, ? super R> p) {
         then(p);
     }
 
@@ -67,7 +67,7 @@
      * @param p BinaryProcedure to add
      * @param q BinaryProcedure to add
      */
-    public BinarySequence(BinaryProcedure p, BinaryProcedure q) {
+    public BinarySequence(BinaryProcedure<? super L, ? super R> p, BinaryProcedure<? super L, ? super R> q) {
         then(p);
         then(q);
     }
@@ -77,7 +77,7 @@
      * @param p BinaryProcedure to add
      * @return this
      */
-    public BinarySequence then(BinaryProcedure p) {
+    public BinarySequence<L, R> then(BinaryProcedure<? super L, ? super R> p) {
         list.add(p);
         return this;
     }
@@ -87,9 +87,9 @@
     /**
      * {@inheritDoc}
      */
-    public void run(Object left, Object right) {
-        for (ListIterator iter = list.listIterator(list.size()); iter.hasPrevious();) {
-            ((BinaryProcedure) iter.previous()).run(left, right);
+    public void run(L left, R right) {
+        for (ListIterator<BinaryProcedure<? super L, ? super R>> iter = list.listIterator(list.size()); iter.hasPrevious();) {
+            iter.previous().run(left, right);
         }
     }
 
@@ -97,7 +97,7 @@
      * {@inheritDoc}
      */
     public boolean equals(Object that) {
-        return that == this || (that instanceof BinarySequence && equals((BinarySequence) that));
+        return that == this || (that instanceof BinarySequence && equals((BinarySequence<?, ?>) that));
     }
 
     /**
@@ -105,7 +105,7 @@
      * @param that BinarySequence to test
      * @return boolean
      */
-    public boolean equals(BinarySequence that) {
+    public boolean equals(BinarySequence<?, ?> that) {
         // by construction, list is never null
         return null != that && list.equals(that.list);
     }

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/Composite.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/Composite.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/Composite.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/Composite.java Mon Jun  9 10:17:39 2008
@@ -23,7 +23,7 @@
 import org.apache.commons.functor.UnaryProcedure;
 
 /**
- * Utility methods for creating composite functors.
+ * Utility/fluent methods for creating composite functors.
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
@@ -37,33 +37,64 @@
 
     /**
      * Create a composite UnaryProcedure.
-     * @param p UnaryProcedure to execute against output of <code>f</code>
-     * @param f UnaryFunction to apply
-     * @return UnaryProcedure
+     * @param procedure UnaryProcedure to execute against output of <code>f</code>
+     * @return CompositeUnaryProcedure<A>
      */
-    public static final UnaryProcedure procedure(UnaryProcedure p, UnaryFunction f) {
-        return new CompositeUnaryProcedure(p, f);
+    public static final <A> CompositeUnaryProcedure<A> procedure(UnaryProcedure<? super A> procedure) {
+        return new CompositeUnaryProcedure<A>(procedure);
+    }
+
+    /**
+     * Create a composite UnaryProcedure.
+     * @param procedure UnaryProcedure to execute against output of <code>f</code>
+     * @param function UnaryFunction to apply
+     * @return CompositeUnaryProcedure<A>
+     */
+    public static final <A, T> CompositeUnaryProcedure<A> procedure(UnaryProcedure<? super T> procedure,
+            UnaryFunction<? super A, ? extends T> function) {
+        return new CompositeUnaryProcedure<T>(procedure).of(function);
     }
 
     /**
      * Create a composite UnaryPredicate.
-     * @param p UnaryPredicate to test the output of <code>f</code>
-     * @param f UnaryFunction to apply
-     * @return UnaryPredicate
+     * @param pred UnaryPredicate to test the output of <code>f</code>
+     * @return CompositeUnaryPredicate<A>
      */
-    public static final UnaryPredicate predicate(UnaryPredicate p, UnaryFunction f) {
-        return new CompositeUnaryPredicate(p, f);
+    public static final <A> CompositeUnaryPredicate<A> predicate(UnaryPredicate<? super A> pred) {
+        return new CompositeUnaryPredicate<A>(pred);
+    }
+
+    /**
+     * Create a composite UnaryPredicate.
+     * @param predicate UnaryPredicate to test the output of <code>f</code>
+     * @param function UnaryFunction to apply
+     * @return CompositeUnaryPredicate<A>
+     */
+    public static final <A, T> CompositeUnaryPredicate<A> predicate(UnaryPredicate<? super T> predicate,
+            UnaryFunction<? super A, ? extends T> function) {
+        return new CompositeUnaryPredicate<T>(predicate).of(function);
     }
 
     /**
      * Create a composite BinaryPredicate.
      * @param p BinaryPredicate to test <i>output(</i><code>f</code><i>), output(</i><code>g</code><i>)</i>
-     * @param f left UnaryFunction
-     * @param g right UnaryFunction
+     * @param g left UnaryFunction
+     * @param h right UnaryFunction
      * @return BinaryPredicate
      */
-    public static final BinaryPredicate predicate(BinaryPredicate p, UnaryFunction f, UnaryFunction g) {
-        return new UnaryCompositeBinaryPredicate(p, f, g);
+    public static final <L, R, G, H> UnaryCompositeBinaryPredicate<L, R> predicate(
+            BinaryPredicate<? super G, ? super H> p, UnaryFunction<? super L, ? extends G> g,
+            UnaryFunction<? super R, ? extends H> h) {
+        return new UnaryCompositeBinaryPredicate<L, R>(p, g, h);
+    }
+
+    /**
+     * Create a composite UnaryFunction.
+     * @param f UnaryFunction to apply to the output of <code>g</code>
+     * @return UnaryFunction
+     */
+    public static final <A, T> CompositeUnaryFunction<A, T> function(UnaryFunction<? super A, ? extends T> f) {
+        return new CompositeUnaryFunction<A, T>(f);
     }
 
     /**
@@ -72,10 +103,24 @@
      * @param g UnaryFunction to apply first
      * @return UnaryFunction
      */
-    public static final UnaryFunction function(UnaryFunction f, UnaryFunction g) {
-        return new CompositeUnaryFunction(f, g);
+    public static final <A, X, T> CompositeUnaryFunction<A, T> function(UnaryFunction<? super X, ? extends T> f, UnaryFunction<? super A, ? extends X> g) {
+        return new CompositeUnaryFunction<X, T>(f).of(g);
     }
 
+//    /**
+//     * Chain a BinaryFunction to a UnaryFunction.
+//     * @param <L>
+//     * @param <R>
+//     * @param <X>
+//     * @param <T>
+//     * @param f UnaryFunction to apply to the output of <code>g</code>
+//     * @param g BinaryFunction to apply first
+//     * @return BinaryFunction<L, R, T>
+//     */
+//    public static final <L, R, X, T> BinaryFunction<L, R, T> function(UnaryFunction<? super X, ? extends T> f, BinaryFunction<? super L, ? super R, ? extends X> g) {
+//        return new CompositeUnaryFunction<X, T>(f).of(g);
+//    }
+
     /**
      * Create a composite<UnaryFunction> BinaryFunction.
      * @param f BinaryFunction to apply to <i>output(</i><code>f</code><i>), output(</i><code>g</code><i>)</i>
@@ -83,8 +128,10 @@
      * @param h right UnaryFunction
      * @return BinaryFunction
      */
-    public static final BinaryFunction function(BinaryFunction f, UnaryFunction g, UnaryFunction h) {
-        return new UnaryCompositeBinaryFunction(f, g, h);
+    public static final <L, R, G, H, T> UnaryCompositeBinaryFunction<L, R, T> function(
+            BinaryFunction<? super G, ? super H, ? extends T> f, UnaryFunction<? super L, ? extends G> g,
+            UnaryFunction<? super R, ? extends H> h) {
+        return new UnaryCompositeBinaryFunction<L, R, T>(f, g, h);
     }
 
     /**
@@ -94,7 +141,9 @@
      * @param h right BinaryFunction
      * @return BinaryFunction
      */
-    public static final BinaryFunction function(BinaryFunction f, BinaryFunction g, BinaryFunction h) {
-        return new BinaryCompositeBinaryFunction(f, g, h);
+    public static final <L, R, G, H, T> BinaryCompositeBinaryFunction<L, R, T> function(
+            BinaryFunction<? super G, ? super H, ? extends T> f, BinaryFunction<? super L, ? super R, ? extends G> g,
+            BinaryFunction<? super L, ? super R, ? extends H> h) {
+        return new BinaryCompositeBinaryFunction<L, R, T>(f, g, h);
     }
 }

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryFunction.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryFunction.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryFunction.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryFunction.java Mon Jun  9 10:17:39 2008
@@ -17,9 +17,6 @@
 package org.apache.commons.functor.core.composite;
 
 import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.ListIterator;
 
 import org.apache.commons.functor.UnaryFunction;
 
@@ -49,67 +46,114 @@
  * </p>
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
+ * @author Matt Benson
  */
-public class CompositeUnaryFunction implements UnaryFunction, Serializable {
+public class CompositeUnaryFunction<A, T> implements UnaryFunction<A, T>, Serializable {
 
-    // attributes
-    // ------------------------------------------------------------------------
-    private List list = new ArrayList();
-
-    // constructor
-    // ------------------------------------------------------------------------
     /**
-     * Create a new CompositeUnaryFunction.
-     */
-    public CompositeUnaryFunction() {
+     * Encapsulates a double function evaluation.
+     * @param <A> argument type
+     * @param <X> intermediate type
+     * @param <T> return type
+     */
+    private class Helper<X> implements UnaryFunction<A, T>, Serializable {
+        private UnaryFunction<? super X, ? extends T> following;
+        private UnaryFunction<? super A, ? extends X> preceding;
+
+        /**
+         * Create a new Helper.
+         * @param following UnaryFunction<X, Y>
+         * @param preceding UnaryFunction<Y, Z>
+         */
+        public Helper(UnaryFunction<? super X, ? extends T> following, UnaryFunction<? super A, ? extends X> preceding) {
+            this.following = following;
+            this.preceding = preceding;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public T evaluate(A obj) {
+            return following.evaluate(preceding.evaluate(obj));
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public boolean equals(Object obj) {
+            return obj == this || obj instanceof Helper && equals((Helper<?>) obj);
+        }
+
+        private boolean equals(Helper<?> helper) {
+            return helper.following.equals(following) && helper.preceding.equals(preceding);
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public int hashCode() {
+            int result = "CompositeUnaryFunction$Helper".hashCode();
+            result <<= 2;
+            result |= following.hashCode();
+            result <<= 2;
+            result |= preceding.hashCode();
+            return result;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public String toString() {
+            // TODO Auto-generated method stub
+            return following.toString() + " of " + preceding.toString();
+        }
     }
 
+    private UnaryFunction<? super A, ? extends T> function;
+
     /**
      * Create a new CompositeUnaryFunction.
-     * @param f UnaryFunction to add
+     * @param function UnaryFunction to call
      */
-    public CompositeUnaryFunction(UnaryFunction f) {
-        of(f);
+    public CompositeUnaryFunction(UnaryFunction<? super A, ? extends T> function) {
+        if (function == null) {
+            throw new IllegalArgumentException("function must not be null");
+        }
+        this.function = function;
     }
 
-    /**
-     * Create a new CompositeUnaryFunction.
-     * @param f UnaryFunction to add
-     * @param g UnaryFunction to add
-     */
-    public CompositeUnaryFunction(UnaryFunction f, UnaryFunction g) {
-        of(f);
-        of(g);
+    private <X> CompositeUnaryFunction(UnaryFunction<? super X, ? extends T> following, UnaryFunction<? super A, ? extends X> preceding) {
+        this.function = new Helper<X>(following, preceding);
     }
 
-    // modifiers
-    // ------------------------------------------------------------------------
     /**
-     * Fluently prepend a UnaryFunction to the chain.
-     * @param f UnaryFunction to prepend
-     * @return this
+     * {@inheritDoc}
      */
-    public CompositeUnaryFunction of(UnaryFunction f) {
-        list.add(f);
-        return this;
+    public T evaluate(A obj) {
+        return function.evaluate(obj);
     }
 
     /**
-     * {@inheritDoc}
+     * Fluently obtain a CompositeUnaryFunction that is "this function" applied to the specified preceding function.
+     * @param <P> argument type of the resulting function.
+     * @param preceding UnaryFunction
+     * @return CompositeUnaryFunction<P, T>
      */
-    public Object evaluate(Object obj) {
-        Object result = obj;
-        for (ListIterator iter = list.listIterator(list.size()); iter.hasPrevious();) {
-            result = ((UnaryFunction) iter.previous()).evaluate(result);
+    public <P> CompositeUnaryFunction<P, T> of(UnaryFunction<? super P, ? extends A> preceding) {
+        if (preceding == null) {
+            throw new IllegalArgumentException("preceding function was null");
         }
-        return result;
+        return new CompositeUnaryFunction<P, T>(function, preceding);
     }
 
     /**
      * {@inheritDoc}
      */
     public boolean equals(Object that) {
-        return that == this || (that instanceof CompositeUnaryFunction && equals((CompositeUnaryFunction) that));
+        return that == this || (that instanceof CompositeUnaryFunction && equals((CompositeUnaryFunction<?, ?>) that));
     }
 
     /**
@@ -117,9 +161,9 @@
      * @param that CompositeUnaryFunction to test
      * @return boolean
      */
-    public boolean equals(CompositeUnaryFunction that) {
+    public boolean equals(CompositeUnaryFunction<?, ?> that) {
         // by construction, list is never null
-        return null != that && list.equals(that.list);
+        return null != that && function.equals(that.function);
     }
 
     /**
@@ -127,14 +171,14 @@
      */
     public int hashCode() {
         // by construction, list is never null
-        return "CompositeUnaryFunction".hashCode() ^ list.hashCode();
+        return ("CompositeUnaryFunction".hashCode() << 4) ^ function.hashCode();
     }
 
     /**
      * {@inheritDoc}
      */
     public String toString() {
-        return "CompositeUnaryFunction<" + list + ">";
+        return "CompositeUnaryFunction<" + function + ">";
     }
 
 }

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryPredicate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryPredicate.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryPredicate.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryPredicate.java Mon Jun  9 10:17:39 2008
@@ -20,6 +20,7 @@
 
 import org.apache.commons.functor.UnaryFunction;
 import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.adapter.UnaryPredicateUnaryFunction;
 
 /**
  * A {@link UnaryPredicate UnaryPredicate}
@@ -44,46 +45,41 @@
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
-public final class CompositeUnaryPredicate implements UnaryPredicate, Serializable {
+public final class CompositeUnaryPredicate<A> implements UnaryPredicate<A>, Serializable {
     // attributes
     // ------------------------------------------------------------------------
-    private CompositeUnaryFunction function = null;
-    private UnaryPredicate predicate = null;
+    private CompositeUnaryFunction<? super A, Boolean> function = null;
 
     // constructor
     // ------------------------------------------------------------------------
     /**
      * Create a new CompositeUnaryPredicate.
-     * @param p UnaryPredicate against which the composite functions' output will be tested
+     * @param predicate UnaryPredicate against which the composite functions' output will be tested
      */
-    public CompositeUnaryPredicate(UnaryPredicate p) {
-        if (null == p) { throw new NullPointerException(); }
-        this.predicate = p;
-        this.function = new CompositeUnaryFunction();
+    public CompositeUnaryPredicate(UnaryPredicate<? super A> predicate) {
+        if (null == predicate) {
+            throw new IllegalArgumentException("predicate must not be null");
+        }
+        this.function = new CompositeUnaryFunction<A, Boolean>(new UnaryPredicateUnaryFunction<A>(predicate));
     }
 
     /**
      * Create a new CompositeUnaryPredicate.
-     * @param p UnaryPredicate against which the composite functions' output will be tested
-     * @param f UnaryFunction single UnaryFunction to apply
+     * @param function delegate
      */
-    public CompositeUnaryPredicate(UnaryPredicate p, UnaryFunction f) {
-        if (null == p) { throw new NullPointerException(); }
-        if (null == f) { throw new NullPointerException(); }
-        this.predicate = p;
-        this.function = new CompositeUnaryFunction(f);
+    private CompositeUnaryPredicate(CompositeUnaryFunction<? super A, Boolean> function) {
+        this.function = function;
     }
 
     // modifiers
     // ------------------------------------------------------------------------
     /**
-     * Fluently prepend a UnaryFunction to the chain.
-     * @param f UnaryFunction to prepend
-     * @return this
-     */
-    public CompositeUnaryPredicate of(UnaryFunction f) {
-        function.of(f);
-        return this;
+     * Fluently obtain a CompositeUnaryPredicate that applies our predicate to the result of the preceding function.
+     * @param preceding UnaryFunction
+     * @return CompositeUnaryPredicate<P>
+     */
+    public <P> CompositeUnaryPredicate<P> of(UnaryFunction<? super P, ? extends A> preceding) {
+        return new CompositeUnaryPredicate<P>(function.of(preceding));
     }
 
     // predicate interface
@@ -91,15 +87,15 @@
     /**
      * {@inheritDoc}
      */
-    public boolean test(Object obj) {
-        return predicate.test(function.evaluate(obj));
+    public boolean test(A obj) {
+        return function.evaluate(obj);
     }
 
     /**
      * {@inheritDoc}
      */
     public boolean equals(Object that) {
-        return that == this || (that instanceof CompositeUnaryPredicate && equals((CompositeUnaryPredicate) that));
+        return that == this || (that instanceof CompositeUnaryPredicate && equals((CompositeUnaryPredicate<?>) that));
     }
 
     /**
@@ -107,8 +103,8 @@
      * @param that CompositeUnaryPredicate to test
      * @return boolean
      */
-    public boolean equals(CompositeUnaryPredicate that) {
-        return null != that && predicate.equals(that.predicate) && function.equals(that.function);
+    public boolean equals(CompositeUnaryPredicate<?> that) {
+        return null != that && function.equals(that.function);
     }
 
     /**
@@ -117,8 +113,6 @@
     public int hashCode() {
         int hash = "CompositeUnaryPredicate".hashCode();
         hash <<= 2;
-        hash ^= predicate.hashCode();
-        hash <<= 2;
         hash ^= function.hashCode();
         return hash;
     }
@@ -127,7 +121,7 @@
      * {@inheritDoc}
      */
     public String toString() {
-        return "CompositeUnaryFunction<" + predicate + ";" + function + ">";
+        return "CompositeUnaryFunction<" + function + ">";
     }
 
 }

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryProcedure.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryProcedure.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryProcedure.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryProcedure.java Mon Jun  9 10:17:39 2008
@@ -20,6 +20,7 @@
 
 import org.apache.commons.functor.UnaryFunction;
 import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.adapter.UnaryProcedureUnaryFunction;
 
 /**
  * A {@link UnaryProcedure UnaryProcedure}
@@ -44,52 +45,37 @@
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
-public final class CompositeUnaryProcedure implements UnaryProcedure, Serializable {
+public final class CompositeUnaryProcedure<A> implements UnaryProcedure<A>, Serializable {
     // attributes
     // ------------------------------------------------------------------------
-    private CompositeUnaryFunction function = null;
-    private UnaryProcedure procedure = null;
+    private CompositeUnaryFunction<? super A, Object> function = null;
 
     // constructor
     // ------------------------------------------------------------------------
     /**
      * Create a new CompositeUnaryProcedure.
-     * @param p final UnaryProcedure to run
+     * @param procedure final UnaryProcedure to run
      */
-    public CompositeUnaryProcedure(UnaryProcedure p) {
-        if (null == p) {
-            throw new NullPointerException();
+    public CompositeUnaryProcedure(UnaryProcedure<? super A> procedure) {
+        if (null == procedure) {
+            throw new IllegalArgumentException("procedure must not be null");
         }
-        this.procedure = p;
-        this.function = new CompositeUnaryFunction();
+        this.function = new CompositeUnaryFunction<A, Object>(new UnaryProcedureUnaryFunction<A, Object>(procedure));
     }
 
-    /**
-     * Create a new CompositeUnaryProcedure.
-     * @param p final UnaryProcedure to run
-     * @param f UnaryFunction to chain into <code>p</code>
-     */
-    public CompositeUnaryProcedure(UnaryProcedure p, UnaryFunction f) {
-        if (null == p) {
-            throw new NullPointerException();
-        }
-        if (null == f) {
-            throw new NullPointerException();
-        }
-        this.procedure = p;
-        this.function = new CompositeUnaryFunction(f);
+    private CompositeUnaryProcedure(CompositeUnaryFunction<? super A, Object> function) {
+        this.function = function;
     }
 
     // modifiers
     // ------------------------------------------------------------------------
     /**
-     * Fluently prepend a transformation to the chain.
-     * @param f UnaryFunction to prepend
-     * @return this
-     */
-    public CompositeUnaryProcedure of(UnaryFunction f) {
-        function.of(f);
-        return this;
+     * Fluently obtain a CompositeUnaryProcedure that runs our procedure against the result of the preceding function.
+     * @param preceding UnaryFunction
+     * @return CompositeUnaryProcedure<P>
+     */
+    public <T> CompositeUnaryProcedure<T> of(UnaryFunction<? super T, ? extends A> preceding) {
+        return new CompositeUnaryProcedure<T>(function.of(preceding));
     }
 
     // predicate interface
@@ -97,15 +83,15 @@
     /**
      * {@inheritDoc}
      */
-    public void run(Object obj) {
-        procedure.run(function.evaluate(obj));
+    public void run(A obj) {
+        function.evaluate(obj);
     }
 
     /**
      * {@inheritDoc}
      */
     public boolean equals(Object that) {
-        return that == this || (that instanceof CompositeUnaryProcedure && equals((CompositeUnaryProcedure) that));
+        return that == this || (that instanceof CompositeUnaryProcedure && equals((CompositeUnaryProcedure<?>) that));
     }
 
     /**
@@ -113,8 +99,8 @@
      * @param that CompositeUnaryProcedure to test
      * @return boolean
      */
-    public boolean equals(CompositeUnaryProcedure that) {
-        return null != that && procedure.equals(that.procedure) && function.equals(that.function);
+    public boolean equals(CompositeUnaryProcedure<?> that) {
+        return null != that && function.equals(that.function);
     }
 
     /**
@@ -123,8 +109,6 @@
     public int hashCode() {
         int hash = "CompositeUnaryProcedure".hashCode();
         hash <<= 2;
-        hash ^= procedure.hashCode();
-        hash <<= 2;
         hash ^= function.hashCode();
         return hash;
     }
@@ -133,7 +117,7 @@
      * {@inheritDoc}
      */
     public String toString() {
-        return "CompositeUnaryProcedure<" + procedure + ";" + function + ">";
+        return "CompositeUnaryProcedure<" + function + ">";
     }
 
 }

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/Conditional.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/Conditional.java?rev=665786&r1=665785&r2=665786&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/Conditional.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/Conditional.java Mon Jun  9 10:17:39 2008
@@ -45,10 +45,11 @@
      * @param q if
      * @param r then
      * @param s else
-     * @return UnaryProcedure
+     * @return UnaryProcedure<A>
      */
-    public static final UnaryProcedure procedure(UnaryPredicate q, UnaryProcedure r, UnaryProcedure s) {
-        return new ConditionalUnaryProcedure(q, r, s);
+    public static final <A> UnaryProcedure<A> procedure(UnaryPredicate<? super A> q, UnaryProcedure<? super A> r,
+            UnaryProcedure<? super A> s) {
+        return new ConditionalUnaryProcedure<A>(q, r, s);
     }
 
     /**
@@ -56,10 +57,11 @@
      * @param q if
      * @param r then
      * @param s else
-     * @return UnaryFunction
+     * @return UnaryFunction<A, T>
      */
-    public static final UnaryFunction function(UnaryPredicate q, UnaryFunction r, UnaryFunction s) {
-        return new ConditionalUnaryFunction(q, r, s);
+    public static final <A, T> UnaryFunction<A, T> function(UnaryPredicate<? super A> q,
+            UnaryFunction<? super A, ? extends T> r, UnaryFunction<? super A, ? extends T> s) {
+        return new ConditionalUnaryFunction<A, T>(q, r, s);
     }
 
     /**
@@ -67,10 +69,11 @@
      * @param q if
      * @param r then
      * @param s else
-     * @return UnaryPredicate
+     * @return UnaryPredicate<A>
      */
-    public static final UnaryPredicate predicate(UnaryPredicate q, UnaryPredicate r, UnaryPredicate s) {
-        return new ConditionalUnaryPredicate(q, r, s);
+    public static final <A> UnaryPredicate<A> predicate(UnaryPredicate<? super A> q, UnaryPredicate<? super A> r,
+            UnaryPredicate<? super A> s) {
+        return new ConditionalUnaryPredicate<A>(q, r, s);
     }
 
     /**
@@ -78,10 +81,11 @@
      * @param q if
      * @param r then
      * @param s else
-     * @return BinaryProcedure
+     * @return BinaryProcedure<L, R>
      */
-    public static final BinaryProcedure procedure(BinaryPredicate q, BinaryProcedure r, BinaryProcedure s) {
-        return new ConditionalBinaryProcedure(q, r, s);
+    public static final <L, R> BinaryProcedure<L, R> procedure(BinaryPredicate<? super L, ? super R> q,
+            BinaryProcedure<? super L, ? super R> r, BinaryProcedure<? super L, ? super R> s) {
+        return new ConditionalBinaryProcedure<L, R>(q, r, s);
     }
 
     /**
@@ -89,10 +93,11 @@
      * @param q if
      * @param r then
      * @param s else
-     * @return BinaryFunction
+     * @return BinaryFunction<L, R, T>
      */
-    public static final BinaryFunction function(BinaryPredicate q, BinaryFunction r, BinaryFunction s) {
-        return new ConditionalBinaryFunction(q, r, s);
+    public static final <L, R, T> BinaryFunction<L, R, T> function(BinaryPredicate<? super L, ? super R> q,
+            BinaryFunction<? super L, ? super R, ? extends T> r, BinaryFunction<? super L, ? super R, ? extends T> s) {
+        return new ConditionalBinaryFunction<L, R, T>(q, r, s);
     }
 
     /**
@@ -100,10 +105,11 @@
      * @param q if
      * @param r then
      * @param s else
-     * @return BinaryPredicate
+     * @return BinaryPredicate<L, R>
      */
-    public static final BinaryPredicate predicate(BinaryPredicate q, BinaryPredicate r, BinaryPredicate s) {
-        return new ConditionalBinaryPredicate(q, r, s);
+    public static final <L, R> BinaryPredicate<L, R> predicate(BinaryPredicate<? super L, ? super R> q,
+            BinaryPredicate<? super L, ? super R> r, BinaryPredicate<? super L, ? super R> s) {
+        return new ConditionalBinaryPredicate<L, R>(q, r, s);
     }
 
 }



Mime
View raw message