commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r666238 - in /commons/sandbox/functor/trunk/src: main/java/org/apache/commons/functor/adapter/ test/java/org/apache/commons/functor/adapter/
Date Tue, 10 Jun 2008 17:54:56 GMT
Author: mbenson
Date: Tue Jun 10 10:54:56 2008
New Revision: 666238

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

Modified:
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/PredicateFunction.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/PredicateUnaryPredicate.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/ProcedureFunction.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/ProcedureUnaryProcedure.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryProcedure.java
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestPredicateFunction.java
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestPredicateUnaryPredicate.java
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestProcedureFunction.java
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestProcedureUnaryProcedure.java
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestUnaryFunctionUnaryProcedure.java

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/PredicateFunction.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/PredicateFunction.java?rev=666238&r1=666237&r2=666238&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/PredicateFunction.java
(original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/PredicateFunction.java
Tue Jun 10 10:54:56 2008
@@ -46,6 +46,9 @@
      * @param predicate to adapt
      */
     public PredicateFunction(Predicate predicate) {
+        if (predicate == null) {
+            throw new IllegalArgumentException("Predicate argument was null");
+        }
         this.predicate = predicate;
     }
 

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/PredicateUnaryPredicate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/PredicateUnaryPredicate.java?rev=666238&r1=666237&r2=666238&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/PredicateUnaryPredicate.java
(original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/PredicateUnaryPredicate.java
Tue Jun 10 10:54:56 2008
@@ -47,6 +47,9 @@
      * @param predicate to adapt
      */
     public PredicateUnaryPredicate(Predicate predicate) {
+        if (predicate == null) {
+            throw new IllegalArgumentException("Predicate argument was null");
+        }
         this.predicate = predicate;
     }
 

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/ProcedureFunction.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/ProcedureFunction.java?rev=666238&r1=666237&r2=666238&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/ProcedureFunction.java
(original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/ProcedureFunction.java
Tue Jun 10 10:54:56 2008
@@ -47,6 +47,9 @@
      * @param procedure to adapt
      */
     public ProcedureFunction(Procedure procedure) {
+        if (procedure == null) {
+            throw new IllegalArgumentException("Procedure argument was null");
+        }
         this.procedure = procedure;
     }
 

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/ProcedureUnaryProcedure.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/ProcedureUnaryProcedure.java?rev=666238&r1=666237&r2=666238&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/ProcedureUnaryProcedure.java
(original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/ProcedureUnaryProcedure.java
Tue Jun 10 10:54:56 2008
@@ -47,6 +47,9 @@
      * @param procedure to adapt
      */
     public ProcedureUnaryProcedure(Procedure procedure) {
+        if (procedure == null) {
+            throw new IllegalArgumentException("Procedure argument was null");
+        }
         this.procedure = procedure;
     }
 

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryProcedure.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryProcedure.java?rev=666238&r1=666237&r2=666238&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryProcedure.java
(original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryProcedure.java
Tue Jun 10 10:54:56 2008
@@ -48,6 +48,9 @@
      * @param function the {@link UnaryFunction UnaryFunction} to wrap
      */
     public UnaryFunctionUnaryProcedure(UnaryFunction<? super A, ?> function) {
+        if (function == null) {
+            throw new IllegalArgumentException("UnaryFunction argument was null");
+        }
         this.function = function;
     }
 

Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestPredicateFunction.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestPredicateFunction.java?rev=666238&r1=666237&r2=666238&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestPredicateFunction.java
(original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestPredicateFunction.java
Tue Jun 10 10:54:56 2008
@@ -44,7 +44,7 @@
     // ------------------------------------------------------------------------
 
     protected Object makeFunctor() {
-        return new PredicateFunction(new Constant(true));
+        return new PredicateFunction(Constant.of(true));
     }
 
     // Lifecycle
@@ -62,23 +62,21 @@
     // ------------------------------------------------------------------------
 
     public void testTestWhenTrue() throws Exception {
-        Function f = new PredicateFunction(new Constant(true));
+        Function<Boolean> f = new PredicateFunction(Constant.TRUE);
         assertEquals(Boolean.TRUE,f.evaluate());
     }
 
     public void testTestWhenFalse() throws Exception {
-        Function f = new PredicateFunction(new Constant(false));
+        Function<Boolean> f = new PredicateFunction(Constant.FALSE);
         assertEquals(Boolean.FALSE,f.evaluate());
     }
 
     public void testEquals() throws Exception {
-        Function f = new PredicateFunction(new Constant(true));
+        Function<Boolean> f = new PredicateFunction(Constant.TRUE);
         assertEquals(f,f);
-        assertObjectsAreEqual(f,new PredicateFunction(new Constant(true)));
-        assertObjectsAreNotEqual(f,new Constant("x"));
-        assertObjectsAreNotEqual(f,new PredicateFunction(new Constant(false)));
-        assertObjectsAreNotEqual(f,new PredicateFunction(null));
-        assertObjectsAreEqual(new PredicateFunction(null),new PredicateFunction(null));
+        assertObjectsAreEqual(f,new PredicateFunction(Constant.TRUE));
+        assertObjectsAreNotEqual(f,Constant.of("x"));
+        assertObjectsAreNotEqual(f,new PredicateFunction(Constant.FALSE));
     }
 
     public void testAdaptNull() throws Exception {
@@ -86,6 +84,6 @@
     }
 
     public void testAdapt() throws Exception {
-        assertNotNull(PredicateFunction.adapt(new Constant(true)));
+        assertNotNull(PredicateFunction.adapt(Constant.TRUE));
     }
 }

Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestPredicateUnaryPredicate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestPredicateUnaryPredicate.java?rev=666238&r1=666237&r2=666238&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestPredicateUnaryPredicate.java
(original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestPredicateUnaryPredicate.java
Tue Jun 10 10:54:56 2008
@@ -44,7 +44,7 @@
     // ------------------------------------------------------------------------
 
     protected Object makeFunctor() {
-        return new PredicateUnaryPredicate(new Constant(true));
+        return new PredicateUnaryPredicate(Constant.TRUE);
     }
 
     // Lifecycle
@@ -62,18 +62,17 @@
     // ------------------------------------------------------------------------
 
     public void testEvaluate() throws Exception {
-        UnaryPredicate p = new PredicateUnaryPredicate(new Constant(true));
+        UnaryPredicate<Object> p = new PredicateUnaryPredicate<Object>(Constant.TRUE);
         assertTrue(p.test(null));
     }
 
     public void testEquals() throws Exception {
-        UnaryPredicate p = new PredicateUnaryPredicate(new Constant(true));
+        UnaryPredicate<Object> p = new PredicateUnaryPredicate<Object>(Constant.TRUE);
         assertEquals(p,p);
-        assertObjectsAreEqual(p,new PredicateUnaryPredicate(new Constant(true)));
-        assertObjectsAreNotEqual(p,new Constant(true));
-        assertObjectsAreNotEqual(p,new PredicateUnaryPredicate(new Constant(false)));
-        assertObjectsAreNotEqual(p,new Constant(false));
-        assertObjectsAreEqual(new PredicateUnaryPredicate(null),new PredicateUnaryPredicate(null));
+        assertObjectsAreEqual(p,new PredicateUnaryPredicate<Object>(Constant.TRUE));
+        assertObjectsAreNotEqual(p,Constant.TRUE);
+        assertObjectsAreNotEqual(p,new PredicateUnaryPredicate<Object>(Constant.FALSE));
+        assertObjectsAreNotEqual(p,Constant.FALSE);
     }
 
     public void testAdaptNull() throws Exception {
@@ -81,6 +80,6 @@
     }
 
     public void testAdapt() throws Exception {
-        assertNotNull(PredicateUnaryPredicate.adapt(new Constant(true)));
+        assertNotNull(PredicateUnaryPredicate.adapt(Constant.TRUE));
     }
 }

Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestProcedureFunction.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestProcedureFunction.java?rev=666238&r1=666237&r2=666238&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestProcedureFunction.java
(original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestProcedureFunction.java
Tue Jun 10 10:54:56 2008
@@ -46,7 +46,7 @@
     // ------------------------------------------------------------------------
 
     protected Object makeFunctor() {
-        return new ProcedureFunction(new NoOp());
+        return new ProcedureFunction<Object>(NoOp.INSTANCE);
     }
 
     // Lifecycle
@@ -64,19 +64,17 @@
     // ------------------------------------------------------------------------
 
     public void testEvaluate() throws Exception {
-        Function f = new ProcedureFunction(new NoOp());
+        Function<Object> f = new ProcedureFunction<Object>(NoOp.INSTANCE);
         assertNull(f.evaluate());
     }
 
     public void testEquals() throws Exception {
-        Function f = new ProcedureFunction(new NoOp());
+        Function<Object> f = new ProcedureFunction<Object>(NoOp.INSTANCE);
         assertEquals(f,f);
-        assertObjectsAreEqual(f,new ProcedureFunction(new NoOp()));
-        assertObjectsAreNotEqual(f,new Constant("x"));
-        assertObjectsAreNotEqual(f,new ProcedureFunction(new Procedure() { public void run()
{ } }));
-        assertObjectsAreNotEqual(f,new Constant(null));
-        assertObjectsAreNotEqual(f,new ProcedureFunction(null));
-        assertObjectsAreEqual(new ProcedureFunction(null),new ProcedureFunction(null));
+        assertObjectsAreEqual(f,new ProcedureFunction<Object>(NoOp.INSTANCE));
+        assertObjectsAreNotEqual(f,Constant.of("x"));
+        assertObjectsAreNotEqual(f,new ProcedureFunction<Object>(new Procedure() {
public void run() { } }));
+        assertObjectsAreNotEqual(f,Constant.of(null));
     }
 
     public void testAdaptNull() throws Exception {

Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestProcedureUnaryProcedure.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestProcedureUnaryProcedure.java?rev=666238&r1=666237&r2=666238&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestProcedureUnaryProcedure.java
(original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestProcedureUnaryProcedure.java
Tue Jun 10 10:54:56 2008
@@ -45,7 +45,7 @@
     // ------------------------------------------------------------------------
 
     protected Object makeFunctor() {
-        return new ProcedureUnaryProcedure(new NoOp());
+        return new ProcedureUnaryProcedure<Object>(NoOp.INSTANCE);
     }
 
     // Lifecycle
@@ -63,17 +63,15 @@
     // ------------------------------------------------------------------------
 
     public void testEvaluate() throws Exception {
-        UnaryProcedure p = new ProcedureUnaryProcedure(new FunctionProcedure(new Constant(null)));
+        UnaryProcedure<Object> p = new ProcedureUnaryProcedure<Object>(new FunctionProcedure(Constant.of(null)));
         p.run(Boolean.TRUE);
     }
 
     public void testEquals() throws Exception {
-        UnaryProcedure p = new ProcedureUnaryProcedure(new NoOp());
+        UnaryProcedure<Object> p = new ProcedureUnaryProcedure<Object>(NoOp.INSTANCE);
         assertEquals(p,p);
-        assertObjectsAreEqual(p,new ProcedureUnaryProcedure(new NoOp()));
-        assertObjectsAreNotEqual(p,new NoOp());
-        assertObjectsAreNotEqual(p,new ProcedureUnaryProcedure(null));
-        assertObjectsAreEqual(new ProcedureUnaryProcedure(null),new ProcedureUnaryProcedure(null));
+        assertObjectsAreEqual(p,new ProcedureUnaryProcedure<Object>(NoOp.INSTANCE));
+        assertObjectsAreNotEqual(p,NoOp.INSTANCE);
     }
 
     public void testAdaptNull() throws Exception {
@@ -81,6 +79,6 @@
     }
 
     public void testAdapt() throws Exception {
-        assertNotNull(ProcedureUnaryProcedure.adapt(new NoOp()));
+        assertNotNull(ProcedureUnaryProcedure.adapt(NoOp.INSTANCE));
     }
 }

Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestUnaryFunctionUnaryProcedure.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestUnaryFunctionUnaryProcedure.java?rev=666238&r1=666237&r2=666238&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestUnaryFunctionUnaryProcedure.java
(original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestUnaryFunctionUnaryProcedure.java
Tue Jun 10 10:54:56 2008
@@ -46,7 +46,7 @@
     // ------------------------------------------------------------------------
 
     protected Object makeFunctor() {
-        return new UnaryFunctionUnaryProcedure(new Constant("K"));
+        return new UnaryFunctionUnaryProcedure<Object>(Constant.of("K"));
     }
 
     // Lifecycle
@@ -64,12 +64,12 @@
     // ------------------------------------------------------------------------
 
     public void testRun() throws Exception {
-        class EvaluateCounter implements UnaryFunction {
+        class EvaluateCounter implements UnaryFunction<Object, Integer> {
             int count = 0;
-            public Object evaluate(Object a) { return new Integer(count++); }
+            public Integer evaluate(Object a) { return count++; }
         }
         EvaluateCounter counter = new EvaluateCounter();
-        UnaryProcedure p = new UnaryFunctionUnaryProcedure(counter);
+        UnaryProcedure<Object> p = new UnaryFunctionUnaryProcedure<Object>(counter);
         assertEquals(0,counter.count);
         p.run(null);
         assertEquals(1,counter.count);
@@ -78,13 +78,11 @@
     }
 
     public void testEquals() throws Exception {
-        UnaryProcedure p = new UnaryFunctionUnaryProcedure(new Constant("K"));
+        UnaryProcedure<Object> p = new UnaryFunctionUnaryProcedure<Object>(Constant.of("K"));
         assertEquals(p,p);
-        assertObjectsAreEqual(p,new UnaryFunctionUnaryProcedure(new Constant("K")));
-        assertObjectsAreNotEqual(p,new NoOp());
-        assertObjectsAreNotEqual(p,new UnaryFunctionUnaryProcedure(null));
-        assertObjectsAreNotEqual(p,new UnaryFunctionUnaryProcedure(new Constant("J")));
-        assertObjectsAreEqual(new UnaryFunctionUnaryProcedure(null),new UnaryFunctionUnaryProcedure(null));
+        assertObjectsAreEqual(p,new UnaryFunctionUnaryProcedure<Object>(Constant.of("K")));
+        assertObjectsAreNotEqual(p,NoOp.INSTANCE);
+        assertObjectsAreNotEqual(p,new UnaryFunctionUnaryProcedure<Object>(Constant.of("J")));
     }
 
     public void testAdaptNull() throws Exception {
@@ -92,6 +90,6 @@
     }
 
     public void testAdapt() throws Exception {
-        assertNotNull(UnaryFunctionUnaryProcedure.adapt(new Constant("K")));
+        assertNotNull(UnaryFunctionUnaryProcedure.adapt(Constant.of("K")));
     }
 }



Mime
View raw message