commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r666220 - in /commons/sandbox/functor/trunk/src: main/java/org/apache/commons/functor/core/composite/ test/java/org/apache/commons/functor/core/composite/
Date Tue, 10 Jun 2008 17:20:19 GMT
Author: mbenson
Date: Tue Jun 10 10:20:19 2008
New Revision: 666220

URL: http://svn.apache.org/viewvc?rev=666220&view=rev
Log:
unchecked warnings; IllegalArgumentExceptions on null constructor args

Modified:
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalFunction.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalPredicate.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalProcedure.java
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalFunction.java
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalPredicate.java
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalProcedure.java

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalFunction.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalFunction.java?rev=666220&r1=666219&r2=666220&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalFunction.java
(original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalFunction.java
Tue Jun 10 10:20:19 2008
@@ -57,7 +57,13 @@
      * @param elseFunc else
      */
     public ConditionalFunction(Predicate ifPred, Function<? extends T> thenFunc, Function<?
extends T> elseFunc) {
+        if (ifPred == null) {
+            throw new IllegalArgumentException("Predicate argument was null");
+        }
         this.ifPred = ifPred;
+        if (thenFunc == null || elseFunc == null) {
+            throw new IllegalArgumentException("One or more Function arguments was null");
+        }
         this.thenFunc = thenFunc;
         this.elseFunc = elseFunc;
     }

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalPredicate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalPredicate.java?rev=666220&r1=666219&r2=666220&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalPredicate.java
(original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalPredicate.java
Tue Jun 10 10:20:19 2008
@@ -56,6 +56,9 @@
      * @param elsePred else
      */
     public ConditionalPredicate(Predicate ifPred, Predicate thenPred, Predicate elsePred)
{
+        if (ifPred == null || thenPred == null || elsePred == null) {
+            throw new IllegalArgumentException("One or more Predicate arguments was null");
+        }
         this.ifPred = ifPred;
         this.thenPred = thenPred;
         this.elsePred = elsePred;

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalProcedure.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalProcedure.java?rev=666220&r1=666219&r2=666220&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalProcedure.java
(original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalProcedure.java
Tue Jun 10 10:20:19 2008
@@ -66,7 +66,13 @@
      * @param elseProc else
      */
     public ConditionalProcedure(Predicate ifPred, Procedure thenProc, Procedure elseProc)
{
+        if (ifPred == null) {
+            throw new IllegalArgumentException("Predicate argument was null");
+        }
         this.ifPred = ifPred;
+        if (thenProc == null || elseProc == null) {
+            throw new IllegalArgumentException("Procedure argument was null");
+        }
         this.thenProc = thenProc;
         this.elseProc = elseProc;
     }

Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalFunction.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalFunction.java?rev=666220&r1=666219&r2=666220&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalFunction.java
(original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalFunction.java
Tue Jun 10 10:20:19 2008
@@ -43,10 +43,10 @@
     // ------------------------------------------------------------------------
 
     protected Object makeFunctor() {
-        return new ConditionalFunction(
-            new Constant(true),
-            new Constant("left"),
-            new Constant("right"));
+        return new ConditionalFunction<Object>(
+            Constant.TRUE,
+            Constant.of("left"),
+            Constant.of("right"));
     }
 
     // Lifecycle
@@ -65,50 +65,38 @@
 
     public void testEvaluate() throws Exception {
         {
-            ConditionalFunction f = new ConditionalFunction(
-                new Constant(true),
-                new Constant("left"),
-                new Constant("right"));
+            ConditionalFunction<Object> f = new ConditionalFunction<Object>(
+                Constant.TRUE,
+                Constant.of("left"),
+                Constant.of("right"));
             assertEquals("left",f.evaluate());
         }
         {
-            ConditionalFunction f = new ConditionalFunction(
-                new Constant(false),
-                new Constant("left"),
-                new Constant("right"));
+            ConditionalFunction<Object> f = new ConditionalFunction<Object>(
+                Constant.FALSE,
+                Constant.of("left"),
+                Constant.of("right"));
             assertEquals("right",f.evaluate());
         }
     }
 
     public void testEquals() throws Exception {
-        ConditionalFunction f = new ConditionalFunction(
-            new Constant(true),
-            new Constant("left"),
-            new Constant("right"));
+        ConditionalFunction<Object> f = new ConditionalFunction<Object>(
+            Constant.TRUE,
+            Constant.of("left"),
+            Constant.of("right"));
         assertEquals(f,f);
-        assertObjectsAreEqual(f,new ConditionalFunction(
-            new Constant(true),
-            new Constant("left"),
-            new Constant("right")));
-        assertObjectsAreNotEqual(f,new ConditionalFunction(
-            new Constant(true),
-            new Constant(null),
-            new Constant("right")));
-        assertObjectsAreNotEqual(f,new ConditionalFunction(
-            new Constant(true),
-            new Constant("left"),
-            new Constant(null)));
-        assertObjectsAreNotEqual(f,new ConditionalFunction(
-            null,
-            new Constant("left"),
-            new Constant("right")));
-        assertObjectsAreNotEqual(f,new ConditionalFunction(
-            new Constant(true),
-            null,
-            new Constant("right")));
-        assertObjectsAreNotEqual(f,new ConditionalFunction(
-            new Constant(true),
-            new Constant("left"),
-            null));
+        assertObjectsAreEqual(f,new ConditionalFunction<Object>(
+            Constant.TRUE,
+            Constant.of("left"),
+            Constant.of("right")));
+        assertObjectsAreNotEqual(f,new ConditionalFunction<Object>(
+            Constant.TRUE,
+            Constant.of(null),
+            Constant.of("right")));
+        assertObjectsAreNotEqual(f,new ConditionalFunction<Object>(
+            Constant.TRUE,
+            Constant.of("left"),
+            Constant.of(null)));
     }
 }

Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalPredicate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalPredicate.java?rev=666220&r1=666219&r2=666220&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalPredicate.java
(original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalPredicate.java
Tue Jun 10 10:20:19 2008
@@ -44,9 +44,9 @@
 
     protected Object makeFunctor() {
         return new ConditionalPredicate(
-            new Constant(true),
-            new Constant(false),
-            new Constant(true));
+            Constant.TRUE,
+            Constant.FALSE,
+            Constant.TRUE);
     }
 
     // Lifecycle
@@ -66,49 +66,37 @@
     public void testTest() throws Exception {
         {
             ConditionalPredicate p = new ConditionalPredicate(
-                new Constant(true),
-                new Constant(true),
-                new Constant(false));
+                Constant.TRUE,
+                Constant.TRUE,
+                Constant.FALSE);
             assertTrue(p.test());
         }
         {
             ConditionalPredicate p = new ConditionalPredicate(
-                new Constant(false),
-                new Constant(true),
-                new Constant(false));
+                Constant.FALSE,
+                Constant.TRUE,
+                Constant.FALSE);
             assertTrue(!p.test());
         }
     }
 
     public void testEquals() throws Exception {
         ConditionalPredicate p = new ConditionalPredicate(
-            new Constant(true),
-            new Constant(true),
-            new Constant(false));
+            Constant.TRUE,
+            Constant.TRUE,
+            Constant.FALSE);
         assertEquals(p,p);
         assertObjectsAreEqual(p,new ConditionalPredicate(
-            new Constant(true),
-            new Constant(true),
-            new Constant(false)));
+            Constant.TRUE,
+            Constant.TRUE,
+            Constant.FALSE));
         assertObjectsAreNotEqual(p,new ConditionalPredicate(
-            new Constant(true),
-            new Constant(false),
-            new Constant(true)));
+            Constant.TRUE,
+            Constant.FALSE,
+            Constant.TRUE));
         assertObjectsAreNotEqual(p,new ConditionalPredicate(
-            new Constant(true),
-            new Constant(true),
-            new Constant(true)));
-        assertObjectsAreNotEqual(p,new ConditionalPredicate(
-            null,
-            new Constant(true),
-            new Constant(true)));
-        assertObjectsAreNotEqual(p,new ConditionalPredicate(
-            new Constant(true),
-            null,
-            new Constant(true)));
-        assertObjectsAreNotEqual(p,new ConditionalPredicate(
-            new Constant(true),
-            new Constant(true),
-            null));
+            Constant.TRUE,
+            Constant.TRUE,
+            Constant.TRUE));
     }
 }

Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalProcedure.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalProcedure.java?rev=666220&r1=666219&r2=666220&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalProcedure.java
(original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalProcedure.java
Tue Jun 10 10:20:19 2008
@@ -46,9 +46,9 @@
 
     protected Object makeFunctor() {
         return new ConditionalProcedure(
-            new Constant(true),
-            new NoOp(),
-            new NoOp());
+            Constant.TRUE,
+            NoOp.INSTANCE,
+            NoOp.INSTANCE);
     }
 
     // Lifecycle
@@ -70,7 +70,7 @@
             RunCounter left = new RunCounter();
             RunCounter right = new RunCounter();
             ConditionalProcedure p = new ConditionalProcedure(
-                new Constant(true),
+                Constant.TRUE,
                 left,
                 right);
             assertEquals(0,left.count);
@@ -89,7 +89,7 @@
             RunCounter left = new RunCounter();
             RunCounter right = new RunCounter();
             ConditionalProcedure p = new ConditionalProcedure(
-                new Constant(false),
+                Constant.FALSE,
                 left,
                 right);
             assertEquals(0,left.count);
@@ -108,30 +108,18 @@
 
     public void testEquals() throws Exception {
         ConditionalProcedure p = new ConditionalProcedure(
-            new Constant(false),
-            new NoOp(),
-            new NoOp());
+            Constant.FALSE,
+            NoOp.INSTANCE,
+            NoOp.INSTANCE);
         assertEquals(p,p);
         assertObjectsAreEqual(p,new ConditionalProcedure(
-            new Constant(false),
-            new NoOp(),
-            new NoOp()));
+            Constant.FALSE,
+            NoOp.INSTANCE,
+            NoOp.INSTANCE));
         assertObjectsAreNotEqual(p,new ConditionalProcedure(
-            new Constant(true),
-            new NoOp(),
-            new NoOp()));
-        assertObjectsAreNotEqual(p,new ConditionalProcedure(
-            null,
-            new NoOp(),
-            new NoOp()));
-        assertObjectsAreNotEqual(p,new ConditionalProcedure(
-            new Constant(false),
-            null,
-            new NoOp()));
-        assertObjectsAreNotEqual(p,new ConditionalProcedure(
-            new Constant(false),
-            new NoOp(),
-            null));
+            Constant.TRUE,
+            NoOp.INSTANCE,
+            NoOp.INSTANCE));
     }
 
     // Classes



Mime
View raw message