Return-Path: Delivered-To: apmail-commons-commits-archive@locus.apache.org Received: (qmail 44839 invoked from network); 28 Aug 2008 22:34:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 28 Aug 2008 22:34:09 -0000 Received: (qmail 59510 invoked by uid 500); 28 Aug 2008 22:34:07 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 59089 invoked by uid 500); 28 Aug 2008 22:34:05 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 59080 invoked by uid 99); 28 Aug 2008 22:34:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Aug 2008 15:34:05 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Aug 2008 22:33:14 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id DDB2B238899B; Thu, 28 Aug 2008 15:33:44 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r690030 - in /commons/sandbox/functor/trunk/src: main/java/org/apache/commons/functor/adapter/ test/java/org/apache/commons/functor/adapter/ Date: Thu, 28 Aug 2008 22:33:44 -0000 To: commits@commons.apache.org From: mbenson@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080828223344.DDB2B238899B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mbenson Date: Thu Aug 28 15:33:43 2008 New Revision: 690030 URL: http://svn.apache.org/viewvc?rev=690030&view=rev Log: add missing binaryfunctor to corresponding unaryfunctor adapters Added: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/BinaryPredicateUnaryPredicate.java (with props) commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureUnaryProcedure.java (with props) commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestBinaryPredicateUnaryPredicate.java (with props) commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestBinaryProcedureUnaryProcedure.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/BinaryPredicateUnaryPredicate.java URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/BinaryPredicateUnaryPredicate.java?rev=690030&view=auto ============================================================================== --- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/BinaryPredicateUnaryPredicate.java (added) +++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/BinaryPredicateUnaryPredicate.java Thu Aug 28 15:33:43 2008 @@ -0,0 +1,95 @@ +/* + * 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 org.apache.commons.functor.BinaryPredicate; +import org.apache.commons.functor.UnaryPredicate; + +/** + * Adapts a BinaryPredicate as a UnaryPredicate by sending the same argument to both sides of the BinaryPredicate. + * @version $Revision$ $Date$ + * @author Matt Benson + */ +public final class BinaryPredicateUnaryPredicate implements UnaryPredicate { + private BinaryPredicate predicate; + + /** + * Create a new BinaryPredicateUnaryPredicate. + * @param predicate to adapt + */ + public BinaryPredicateUnaryPredicate(BinaryPredicate predicate) { + if (null == predicate) { + throw new IllegalArgumentException("BinaryPredicate argument was null"); + } + this.predicate = predicate; + } + + /** + * {@inheritDoc} + */ + public boolean test(A obj) { + return predicate.test(obj, obj); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + return obj == this || obj instanceof BinaryPredicateUnaryPredicate + && equals((BinaryPredicateUnaryPredicate) obj); + } + + /** + * Learn whether another BinaryPredicateUnaryPredicate is equal to + * this. + * + * @param that BinaryPredicateUnaryPredicate to check + * + * @return whether equal + */ + public boolean equals(BinaryPredicateUnaryPredicate that) { + return that != null && that.predicate.equals(this.predicate); + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return ("BinaryPredicateUnaryPredicate".hashCode() << 2) | predicate.hashCode(); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return "BinaryPredicateUnaryPredicate<" + predicate + ">"; + } + + /** + * Adapt a BinaryFunction as a UnaryFunction. + * @param + * @param predicate BinaryPredicate to adapt + * @return UnaryPredicate + */ + public static UnaryPredicate adapt(BinaryPredicate predicate) { + return null == predicate ? null : new BinaryPredicateUnaryPredicate(predicate); + } + +} Propchange: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/BinaryPredicateUnaryPredicate.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/BinaryPredicateUnaryPredicate.java ------------------------------------------------------------------------------ --- svn:keywords (added) +++ svn:keywords Thu Aug 28 15:33:43 2008 @@ -0,0 +1,5 @@ +Date +Author +Id +Revision +HeadURL Added: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureUnaryProcedure.java URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureUnaryProcedure.java?rev=690030&view=auto ============================================================================== --- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureUnaryProcedure.java (added) +++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureUnaryProcedure.java Thu Aug 28 15:33:43 2008 @@ -0,0 +1,95 @@ +/* + * 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 org.apache.commons.functor.BinaryProcedure; +import org.apache.commons.functor.UnaryProcedure; + +/** + * Adapts a BinaryProcedure as a UnaryProcedure by sending the same argument to both sides of the BinaryProcedure. + * @version $Revision$ $Date$ + * @author Matt Benson + */ +public final class BinaryProcedureUnaryProcedure implements UnaryProcedure { + private BinaryProcedure procedure; + + /** + * Create a new BinaryProcedureUnaryProcedure. + * @param procedure to adapt + */ + public BinaryProcedureUnaryProcedure(BinaryProcedure procedure) { + if (null == procedure) { + throw new IllegalArgumentException("BinaryProcedure argument was null"); + } + this.procedure = procedure; + } + + /** + * {@inheritDoc} + */ + public void run(A obj) { + procedure.run(obj, obj); + }; + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + return obj == this || obj instanceof BinaryProcedureUnaryProcedure + && equals((BinaryProcedureUnaryProcedure) obj); + } + + /** + * Learn whether another BinaryProcedureUnaryProcedure is equal to + * this. + * + * @param that BinaryProcedureUnaryProcedure to check + * + * @return whether equal + */ + public boolean equals(BinaryProcedureUnaryProcedure that) { + return that != null && that.procedure.equals(this.procedure); + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return ("BinaryProcedureUnaryProcedure".hashCode() << 2) | procedure.hashCode(); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return "BinaryProcedureUnaryProcedure<" + procedure + ">"; + } + + /** + * Adapt a BinaryProcedure as a UnaryProcedure. + * @param + * @param predicate BinaryProcedure to adapt + * @return UnaryProcedure + */ + public static UnaryProcedure adapt(BinaryProcedure procedure) { + return null == procedure ? null : new BinaryProcedureUnaryProcedure(procedure); + } + +} Propchange: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureUnaryProcedure.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureUnaryProcedure.java ------------------------------------------------------------------------------ --- svn:keywords (added) +++ svn:keywords Thu Aug 28 15:33:43 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=690030&r1=690029&r2=690030&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 15:33:43 2008 @@ -39,7 +39,6 @@ suite.addTest(TestProcedureFunction.suite()); suite.addTest(TestUnaryProcedureUnaryFunction.suite()); suite.addTest(TestBinaryProcedureBinaryFunction.suite()); - suite.addTest(TestBinaryFunctionUnaryFunction.suite()); suite.addTest(TestFunctionPredicate.suite()); suite.addTest(TestUnaryFunctionUnaryPredicate.suite()); @@ -76,6 +75,10 @@ suite.addTest(TestRightBoundProcedure.suite()); suite.addTest(TestFullyBoundProcedure.suite()); + suite.addTest(TestBinaryFunctionUnaryFunction.suite()); + suite.addTest(TestBinaryPredicateUnaryPredicate.suite()); + suite.addTest(TestBinaryProcedureUnaryProcedure.suite()); + return suite; } } Added: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestBinaryPredicateUnaryPredicate.java URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestBinaryPredicateUnaryPredicate.java?rev=690030&view=auto ============================================================================== --- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestBinaryPredicateUnaryPredicate.java (added) +++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestBinaryPredicateUnaryPredicate.java Thu Aug 28 15:33:43 2008 @@ -0,0 +1,91 @@ +/* + * 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.UnaryPredicate; +import org.apache.commons.functor.core.Constant; +import org.apache.commons.functor.core.IsNotSame; +import org.apache.commons.functor.core.IsSame; + +/** + * @version $Revision$ $Date$ + * @author Matt Benson + */ +public class TestBinaryPredicateUnaryPredicate extends BaseFunctorTest { + + // Conventional + // ------------------------------------------------------------------------ + + public TestBinaryPredicateUnaryPredicate(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(TestBinaryPredicateUnaryPredicate.class); + } + + // Functor Testing Framework + // ------------------------------------------------------------------------ + + protected Object makeFunctor() { + return new BinaryPredicateUnaryPredicate(IsSame.INSTANCE); + } + + // Lifecycle + // ------------------------------------------------------------------------ + + public void setUp() throws Exception { + super.setUp(); + } + + public void tearDown() throws Exception { + super.tearDown(); + } + + // Tests + // ------------------------------------------------------------------------ + + public void testTestWhenTrue() throws Exception { + UnaryPredicate p = new BinaryPredicateUnaryPredicate(IsSame.INSTANCE); + assertTrue(p.test(null)); + } + + public void testTestWhenFalse() throws Exception { + UnaryPredicate p = new BinaryPredicateUnaryPredicate(IsNotSame.INSTANCE); + assertFalse(p.test(null)); + } + + public void testEquals() throws Exception { + UnaryPredicate p = new BinaryPredicateUnaryPredicate(IsSame.INSTANCE); + assertEquals(p, p); + assertObjectsAreEqual(p, new BinaryPredicateUnaryPredicate(IsSame.INSTANCE)); + assertObjectsAreNotEqual(p, Constant.truePredicate()); + assertObjectsAreNotEqual(p, new BinaryPredicateUnaryPredicate(IsNotSame.INSTANCE)); + } + + public void testAdaptNull() throws Exception { + assertNull(BinaryPredicateUnaryPredicate.adapt(null)); + } + + public void testAdapt() throws Exception { + assertNotNull(BinaryPredicateUnaryPredicate.adapt(Constant.TRUE)); + } +} Propchange: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestBinaryPredicateUnaryPredicate.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestBinaryPredicateUnaryPredicate.java ------------------------------------------------------------------------------ --- svn:keywords (added) +++ svn:keywords Thu Aug 28 15:33:43 2008 @@ -0,0 +1,5 @@ +Date +Author +Id +Revision +HeadURL Added: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestBinaryProcedureUnaryProcedure.java URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestBinaryProcedureUnaryProcedure.java?rev=690030&view=auto ============================================================================== --- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestBinaryProcedureUnaryProcedure.java (added) +++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestBinaryProcedureUnaryProcedure.java Thu Aug 28 15:33:43 2008 @@ -0,0 +1,84 @@ +/* + * 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.UnaryProcedure; +import org.apache.commons.functor.core.NoOp; + +/** + * @version $Revision$ $Date$ + * @author Matt Benson + */ +public class TestBinaryProcedureUnaryProcedure extends BaseFunctorTest { + + // Conventional + // ------------------------------------------------------------------------ + + public TestBinaryProcedureUnaryProcedure(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(TestBinaryProcedureUnaryProcedure.class); + } + + // Functor Testing Framework + // ------------------------------------------------------------------------ + + protected Object makeFunctor() { + return new BinaryProcedureUnaryProcedure(NoOp.INSTANCE); + } + + // Lifecycle + // ------------------------------------------------------------------------ + + public void setUp() throws Exception { + super.setUp(); + } + + public void tearDown() throws Exception { + super.tearDown(); + } + + // Tests + // ------------------------------------------------------------------------ + + public void testRun() throws Exception { + UnaryProcedure p = new BinaryProcedureUnaryProcedure(NoOp.INSTANCE); + p.run(null); + } + + public void testEquals() throws Exception { + UnaryProcedure p = new BinaryProcedureUnaryProcedure(NoOp.INSTANCE); + assertEquals(p, p); + assertObjectsAreEqual(p, new BinaryProcedureUnaryProcedure(NoOp.INSTANCE)); + assertObjectsAreNotEqual(p, NoOp.INSTANCE); + assertObjectsAreNotEqual(p, new BinaryProcedureUnaryProcedure(IgnoreLeftProcedure.adapt(NoOp.INSTANCE))); + } + + public void testAdaptNull() throws Exception { + assertNull(BinaryProcedureUnaryProcedure.adapt(null)); + } + + public void testAdapt() throws Exception { + assertNotNull(BinaryProcedureUnaryProcedure.adapt(NoOp.INSTANCE)); + } +} Propchange: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestBinaryProcedureUnaryProcedure.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestBinaryProcedureUnaryProcedure.java ------------------------------------------------------------------------------ --- svn:keywords (added) +++ svn:keywords Thu Aug 28 15:33:43 2008 @@ -0,0 +1,5 @@ +Date +Author +Id +Revision +HeadURL