You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mb...@apache.org on 2008/06/10 19:08:54 UTC
svn commit: r666209 - in /commons/sandbox/functor/trunk/src:
main/java/org/apache/commons/functor/core/composite/
test/java/org/apache/commons/functor/core/composite/
Author: mbenson
Date: Tue Jun 10 10:08:53 2008
New Revision: 666209
URL: http://svn.apache.org/viewvc?rev=666209&view=rev
Log:
unchecked warnings; IllegalArgumentExceptions on null constructor args
Modified:
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryFunction.java
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryPredicate.java
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryProcedure.java
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryFunction.java
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryPredicate.java
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryProcedure.java
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalBinaryPredicate.java
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryFunction.java
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryPredicate.java
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryProcedure.java
Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryFunction.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryFunction.java?rev=666209&r1=666208&r2=666209&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryFunction.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryFunction.java Tue Jun 10 10:08:53 2008
@@ -60,10 +60,10 @@
BinaryFunction<? super L, ? super R, ? extends T> thenFunc,
BinaryFunction<? super L, ? super R, ? extends T> elseFunc) {
if (ifPred == null) {
- throw new IllegalArgumentException("test predicate must not be null");
+ throw new IllegalArgumentException("BinaryPredicate argument was null");
}
if (thenFunc == null || elseFunc == null) {
- throw new IllegalArgumentException("neither resulting function may be null");
+ throw new IllegalArgumentException("One or more BinaryFunction arguments was null");
}
this.ifPred = ifPred;
this.thenFunc = thenFunc;
Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryPredicate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryPredicate.java?rev=666209&r1=666208&r2=666209&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryPredicate.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryPredicate.java Tue Jun 10 10:08:53 2008
@@ -57,6 +57,9 @@
*/
public ConditionalBinaryPredicate(BinaryPredicate<? super L, ? super R> ifPred,
BinaryPredicate<? super L, ? super R> thenPred, BinaryPredicate<? super L, ? super R> elsePred) {
+ if (ifPred == null || thenPred == null || elsePred == null) {
+ throw new IllegalArgumentException("One or more BinaryPredicate 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/ConditionalBinaryProcedure.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryProcedure.java?rev=666209&r1=666208&r2=666209&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryProcedure.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryProcedure.java Tue Jun 10 10:08:53 2008
@@ -70,7 +70,13 @@
*/
public ConditionalBinaryProcedure(BinaryPredicate<? super L, ? super R> ifPred,
BinaryProcedure<? super L, ? super R> thenProc, BinaryProcedure<? super L, ? super R> elseProc) {
+ if (ifPred == null) {
+ throw new IllegalArgumentException("BinaryPredicate argument was null");
+ }
this.ifPred = ifPred;
+ if (thenProc == null || elseProc == null) {
+ throw new IllegalArgumentException("One or more BinaryProcedure arguments was null");
+ }
this.thenProc = thenProc;
this.elseProc = elseProc;
}
Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryFunction.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryFunction.java?rev=666209&r1=666208&r2=666209&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryFunction.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryFunction.java Tue Jun 10 10:08:53 2008
@@ -53,14 +53,20 @@
/**
* Create a new ConditionalUnaryFunction.
* @param ifPred if
- * @param thenPred then
- * @param elsePred else
+ * @param thenFunc then
+ * @param elseFunc else
*/
- public ConditionalUnaryFunction(UnaryPredicate<? super A> ifPred, UnaryFunction<? super A, ? extends T> thenPred,
- UnaryFunction<? super A, ? extends T> elsePred) {
+ public ConditionalUnaryFunction(UnaryPredicate<? super A> ifPred, UnaryFunction<? super A, ? extends T> thenFunc,
+ UnaryFunction<? super A, ? extends T> elseFunc) {
+ if (ifPred == null) {
+ throw new IllegalArgumentException("UnaryPredicate argument was null");
+ }
this.ifPred = ifPred;
- this.thenFunc = thenPred;
- this.elseFunc = elsePred;
+ if (thenFunc == null || elseFunc == null) {
+ throw new IllegalArgumentException("One or more UnaryFunction arguments was null");
+ }
+ this.thenFunc = thenFunc;
+ this.elseFunc = elseFunc;
}
// predicate interface
Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryPredicate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryPredicate.java?rev=666209&r1=666208&r2=666209&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryPredicate.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryPredicate.java Tue Jun 10 10:08:53 2008
@@ -57,6 +57,9 @@
*/
public ConditionalUnaryPredicate(UnaryPredicate<? super A> ifPred, UnaryPredicate<? super A> thenPred,
UnaryPredicate<? super A> elsePred) {
+ if (ifPred == null || thenPred == null || elsePred == null) {
+ throw new IllegalArgumentException("One or more UnaryPredicate 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/ConditionalUnaryProcedure.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryProcedure.java?rev=666209&r1=666208&r2=666209&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryProcedure.java (original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryProcedure.java Tue Jun 10 10:08:53 2008
@@ -66,7 +66,13 @@
* @param elseProc else
*/
public ConditionalUnaryProcedure(UnaryPredicate<? super A> ifPred, UnaryProcedure<? super A> thenProc, UnaryProcedure<? super A> elseProc) {
+ if (ifPred == null) {
+ throw new IllegalArgumentException("UnaryPredicate argument was null");
+ }
this.ifPred = ifPred;
+ if (thenProc == null || elseProc == null) {
+ throw new IllegalArgumentException("One or more UnaryProcedure arguments was null");
+ }
this.thenProc = thenProc;
this.elseProc = elseProc;
}
Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalBinaryPredicate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalBinaryPredicate.java?rev=666209&r1=666208&r2=666209&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalBinaryPredicate.java (original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalBinaryPredicate.java Tue Jun 10 10:08:53 2008
@@ -43,10 +43,10 @@
// ------------------------------------------------------------------------
protected Object makeFunctor() {
- return new ConditionalBinaryPredicate(
- new Constant(true),
- new Constant(false),
- new Constant(true));
+ return new ConditionalBinaryPredicate<Object, Object>(
+ Constant.TRUE,
+ Constant.FALSE,
+ Constant.TRUE);
}
// Lifecycle
@@ -65,50 +65,38 @@
public void testTest() throws Exception {
{
- ConditionalBinaryPredicate p = new ConditionalBinaryPredicate(
- new Constant(true),
- new Constant(true),
- new Constant(false));
+ ConditionalBinaryPredicate<Object, Object> p = new ConditionalBinaryPredicate<Object, Object>(
+ Constant.TRUE,
+ Constant.TRUE,
+ Constant.FALSE);
assertTrue(p.test(null,null));
}
{
- ConditionalBinaryPredicate p = new ConditionalBinaryPredicate(
- new Constant(false),
- new Constant(true),
- new Constant(false));
- assertTrue(!p.test(null,null));
+ ConditionalBinaryPredicate<Object, Object> p = new ConditionalBinaryPredicate<Object, Object>(
+ Constant.FALSE,
+ Constant.TRUE,
+ Constant.FALSE);
+ assertFalse(p.test(null,null));
}
}
public void testEquals() throws Exception {
- ConditionalBinaryPredicate p = new ConditionalBinaryPredicate(
- new Constant(true),
- new Constant(true),
- new Constant(false));
+ ConditionalBinaryPredicate<Object, Object> p = new ConditionalBinaryPredicate<Object, Object>(
+ Constant.TRUE,
+ Constant.TRUE,
+ Constant.FALSE);
assertEquals(p,p);
- assertObjectsAreEqual(p,new ConditionalBinaryPredicate(
- new Constant(true),
- new Constant(true),
- new Constant(false)));
- assertObjectsAreNotEqual(p,new ConditionalBinaryPredicate(
- new Constant(true),
- new Constant(false),
- new Constant(true)));
- assertObjectsAreNotEqual(p,new ConditionalBinaryPredicate(
- new Constant(true),
- new Constant(true),
- new Constant(true)));
- assertObjectsAreNotEqual(p,new ConditionalBinaryPredicate(
- null,
- new Constant(true),
- new Constant(true)));
- assertObjectsAreNotEqual(p,new ConditionalBinaryPredicate(
- new Constant(true),
- null,
- new Constant(true)));
- assertObjectsAreNotEqual(p,new ConditionalBinaryPredicate(
- new Constant(true),
- new Constant(true),
- null));
+ assertObjectsAreEqual(p,new ConditionalBinaryPredicate<Object, Object>(
+ Constant.TRUE,
+ Constant.TRUE,
+ Constant.FALSE));
+ assertObjectsAreNotEqual(p,new ConditionalBinaryPredicate<Object, Object>(
+ Constant.TRUE,
+ Constant.FALSE,
+ Constant.TRUE));
+ assertObjectsAreNotEqual(p,new ConditionalBinaryPredicate<Object, Object>(
+ Constant.TRUE,
+ Constant.TRUE,
+ Constant.TRUE));
}
}
Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryFunction.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryFunction.java?rev=666209&r1=666208&r2=666209&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryFunction.java (original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryFunction.java Tue Jun 10 10:08:53 2008
@@ -44,10 +44,10 @@
// ------------------------------------------------------------------------
protected Object makeFunctor() {
- return new ConditionalUnaryFunction(
- new Constant(true),
- new Constant("left"),
- new Constant("right"));
+ return new ConditionalUnaryFunction<Object, Object>(
+ Constant.TRUE,
+ Constant.of("left"),
+ Constant.of("right"));
}
// Lifecycle
@@ -65,43 +65,31 @@
// ------------------------------------------------------------------------
public void testEvaluate() throws Exception {
- ConditionalUnaryFunction f = new ConditionalUnaryFunction(
- new Identity(),
- new Constant("left"),
- new Constant("right"));
+ ConditionalUnaryFunction<Object, Object> f = new ConditionalUnaryFunction<Object, Object>(
+ Identity.INSTANCE,
+ Constant.of("left"),
+ Constant.of("right"));
assertEquals("left",f.evaluate(Boolean.TRUE));
assertEquals("right",f.evaluate(Boolean.FALSE));
}
public void testEquals() throws Exception {
- ConditionalUnaryFunction f = new ConditionalUnaryFunction(
- new Identity(),
- new Constant("left"),
- new Constant("right"));
+ ConditionalUnaryFunction<Object, Object> f = new ConditionalUnaryFunction<Object, Object>(
+ Identity.INSTANCE,
+ Constant.of("left"),
+ Constant.of("right"));
assertEquals(f,f);
- assertObjectsAreEqual(f,new ConditionalUnaryFunction(
- new Identity(),
- new Constant("left"),
- new Constant("right")));
- assertObjectsAreNotEqual(f,new ConditionalUnaryFunction(
- new Identity(),
- new Constant(null),
- new Constant("right")));
- assertObjectsAreNotEqual(f,new ConditionalUnaryFunction(
- new Constant(true),
- new Constant("left"),
- new Constant("right")));
- assertObjectsAreNotEqual(f,new ConditionalUnaryFunction(
- null,
- new Constant("left"),
- new Constant("right")));
- assertObjectsAreNotEqual(f,new ConditionalUnaryFunction(
- new Constant(true),
- null,
- new Constant("right")));
- assertObjectsAreNotEqual(f,new ConditionalUnaryFunction(
- new Constant(true),
- new Constant("left"),
- null));
+ assertObjectsAreEqual(f,new ConditionalUnaryFunction<Object, Object>(
+ Identity.INSTANCE,
+ Constant.of("left"),
+ Constant.of("right")));
+ assertObjectsAreNotEqual(f,new ConditionalUnaryFunction<Object, Object>(
+ Identity.INSTANCE,
+ Constant.of(null),
+ Constant.of("right")));
+ assertObjectsAreNotEqual(f,new ConditionalUnaryFunction<Object, Object>(
+ Constant.TRUE,
+ Constant.of("left"),
+ Constant.of("right")));
}
}
Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryPredicate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryPredicate.java?rev=666209&r1=666208&r2=666209&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryPredicate.java (original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryPredicate.java Tue Jun 10 10:08:53 2008
@@ -44,10 +44,10 @@
// ------------------------------------------------------------------------
protected Object makeFunctor() {
- return new ConditionalUnaryPredicate(
- new Constant(true),
- new Constant(false),
- new Constant(true));
+ return new ConditionalUnaryPredicate<Object>(
+ Constant.TRUE,
+ Constant.FALSE,
+ Constant.TRUE);
}
// Lifecycle
@@ -65,43 +65,31 @@
// ------------------------------------------------------------------------
public void testTest() throws Exception {
- ConditionalUnaryPredicate p = new ConditionalUnaryPredicate(
- new Identity(),
- new Constant(true),
- new Constant(false));
+ ConditionalUnaryPredicate<Object> p = new ConditionalUnaryPredicate<Object>(
+ Identity.INSTANCE,
+ Constant.TRUE,
+ Constant.FALSE);
assertTrue(p.test(Boolean.TRUE));
assertTrue(!p.test(Boolean.FALSE));
}
public void testEquals() throws Exception {
- ConditionalUnaryPredicate p = new ConditionalUnaryPredicate(
- new Identity(),
- new Constant(true),
- new Constant(true));
+ ConditionalUnaryPredicate<Object> p = new ConditionalUnaryPredicate<Object>(
+ Identity.INSTANCE,
+ Constant.TRUE,
+ Constant.TRUE);
assertEquals(p,p);
- assertObjectsAreEqual(p,new ConditionalUnaryPredicate(
- new Identity(),
- new Constant(true),
- new Constant(true)));
- assertObjectsAreNotEqual(p,new ConditionalUnaryPredicate(
- new Identity(),
- new Constant(false),
- new Constant(true)));
- assertObjectsAreNotEqual(p,new ConditionalUnaryPredicate(
- new Constant(true),
- new Constant(true),
- new Constant(true)));
- assertObjectsAreNotEqual(p,new ConditionalUnaryPredicate(
- null,
- new Constant(true),
- new Constant(true)));
- assertObjectsAreNotEqual(p,new ConditionalUnaryPredicate(
- new Constant(true),
- null,
- new Constant(true)));
- assertObjectsAreNotEqual(p,new ConditionalUnaryPredicate(
- new Constant(true),
- new Constant(true),
- null));
+ assertObjectsAreEqual(p,new ConditionalUnaryPredicate<Object>(
+ Identity.INSTANCE,
+ Constant.TRUE,
+ Constant.TRUE));
+ assertObjectsAreNotEqual(p,new ConditionalUnaryPredicate<Object>(
+ Identity.INSTANCE,
+ Constant.FALSE,
+ Constant.TRUE));
+ assertObjectsAreNotEqual(p,new ConditionalUnaryPredicate<Object>(
+ Constant.TRUE,
+ Constant.TRUE,
+ Constant.TRUE));
}
}
Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryProcedure.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryProcedure.java?rev=666209&r1=666208&r2=666209&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryProcedure.java (original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryProcedure.java Tue Jun 10 10:08:53 2008
@@ -46,10 +46,10 @@
// ------------------------------------------------------------------------
protected Object makeFunctor() {
- return new ConditionalUnaryProcedure(
- new Constant(true),
- new NoOp(),
- new NoOp());
+ return new ConditionalUnaryProcedure<Object>(
+ Constant.TRUE,
+ NoOp.INSTANCE,
+ NoOp.INSTANCE);
}
// Lifecycle
@@ -69,8 +69,8 @@
public void testRun() throws Exception {
RunCounter left = new RunCounter();
RunCounter right = new RunCounter();
- ConditionalUnaryProcedure p = new ConditionalUnaryProcedure(
- new Identity(),
+ ConditionalUnaryProcedure<Object> p = new ConditionalUnaryProcedure<Object>(
+ Identity.INSTANCE,
left,
right);
assertEquals(0,left.count);
@@ -87,37 +87,25 @@
}
public void testEquals() throws Exception {
- ConditionalUnaryProcedure p = new ConditionalUnaryProcedure(
- new Identity(),
- new NoOp(),
- new NoOp());
+ ConditionalUnaryProcedure<Object> p = new ConditionalUnaryProcedure<Object>(
+ Identity.INSTANCE,
+ NoOp.INSTANCE,
+ NoOp.INSTANCE);
assertEquals(p,p);
- assertObjectsAreEqual(p,new ConditionalUnaryProcedure(
- new Identity(),
- new NoOp(),
- new NoOp()));
- assertObjectsAreNotEqual(p,new ConditionalUnaryProcedure(
- new Constant(true),
- new NoOp(),
- new NoOp()));
- assertObjectsAreNotEqual(p,new ConditionalUnaryProcedure(
- null,
- new NoOp(),
- new NoOp()));
- assertObjectsAreNotEqual(p,new ConditionalUnaryProcedure(
- new Identity(),
- null,
- new NoOp()));
- assertObjectsAreNotEqual(p,new ConditionalUnaryProcedure(
- new Identity(),
- new NoOp(),
- null));
+ assertObjectsAreEqual(p,new ConditionalUnaryProcedure<Object>(
+ Identity.INSTANCE,
+ NoOp.INSTANCE,
+ NoOp.INSTANCE));
+ assertObjectsAreNotEqual(p,new ConditionalUnaryProcedure<Object>(
+ Constant.TRUE,
+ NoOp.INSTANCE,
+ NoOp.INSTANCE));
}
// Classes
// ------------------------------------------------------------------------
- static class RunCounter implements UnaryProcedure {
+ static class RunCounter implements UnaryProcedure<Object> {
public void run(Object obj) {
count++;
}