commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r666173 - 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 15:57:17 GMT
Author: mbenson
Date: Tue Jun 10 08:57:17 2008
New Revision: 666173

URL: http://svn.apache.org/viewvc?rev=666173&view=rev
Log:
unchecked warnings; throw IllegalArgumentException on null constructor args; fully genericize
BinaryFunctor<L, R>

Modified:
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftProcedure.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/IgnoreRightProcedure.java
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestIgnoreLeftProcedure.java
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestIgnoreRightProcedure.java

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

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/IgnoreRightProcedure.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/IgnoreRightProcedure.java?rev=666173&r1=666172&r2=666173&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/IgnoreRightProcedure.java
(original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/IgnoreRightProcedure.java
Tue Jun 10 08:57:17 2008
@@ -38,22 +38,25 @@
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
-public final class IgnoreRightProcedure<A> implements BinaryProcedure<A, Object>,
Serializable {
+public final class IgnoreRightProcedure<L, R> implements BinaryProcedure<L, R>,
Serializable {
     /** The {@link UnaryProcedure UnaryProcedure} I'm wrapping. */
-    private UnaryProcedure<? super A> procedure;
+    private UnaryProcedure<? super L> procedure;
 
     /**
      * Create a new IgnoreRightProcedure.
      * @param procedure UnaryProcedure to adapt
      */
-    public IgnoreRightProcedure(UnaryProcedure<? super A> procedure) {
+    public IgnoreRightProcedure(UnaryProcedure<? super L> procedure) {
+        if (procedure == null) {
+            throw new IllegalArgumentException("UnaryProcedure argument was null");
+        }
         this.procedure = procedure;
     }
 
     /**
      * {@inheritDoc}
      */
-    public void run(A left, Object right) {
+    public void run(L left, R right) {
         procedure.run(left);
     }
 
@@ -61,7 +64,7 @@
      * {@inheritDoc}
      */
     public boolean equals(Object that) {
-        return that == this || (that instanceof IgnoreRightProcedure && equals((IgnoreRightProcedure<?>)
that));
+        return that == this || (that instanceof IgnoreRightProcedure && equals((IgnoreRightProcedure<?,
?>) that));
     }
 
     /**
@@ -69,7 +72,7 @@
      * @param that IgnoreRightProcedure to test
      * @return boolean
      */
-    public boolean equals(IgnoreRightProcedure<?> that) {
+    public boolean equals(IgnoreRightProcedure<?, ?> that) {
         return null != that && (null == procedure ? null == that.procedure : procedure.equals(that.procedure));
     }
 
@@ -96,8 +99,8 @@
      * @param procedure UnaryProcedure to adapt
      * @return IgnoreRightProcedure
      */
-    public static <A> IgnoreRightProcedure<A> adapt(UnaryProcedure<? super
A> procedure) {
-        return null == procedure ? null : new IgnoreRightProcedure<A>(procedure);
+    public static <L, R> IgnoreRightProcedure<L, R> adapt(UnaryProcedure<?
super L> procedure) {
+        return null == procedure ? null : new IgnoreRightProcedure<L, R>(procedure);
     }
 
 }

Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestIgnoreLeftProcedure.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestIgnoreLeftProcedure.java?rev=666173&r1=666172&r2=666173&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestIgnoreLeftProcedure.java
(original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestIgnoreLeftProcedure.java
Tue Jun 10 08:57:17 2008
@@ -45,7 +45,7 @@
     // ------------------------------------------------------------------------
 
     protected Object makeFunctor() {
-        return new IgnoreLeftProcedure(new NoOp());
+        return new IgnoreLeftProcedure<Object, Object>(NoOp.INSTANCE);
     }
 
     // Lifecycle
@@ -63,17 +63,16 @@
     // ------------------------------------------------------------------------
 
     public void testEvaluate() throws Exception {
-        BinaryProcedure p = new IgnoreLeftProcedure(new UnaryFunctionUnaryProcedure(new Identity()));
+        BinaryProcedure<Object, Object> p = new IgnoreLeftProcedure<Object, Object>(
+                new UnaryFunctionUnaryProcedure<Object>(Identity.INSTANCE));
         p.run(null,Boolean.TRUE);
     }
 
     public void testEquals() throws Exception {
-        BinaryProcedure p = new IgnoreLeftProcedure(new NoOp());
+        BinaryProcedure<Object, Object> p = new IgnoreLeftProcedure<Object, Object>(NoOp.INSTANCE);
         assertEquals(p,p);
-        assertObjectsAreEqual(p,new IgnoreLeftProcedure(new NoOp()));
-        assertObjectsAreNotEqual(p,new NoOp());
-        assertObjectsAreNotEqual(p,new IgnoreLeftProcedure(null));
-        assertObjectsAreEqual(new IgnoreLeftProcedure(null),new IgnoreLeftProcedure(null));
+        assertObjectsAreEqual(p,new IgnoreLeftProcedure<Object, Object>(NoOp.INSTANCE));
+        assertObjectsAreNotEqual(p,NoOp.INSTANCE);
     }
 
     public void testAdaptNull() throws Exception {
@@ -81,6 +80,6 @@
     }
 
     public void testAdapt() throws Exception {
-        assertNotNull(IgnoreLeftProcedure.adapt(new NoOp()));
+        assertNotNull(IgnoreLeftProcedure.adapt(NoOp.INSTANCE));
     }
 }

Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestIgnoreRightProcedure.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestIgnoreRightProcedure.java?rev=666173&r1=666172&r2=666173&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestIgnoreRightProcedure.java
(original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestIgnoreRightProcedure.java
Tue Jun 10 08:57:17 2008
@@ -45,7 +45,7 @@
     // ------------------------------------------------------------------------
 
     protected Object makeFunctor() {
-        return new IgnoreRightProcedure(new NoOp());
+        return new IgnoreRightProcedure<Object, Object>(NoOp.INSTANCE);
     }
 
     // Lifecycle
@@ -63,17 +63,16 @@
     // ------------------------------------------------------------------------
 
     public void testEvaluate() throws Exception {
-        BinaryProcedure p = new IgnoreRightProcedure(new UnaryFunctionUnaryProcedure(new
Identity()));
+        BinaryProcedure<Object, Object> p = new IgnoreRightProcedure<Object, Object>(
+                new UnaryFunctionUnaryProcedure<Object>(Identity.INSTANCE));
         p.run(Boolean.TRUE,null);
     }
 
     public void testEquals() throws Exception {
-        BinaryProcedure p = new IgnoreRightProcedure(new NoOp());
+        BinaryProcedure<Object, Object> p = new IgnoreRightProcedure<Object, Object>(NoOp.INSTANCE);
         assertEquals(p,p);
-        assertObjectsAreEqual(p,new IgnoreRightProcedure(new NoOp()));
-        assertObjectsAreNotEqual(p,new NoOp());
-        assertObjectsAreNotEqual(p,new IgnoreRightProcedure(null));
-        assertObjectsAreEqual(new IgnoreRightProcedure(null),new IgnoreRightProcedure(null));
+        assertObjectsAreEqual(p,new IgnoreRightProcedure<Object, Object>(NoOp.INSTANCE));
+        assertObjectsAreNotEqual(p,NoOp.INSTANCE);
     }
 
     public void testAdaptNull() throws Exception {
@@ -81,6 +80,6 @@
     }
 
     public void testAdapt() throws Exception {
-        assertNotNull(IgnoreRightProcedure.adapt(new NoOp()));
+        assertNotNull(IgnoreRightProcedure.adapt(NoOp.INSTANCE));
     }
 }



Mime
View raw message