commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r666113 - in /commons/sandbox/functor/trunk/src: main/java/org/apache/commons/functor/adapter/IgnoreLeftPredicate.java test/java/org/apache/commons/functor/adapter/TestIgnoreLeftPredicate.java
Date Tue, 10 Jun 2008 13:59:13 GMT
Author: mbenson
Date: Tue Jun 10 06:59:13 2008
New Revision: 666113

URL: http://svn.apache.org/viewvc?rev=666113&view=rev
Log:
null guard constructor argument with IllegalArgumentException; make into a fully generic BinaryPredicate

Modified:
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftPredicate.java
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestIgnoreLeftPredicate.java

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftPredicate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftPredicate.java?rev=666113&r1=666112&r2=666113&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftPredicate.java
(original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftPredicate.java
Tue Jun 10 06:59:13 2008
@@ -38,22 +38,25 @@
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
-public final class IgnoreLeftPredicate<A> implements BinaryPredicate<Object, A>,
Serializable {
+public final class IgnoreLeftPredicate<L, R> implements BinaryPredicate<L, R>,
Serializable {
     /** The {@link UnaryPredicate UnaryPredicate} I'm wrapping. */
-    private UnaryPredicate<? super A> predicate;
+    private UnaryPredicate<? super R> predicate;
 
     /**
      * Create a new IgnoreLeftPredicate.
      * @param predicate the right predicate
      */
-    public IgnoreLeftPredicate(UnaryPredicate<? super A> predicate) {
+    public IgnoreLeftPredicate(UnaryPredicate<? super R> predicate) {
+        if (predicate == null) {
+            throw new IllegalArgumentException("UnaryPredicate argument was null");
+        }
         this.predicate = predicate;
     }
 
     /**
      * {@inheritDoc}
      */
-    public boolean test(Object left, A right) {
+    public boolean test(L left, R right) {
         return predicate.test(right);
     }
 
@@ -61,7 +64,7 @@
      * {@inheritDoc}
      */
     public boolean equals(Object that) {
-        return that == this || (that instanceof IgnoreLeftPredicate && equals((IgnoreLeftPredicate<?>)
that));
+        return that == this || (that instanceof IgnoreLeftPredicate && equals((IgnoreLeftPredicate<?,
?>) that));
     }
 
     /**
@@ -69,7 +72,7 @@
      * @param that the IgnoreLeftPredicate to test
      * @return boolean
      */
-    public boolean equals(IgnoreLeftPredicate<?> that) {
+    public boolean equals(IgnoreLeftPredicate<?, ?> that) {
         return null != that && (null == predicate ? null == that.predicate : predicate.equals(that.predicate));
     }
 
@@ -93,11 +96,13 @@
 
     /**
      * Adapt a UnaryPredicate to an IgnoreLeftPredicate.
+     * @param <L>
+     * @param <R>
      * @param predicate to adapt
-     * @return IgnoreLeftPredicate
+     * @return IgnoreLeftPredicate<L, R>
      */
-    public static <A> IgnoreLeftPredicate<A> adapt(UnaryPredicate<? super
A> predicate) {
-        return null == predicate ? null : new IgnoreLeftPredicate<A>(predicate);
+    public static <L, R> IgnoreLeftPredicate<L, R> adapt(UnaryPredicate<?
super R> predicate) {
+        return null == predicate ? null : new IgnoreLeftPredicate<L, R>(predicate);
     }
 
 }

Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestIgnoreLeftPredicate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestIgnoreLeftPredicate.java?rev=666113&r1=666112&r2=666113&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestIgnoreLeftPredicate.java
(original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestIgnoreLeftPredicate.java
Tue Jun 10 06:59:13 2008
@@ -21,6 +21,8 @@
 
 import org.apache.commons.functor.BaseFunctorTest;
 import org.apache.commons.functor.BinaryPredicate;
+import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.UnaryPredicate;
 import org.apache.commons.functor.core.Constant;
 import org.apache.commons.functor.core.Identity;
 
@@ -63,19 +65,21 @@
     // ------------------------------------------------------------------------
 
     public void testEvaluate() throws Exception {
-        BinaryPredicate p = new IgnoreLeftPredicate(new UnaryFunctionUnaryPredicate(new Identity()));
+        BinaryPredicate<Object, Boolean> p = new IgnoreLeftPredicate<Object, Boolean>(
+                new UnaryFunctionUnaryPredicate<Boolean>(Identity.<Boolean> instance()));
         assertTrue(p.test(null,Boolean.TRUE));
         assertTrue(!p.test(null,Boolean.FALSE));
     }
 
     public void testEquals() throws Exception {
-        BinaryPredicate p = new IgnoreLeftPredicate(new UnaryFunctionUnaryPredicate(new Identity()));
+        BinaryPredicate<Object, Boolean> p = new IgnoreLeftPredicate<Object, Boolean>(
+                new UnaryFunctionUnaryPredicate<Boolean>(Identity.<Boolean> instance()));
         assertEquals(p,p);
-        assertObjectsAreEqual(p,new IgnoreLeftPredicate(new UnaryFunctionUnaryPredicate(new
Identity())));
-        assertObjectsAreNotEqual(p,new Constant(true));
-        assertObjectsAreNotEqual(p,new IgnoreLeftPredicate(new Constant(false)));
-        assertObjectsAreNotEqual(p,new Constant(false));
-        assertObjectsAreEqual(new IgnoreLeftPredicate(null),new IgnoreLeftPredicate(null));
+        assertObjectsAreEqual(p,new IgnoreLeftPredicate<Object, Boolean>(
+                new UnaryFunctionUnaryPredicate<Boolean>(Identity.<Boolean> instance())));
+        assertObjectsAreNotEqual(p,Constant.TRUE);
+        assertObjectsAreNotEqual(p,new IgnoreLeftPredicate(Constant.FALSE));
+        assertObjectsAreNotEqual(p,Constant.FALSE);
     }
 
     public void testAdaptNull() throws Exception {



Mime
View raw message