commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r666140 - in /commons/sandbox/functor/trunk/src: main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryPredicate.java test/java/org/apache/commons/functor/adapter/TestUnaryFunctionUnaryPredicate.java
Date Tue, 10 Jun 2008 14:50:18 GMT
Author: mbenson
Date: Tue Jun 10 07:50:17 2008
New Revision: 666140

URL: http://svn.apache.org/viewvc?rev=666140&view=rev
Log:
unchecked; IllegalArgumentException on null constructor argument

Modified:
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryPredicate.java
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestUnaryFunctionUnaryPredicate.java

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryPredicate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryPredicate.java?rev=666140&r1=666139&r2=666140&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryPredicate.java
(original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryPredicate.java
Tue Jun 10 07:50:17 2008
@@ -39,14 +39,17 @@
  */
 public final class UnaryFunctionUnaryPredicate<A> implements UnaryPredicate<A>,
Serializable {
     /** The {@link UnaryFunction UnaryFunction} I'm wrapping. */
-    private UnaryFunction<A, Boolean> function;
+    private UnaryFunction<? super A, Boolean> function;
 
     /**
      * Create an {@link UnaryPredicate UnaryPredicate} wrapping
      * the given {@link UnaryFunction UnaryFunction}.
      * @param function the {@link UnaryFunction UnaryFunction} to wrap
      */
-    public UnaryFunctionUnaryPredicate(UnaryFunction<A, Boolean> function) {
+    public UnaryFunctionUnaryPredicate(UnaryFunction<? super A, Boolean> function)
{
+        if (function == null) {
+            throw new IllegalArgumentException("UnaryFunction argument was null");
+        }
         this.function = function;
     }
 
@@ -99,20 +102,22 @@
     }
 
     /**
+     * 
      * Adapt the given, possibly-<code>null</code>,
      * {@link UnaryFunction UnaryFunction} to the
      * {@link UnaryPredicate UnaryPredicate} interface.
      * When the given <code>UnaryFunction</code> is <code>null</code>,
      * returns <code>null</code>.
      *
+     * @param <A>
      * @param function the possibly-<code>null</code>
      *        {@link UnaryFunction UnaryFunction} to adapt
      * @return a {@link UnaryPredicate UnaryPredicate} wrapping the given
      *         {@link UnaryFunction UnaryFunction}, or <code>null</code>
      *         if the given <code>UnaryFunction</code> is <code>null</code>
      */
-    public static <P> UnaryFunctionUnaryPredicate<P> adapt(UnaryFunction<P,
Boolean> function) {
-        return null == function ? null : new UnaryFunctionUnaryPredicate<P>(function);
+    public static <A> UnaryFunctionUnaryPredicate<A> adapt(UnaryFunction<?
super A, Boolean> function) {
+        return null == function ? null : new UnaryFunctionUnaryPredicate<A>(function);
     }
 
 }

Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestUnaryFunctionUnaryPredicate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestUnaryFunctionUnaryPredicate.java?rev=666140&r1=666139&r2=666140&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestUnaryFunctionUnaryPredicate.java
(original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestUnaryFunctionUnaryPredicate.java
Tue Jun 10 07:50:17 2008
@@ -44,7 +44,7 @@
     // ------------------------------------------------------------------------
 
     protected Object makeFunctor() {
-        return new UnaryFunctionUnaryPredicate(new Constant(Boolean.TRUE));
+        return new UnaryFunctionUnaryPredicate<Object>(Constant.TRUE);
     }
 
     // Lifecycle
@@ -62,43 +62,21 @@
     // ------------------------------------------------------------------------
 
     public void testTestWhenTrue() throws Exception {
-        UnaryPredicate p = new UnaryFunctionUnaryPredicate(new Constant(Boolean.TRUE));
+        UnaryPredicate<Object> p = new UnaryFunctionUnaryPredicate<Object>(Constant.TRUE);
         assertTrue(p.test(null));
     }
 
     public void testTestWhenFalse() throws Exception {
-        UnaryPredicate p = new UnaryFunctionUnaryPredicate(new Constant(Boolean.FALSE));
+        UnaryPredicate<Object> p = new UnaryFunctionUnaryPredicate<Object>(Constant.FALSE);
         assertTrue(!p.test(null));
     }
 
-    public void testTestWhenNull() throws Exception {
-        UnaryPredicate p = new UnaryFunctionUnaryPredicate(new Constant(null));
-        try {
-            p.test("xyzzy");
-            fail("Expected NullPointerException");
-        } catch(NullPointerException e) {
-            // expected
-        }
-    }
-
-    public void testTestWhenNonBoolean() throws Exception {
-        UnaryPredicate p = new UnaryFunctionUnaryPredicate(new Constant(new Integer(2)));
-        try {
-            p.test("xyzzy");
-            fail("Expected ClassCastException");
-        } catch(ClassCastException e) {
-            // expected
-        }
-    }
-
     public void testEquals() throws Exception {
-        UnaryPredicate p = new UnaryFunctionUnaryPredicate(new Constant(Boolean.TRUE));
+        UnaryPredicate<Object> p = new UnaryFunctionUnaryPredicate<Object>(Constant.TRUE);
         assertEquals(p,p);
-        assertObjectsAreEqual(p,new UnaryFunctionUnaryPredicate(new Constant(Boolean.TRUE)));
-        assertObjectsAreNotEqual(p,Constant.truePredicate());
-        assertObjectsAreNotEqual(p,new UnaryFunctionUnaryPredicate(null));
-        assertObjectsAreNotEqual(p,new UnaryFunctionUnaryPredicate(new Constant(Boolean.FALSE)));
-        assertObjectsAreEqual(new UnaryFunctionUnaryPredicate(null),new UnaryFunctionUnaryPredicate(null));
+        assertObjectsAreEqual(p,new UnaryFunctionUnaryPredicate<Object>(Constant.TRUE));
+        assertObjectsAreNotEqual(p,Constant.TRUE);
+        assertObjectsAreNotEqual(p,new UnaryFunctionUnaryPredicate<Object>(Constant.FALSE));
     }
 
     public void testAdaptNull() throws Exception {
@@ -106,6 +84,6 @@
     }
 
     public void testAdapt() throws Exception {
-        assertNotNull(UnaryFunctionUnaryPredicate.adapt(new Constant(Boolean.TRUE)));
+        assertNotNull(UnaryFunctionUnaryPredicate.adapt(Constant.TRUE));
     }
 }



Mime
View raw message