Author: mbenson
Date: Thu Aug 28 12:16:02 2008
New Revision: 689935
URL: http://svn.apache.org/viewvc?rev=689935&view=rev
Log:
add Fully-bound adapters from BinaryFunctor* to NullaryFunctor*
Added:
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundFunction.java
(with props)
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundPredicate.java
(with props)
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundProcedure.java
(with props)
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundFunction.java
(with props)
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundPredicate.java
(with props)
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundProcedure.java
(with props)
Modified:
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestAll.java
Added:
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundFunction.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundFunction.java?rev=689935&view=auto
==============================================================================
---
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundFunction.java
(added)
+++
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundFunction.java
Thu Aug 28 12:16:02 2008
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.functor.adapter;
+
+import java.io.Serializable;
+
+import org.apache.commons.functor.BinaryFunction;
+import org.apache.commons.functor.Function;
+
+/**
+ * Adapts a
+ * [EMAIL PROTECTED] BinaryFunction BinaryFunction}
+ * to the
+ * [EMAIL PROTECTED] Function Function} interface
+ * using constant arguments.
+ * <p/>
+ * Note that although this class implements
+ * [EMAIL PROTECTED] Serializable}, a given instance will
+ * only be truly <code>Serializable</code> if the
+ * underlying objects are. Attempts to serialize
+ * an instance whose delegates are not
+ * <code>Serializable</code> will result in an exception.
+ *
+ * @version $Revision$ $Date$
+ * @author Matt Benson
+ */
+public final class FullyBoundFunction<L, R, T> implements Function<T>,
Serializable {
+ /** The [EMAIL PROTECTED] BinaryFunction BinaryFunction} I'm wrapping. */
+ private BinaryFunction<? super L, ? super R, ? extends T> function;
+ /** The left parameter to pass to that function. */
+ private L left;
+ /** The right parameter to pass to that function. */
+ private R right;
+
+ /**
+ * Create a new FullyBoundFunction.
+ * @param function the function to adapt
+ * @param left the left side argument to use
+ * @param right the right side argument to use
+ */
+ public FullyBoundFunction(BinaryFunction<? super L, ? super R, ? extends
T> function, L left, R right) {
+ if (function == null) {
+ throw new IllegalArgumentException("BinaryFunction argument was
null");
+ }
+ this.function = function;
+ this.left = left;
+ this.right = right;
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public T evaluate() {
+ return function.evaluate(left, right);
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public boolean equals(Object that) {
+ return that == this || (that instanceof FullyBoundFunction &&
equals((FullyBoundFunction<?, ?, ?>) that));
+ }
+
+ /**
+ * Learn whether another FullyBoundFunction is equal to this.
+ * @param that FullyBoundFunction to test
+ * @return boolean
+ */
+ public boolean equals(FullyBoundFunction<?, ?, ?> that) {
+ return null != that && (null == function ? null == that.function :
function.equals(that.function))
+ && (null == left ? null == that.left : left.equals(that.left))
+ && (null == right ? null == that.right :
right.equals(that.right));
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public int hashCode() {
+ int hash = "FullyBoundFunction".hashCode();
+ if (null != function) {
+ hash <<= 2;
+ hash ^= function.hashCode();
+ }
+ hash <<= 2;
+ if (null != left) {
+ hash ^= left.hashCode();
+ }
+ hash <<= 2;
+ if (null != right) {
+ hash ^= right.hashCode();
+ }
+ return hash;
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public String toString() {
+ return "FullyBoundFunction<" + function + "(" + left + ", " + right +
")>";
+ }
+
+ /**
+ * Adapt a BinaryFunction as a Function.
+ * @param function to adapt
+ * @param left left side argument
+ * @param right right side argument
+ * @return FullyBoundFunction
+ */
+ public static <L, R, T> FullyBoundFunction<L, R, T> bind(
+ BinaryFunction<? super L, ? super R, ? extends T> function, L
left, R right) {
+ return null == function ? null : new FullyBoundFunction<L, R,
T>(function, left, right);
+ }
+
+}
Propchange:
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundFunction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundFunction.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Aug 28 12:16:02 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL
Added:
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundPredicate.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundPredicate.java?rev=689935&view=auto
==============================================================================
---
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundPredicate.java
(added)
+++
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundPredicate.java
Thu Aug 28 12:16:02 2008
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.functor.adapter;
+
+import java.io.Serializable;
+
+import org.apache.commons.functor.BinaryPredicate;
+import org.apache.commons.functor.Predicate;
+import org.apache.commons.functor.UnaryPredicate;
+
+/**
+ * Adapts a
+ * [EMAIL PROTECTED] BinaryPredicate BinaryPredicate}
+ * to the
+ * [EMAIL PROTECTED] UnaryPredicate UnaryPredicate} interface
+ * using a constant left-side argument.
+ * <p/>
+ * Note that although this class implements
+ * [EMAIL PROTECTED] Serializable}, a given instance will
+ * only be truly <code>Serializable</code> if the
+ * underlying objects are. Attempts to serialize
+ * an instance whose delegates are not
+ * <code>Serializable</code> will result in an exception.
+ *
+ * @version $Revision$ $Date$
+ * @author Matt Benson
+ */
+public final class FullyBoundPredicate<L, R> implements Predicate,
Serializable {
+
+ /** The [EMAIL PROTECTED] BinaryPredicate BinaryPredicate} I'm wrapping. */
+ private BinaryPredicate<? super L, ? super R> predicate;
+ /** The left parameter to pass to that predicate. */
+ private L left;
+ /** The right parameter to pass to that predicate. */
+ private R right;
+
+ /**
+ * Create a new FullyBoundPredicate.
+ * @param predicate the predicate to adapt
+ * @param left the left argument to use
+ * @param right the right argument to use
+ */
+ public FullyBoundPredicate(BinaryPredicate<? super L, ? super R>
predicate, L left, R right) {
+ if (predicate == null) {
+ throw new IllegalArgumentException("BinaryPredicate argument was
null");
+ }
+ this.predicate = predicate;
+ this.left = left;
+ this.right = right;
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public boolean test() {
+ return predicate.test(left, right);
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public boolean equals(Object that) {
+ return that == this || (that instanceof FullyBoundPredicate &&
equals((FullyBoundPredicate<?, ?>) that));
+ }
+
+ /**
+ * Learn whether another FullyBoundPredicate is equal to this.
+ * @param that FullyBoundPredicate to test
+ * @return boolean
+ */
+ public boolean equals(FullyBoundPredicate<?, ?> that) {
+ return null != that && (null == predicate ? null == that.predicate :
predicate.equals(that.predicate))
+ && (null == left ? null == that.left : left.equals(that.left))
+ && (null == right ? null == that.right :
right.equals(that.right));
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public int hashCode() {
+ int hash = "FullyBoundPredicate".hashCode();
+ if (null != predicate) {
+ hash <<= 2;
+ hash ^= predicate.hashCode();
+ }
+ hash <<= 2;
+ if (null != left) {
+ hash ^= left.hashCode();
+ }
+ hash <<= 2;
+ if (null != right) {
+ hash ^= right.hashCode();
+ }
+ return hash;
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public String toString() {
+ return "FullyBoundPredicate<" + predicate + "(" + left + ", " + right
+ ")>";
+ }
+
+ /**
+ * Adapt a BinaryPredicate to the Predicate interface.
+ * @param predicate to adapt
+ * @param left L argument to always send as the left operand to the
wrapped function
+ * @param right R argument to always send as the right operand to the
wrapped function
+ * @return FullyBoundPredicate
+ */
+ public static <L, R> FullyBoundPredicate<L, R> bind(BinaryPredicate<?
super L, ? super R> predicate, L left, R right) {
+ return null == predicate ? null : new FullyBoundPredicate<L,
R>(predicate, left, right);
+ }
+}
Propchange:
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundPredicate.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundPredicate.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Aug 28 12:16:02 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL
Added:
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundProcedure.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundProcedure.java?rev=689935&view=auto
==============================================================================
---
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundProcedure.java
(added)
+++
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundProcedure.java
Thu Aug 28 12:16:02 2008
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.functor.adapter;
+
+import java.io.Serializable;
+
+import org.apache.commons.functor.BinaryProcedure;
+import org.apache.commons.functor.Procedure;
+
+/**
+ * Adapts a
+ * [EMAIL PROTECTED] BinaryProcedure BinaryProcedure}
+ * to the
+ * [EMAIL PROTECTED] Procedure Procedure} interface
+ * using a constant left-side argument.
+ * <p/>
+ * Note that although this class implements
+ * [EMAIL PROTECTED] Serializable}, a given instance will
+ * only be truly <code>Serializable</code> if the
+ * underlying objects are. Attempts to serialize
+ * an instance whose delegates are not
+ * <code>Serializable</code> will result in an exception.
+ *
+ * @version $Revision$ $Date$
+ * @author Matt Benson
+ */
+public final class FullyBoundProcedure<L, R> implements Procedure,
Serializable {
+ /** The [EMAIL PROTECTED] BinaryProcedure BinaryProcedure} I'm wrapping. */
+ private BinaryProcedure<? super L, ? super R> procedure;
+ /** The left parameter to pass to that procedure. */
+ private L left;
+ /** The right parameter to pass to that procedure. */
+ private R right;
+
+ /**
+ * Create a new FullyBoundProcedure.
+ * @param procedure the procedure to adapt
+ * @param left the left argument to use
+ * @param right the right argument to use
+ */
+ public FullyBoundProcedure(BinaryProcedure<? super L, ? super R>
procedure, L left, R right) {
+ if (procedure == null) {
+ throw new IllegalArgumentException("BinaryProcedure argument was
null");
+ }
+ this.procedure = procedure;
+ this.left = left;
+ this.right = right;
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public void run() {
+ procedure.run(left, right);
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public boolean equals(Object that) {
+ return that == this || (that instanceof FullyBoundProcedure &&
equals((FullyBoundProcedure<?, ?>) that));
+ }
+
+ /**
+ * Learn whether another FullyBoundProcedure is equal to this.
+ * @param that FullyBoundProcedure to test
+ * @return boolean
+ */
+ public boolean equals(FullyBoundProcedure<?, ?> that) {
+ return null != that && (null == procedure ? null == that.procedure :
procedure.equals(that.procedure))
+ && (null == left ? null == that.left : left.equals(that.left))
+ && (null == right ? null == that.right :
right.equals(that.right));
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public int hashCode() {
+ int hash = "LeftBoundProcedure".hashCode();
+ if (null != procedure) {
+ hash <<= 2;
+ hash ^= procedure.hashCode();
+ }
+ hash <<= 2;
+ if (null != left) {
+ hash ^= left.hashCode();
+ }
+ hash <<= 2;
+ if (null != right) {
+ hash ^= right.hashCode();
+ }
+ return hash;
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public String toString() {
+ return "FullyBoundProcedure<" + procedure + "(" + left + ", " + right
+ ")>";
+ }
+
+ /**
+ * Adapt a BinaryProcedure to the Procedure interface.
+ * @param procedure to adapt
+ * @param left left side argument
+ * @param right right side argument
+ * @return FullyBoundProcedure
+ */
+ public static <L, R> FullyBoundProcedure<L, R> bind(BinaryProcedure<?
super L, ? super R> procedure, L left, R right) {
+ return null == procedure ? null : new FullyBoundProcedure<L,
R>(procedure, left, right);
+ }
+
+}
Propchange:
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundProcedure.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FullyBoundProcedure.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Aug 28 12:16:02 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL
Modified:
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestAll.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestAll.java?rev=689935&r1=689934&r2=689935&view=diff
==============================================================================
---
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestAll.java
(original)
+++
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestAll.java
Thu Aug 28 12:16:02 2008
@@ -63,14 +63,17 @@
suite.addTest(TestBoundFunction.suite());
suite.addTest(TestLeftBoundFunction.suite());
suite.addTest(TestRightBoundFunction.suite());
+ suite.addTest(TestFullyBoundFunction.suite());
suite.addTest(TestBoundPredicate.suite());
suite.addTest(TestLeftBoundPredicate.suite());
suite.addTest(TestRightBoundPredicate.suite());
+ suite.addTest(TestFullyBoundPredicate.suite());
suite.addTest(TestBoundProcedure.suite());
suite.addTest(TestLeftBoundProcedure.suite());
suite.addTest(TestRightBoundProcedure.suite());
+ suite.addTest(TestFullyBoundProcedure.suite());
return suite;
}
Added:
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundFunction.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundFunction.java?rev=689935&view=auto
==============================================================================
---
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundFunction.java
(added)
+++
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundFunction.java
Thu Aug 28 12:16:02 2008
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.functor.adapter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.functor.BaseFunctorTest;
+import org.apache.commons.functor.Function;
+import org.apache.commons.functor.core.Constant;
+import org.apache.commons.functor.core.LeftIdentity;
+import org.apache.commons.functor.core.RightIdentity;
+
+/**
+ * @version $Revision$ $Date$
+ * @author Matt Benson
+ */
+public class TestFullyBoundFunction extends BaseFunctorTest {
+
+ // Conventional
+ // ------------------------------------------------------------------------
+
+ public TestFullyBoundFunction(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TestFullyBoundFunction.class);
+ }
+
+ // Functor Testing Framework
+ // ------------------------------------------------------------------------
+
+ protected Object makeFunctor() {
+ return new FullyBoundFunction<Object, Object,
Object>(RightIdentity.FUNCTION, null, "xyzzy");
+ }
+
+ // Lifecycle
+ // ------------------------------------------------------------------------
+
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ // Tests
+ // ------------------------------------------------------------------------
+
+ public void testEvaluate() throws Exception {
+ Function<Object> f = new FullyBoundFunction<String, Object,
Object>(RightIdentity.FUNCTION, null, "foo");
+ assertEquals("foo", f.evaluate());
+ }
+
+ public void testEquals() throws Exception {
+ Function<Object> f = new FullyBoundFunction<Object, Object,
Object>(RightIdentity.FUNCTION, null, "xyzzy");
+ assertEquals(f, f);
+ assertObjectsAreEqual(f, new FullyBoundFunction<Object, Object,
Object>(RightIdentity.FUNCTION, null, "xyzzy"));
+ assertObjectsAreNotEqual(f, Constant.of("xyzzy"));
+ assertObjectsAreNotEqual(f, new FullyBoundFunction<Object, Object,
Object>(LeftIdentity.FUNCTION, null, "xyzzy"));
+ assertObjectsAreNotEqual(f, new FullyBoundFunction<Object, Object,
Object>(RightIdentity.FUNCTION, null, "bar"));
+ }
+
+ public void testAdaptNull() throws Exception {
+ assertNull(FullyBoundFunction.bind(null, null, "xyzzy"));
+ }
+
+ public void testAdapt() throws Exception {
+ assertNotNull(FullyBoundFunction.bind(RightIdentity.FUNCTION, "xyzzy",
"foobar"));
+ assertNotNull(FullyBoundFunction.bind(RightIdentity.FUNCTION, null,
null));
+ }
+}
Propchange:
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundFunction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundFunction.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Aug 28 12:16:02 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL
Added:
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundPredicate.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundPredicate.java?rev=689935&view=auto
==============================================================================
---
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundPredicate.java
(added)
+++
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundPredicate.java
Thu Aug 28 12:16:02 2008
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.functor.adapter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.functor.BaseFunctorTest;
+import org.apache.commons.functor.Predicate;
+import org.apache.commons.functor.core.Constant;
+import org.apache.commons.functor.core.RightIdentity;
+
+/**
+ * @version $Revision$ $Date$
+ * @author Matt Benson
+ */
+public class TestFullyBoundPredicate extends BaseFunctorTest {
+
+ // Conventional
+ // ------------------------------------------------------------------------
+
+ public TestFullyBoundPredicate(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TestFullyBoundPredicate.class);
+ }
+
+ // Functor Testing Framework
+ // ------------------------------------------------------------------------
+
+ protected Object makeFunctor() {
+ return new FullyBoundPredicate<Object, Object>(Constant.TRUE, null,
"xyzzy");
+ }
+
+ // Lifecycle
+ // ------------------------------------------------------------------------
+
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ // Tests
+ // ------------------------------------------------------------------------
+
+ public void testTest() throws Exception {
+ Predicate p = new FullyBoundPredicate<Object, Boolean>(
+ new BinaryFunctionBinaryPredicate<Object,
Boolean>(RightIdentity.<Object, Boolean> function()), "foo", Boolean.TRUE);
+ assertEquals(true, p.test());
+ }
+
+ public void testEquals() throws Exception {
+ Predicate p = new FullyBoundPredicate<Object, Boolean>(Constant.TRUE,
"xyzzy", null);
+ assertEquals(p, p);
+ assertObjectsAreEqual(p, new FullyBoundPredicate<Object,
Boolean>(Constant.TRUE, "xyzzy", null));
+ assertObjectsAreNotEqual(p, Constant.TRUE);
+ assertObjectsAreNotEqual(p, new FullyBoundPredicate<Object,
Boolean>(Constant.FALSE, "xyzzy", null));
+ assertObjectsAreNotEqual(p, new FullyBoundPredicate<Object,
Boolean>(Constant.TRUE, "foo", null));
+ assertObjectsAreNotEqual(p, new FullyBoundPredicate<Object,
String>(Constant.TRUE, null, "xyzzy"));
+ }
+
+ public void testAdaptNull() throws Exception {
+ assertNull(FullyBoundPredicate.bind(null, "xyzzy", null));
+ }
+
+ public void testAdapt() throws Exception {
+ assertNotNull(FullyBoundPredicate.bind(Constant.FALSE, "xyzzy",
"foobar"));
+ assertNotNull(FullyBoundPredicate.bind(Constant.FALSE, null, null));
+ }
+}
Propchange:
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundPredicate.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundPredicate.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Aug 28 12:16:02 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL
Added:
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundProcedure.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundProcedure.java?rev=689935&view=auto
==============================================================================
---
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundProcedure.java
(added)
+++
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundProcedure.java
Thu Aug 28 12:16:02 2008
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.functor.adapter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.functor.BaseFunctorTest;
+import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.core.NoOp;
+import org.apache.commons.functor.core.RightIdentity;
+
+/**
+ * @version $Revision$ $Date$
+ * @author Matt Benson
+ */
+public class TestFullyBoundProcedure extends BaseFunctorTest {
+
+ // Conventional
+ // ------------------------------------------------------------------------
+
+ public TestFullyBoundProcedure(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TestFullyBoundProcedure.class);
+ }
+
+ // Functor Testing Framework
+ // ------------------------------------------------------------------------
+
+ protected Object makeFunctor() {
+ return new FullyBoundProcedure<Object, Object>(NoOp.INSTANCE, "xyzzy",
null);
+ }
+
+ // Lifecycle
+ // ------------------------------------------------------------------------
+
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ // Tests
+ // ------------------------------------------------------------------------
+
+ public void testRun() throws Exception {
+ Procedure p = new FullyBoundProcedure<Object, Object>(new
BinaryFunctionBinaryProcedure<Object, Object>(
+ RightIdentity.FUNCTION), "foo", null);
+ p.run();
+ }
+
+ public void testEquals() throws Exception {
+ Procedure f = new FullyBoundProcedure<Object, Object>(NoOp.INSTANCE,
"xyzzy", null);
+ assertEquals(f, f);
+ assertObjectsAreEqual(f, new FullyBoundProcedure<Object,
Object>(NoOp.INSTANCE, "xyzzy", null));
+ assertObjectsAreNotEqual(f, new NoOp());
+ assertObjectsAreNotEqual(f, new FullyBoundProcedure<Object, Object>(
+ new BinaryFunctionBinaryProcedure<Object,
Object>(RightIdentity.FUNCTION), "xyzzy", null));
+ assertObjectsAreNotEqual(f, new FullyBoundProcedure<Object,
Object>(NoOp.INSTANCE, "foo", null));
+ assertObjectsAreNotEqual(f, new FullyBoundProcedure<Object,
Object>(NoOp.INSTANCE, null, null));
+ }
+
+ public void testAdaptNull() throws Exception {
+ assertNull(FullyBoundProcedure.bind(null, "xyzzy", null));
+ }
+
+ public void testAdapt() throws Exception {
+ assertNotNull(FullyBoundProcedure.bind(new NoOp(), "xyzzy", "foobar"));
+ assertNotNull(FullyBoundProcedure.bind(new NoOp(), null, null));
+ }
+}
Propchange:
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundProcedure.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundProcedure.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Aug 28 12:16:02 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL