commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r689985 - in /commons/sandbox/functor/trunk/src: main/java/org/apache/commons/functor/core/ test/java/org/apache/commons/functor/core/
Date Thu, 28 Aug 2008 21:08:46 GMT
Author: mbenson
Date: Thu Aug 28 14:08:46 2008
New Revision: 689985

URL: http://svn.apache.org/viewvc?rev=689985&view=rev
Log:
Is[Not]Same

Added:
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/IsNotSame.java
  (with props)
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/IsSame.java
  (with props)
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsNotSame.java
  (with props)
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsSame.java
  (with props)
Modified:
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestAll.java

Added: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/IsNotSame.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/IsNotSame.java?rev=689985&view=auto
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/IsNotSame.java
(added)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/IsNotSame.java
Thu Aug 28 14:08:46 2008
@@ -0,0 +1,97 @@
+/*
+ * 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.core;
+
+import java.io.Serializable;
+
+import org.apache.commons.functor.BinaryPredicate;
+import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.adapter.RightBoundPredicate;
+
+/**
+ * {@link #test Tests} the reference (!=) inequality of its arguments.
+ *
+ * @version $Revision$ $Date$
+ * @author Matt Benson
+ */
+public final class IsNotSame<L, R> implements BinaryPredicate<L, R>, Serializable
{
+    // static attributes
+    // ------------------------------------------------------------------------
+    /**
+     * Basic IsNotSame<Object, Object> instance.
+     */
+    public static final IsNotSame<Object, Object> INSTANCE = IsNotSame.<Object,
Object>instance();
+
+    // constructor
+    // ------------------------------------------------------------------------
+    /**
+     * Create a new IsNotSame.
+     */
+    public IsNotSame() {
+    }
+
+    // predicate interface
+    // ------------------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
+    public boolean test(L left, R right) {
+        return left != right;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean equals(Object that) {
+        return that instanceof IsNotSame;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int hashCode() {
+        return "IsNotSame".hashCode();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString() {
+        return "IsNotSame";
+    }
+
+    // static methods
+    // ------------------------------------------------------------------------
+    /**
+     * Get an IsNotSame instance.
+     * @return IsNotSame
+     */
+    public static <L, R> IsNotSame<L, R> instance() {
+        return new IsNotSame<L, R>();
+    }
+
+    /**
+     * Get an IsNotSame UnaryPredicate.
+     * @param <L>
+     * @param <R>
+     * @param object bound comparison object
+     * @return UnaryPredicate<L>
+     */
+    public static <L, R> UnaryPredicate<L> to(R object) {
+        return new RightBoundPredicate<L, R>(new IsNotSame<L, R>(), object);
+    }
+}

Propchange: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/IsNotSame.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/IsNotSame.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Aug 28 14:08:46 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL

Added: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/IsSame.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/IsSame.java?rev=689985&view=auto
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/IsSame.java
(added)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/IsSame.java
Thu Aug 28 14:08:46 2008
@@ -0,0 +1,97 @@
+/*
+ * 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.core;
+
+import java.io.Serializable;
+
+import org.apache.commons.functor.BinaryPredicate;
+import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.adapter.RightBoundPredicate;
+
+/**
+ * {@link #test Tests} the reference (==) equality of its arguments.
+ *
+ * @version $Revision$ $Date$
+ * @author Matt Benson
+ */
+public final class IsSame<L, R> implements BinaryPredicate<L, R>, Serializable
{
+    // static attributes
+    // ------------------------------------------------------------------------
+    /**
+     * Basic IsSame<Object, Object> instance.
+     */
+    public static final IsSame<Object, Object> INSTANCE = IsSame.<Object, Object>instance();
+
+    // constructor
+    // ------------------------------------------------------------------------
+    /**
+     * Create a new IsSame.
+     */
+    public IsSame() {
+    }
+
+    // predicate interface
+    // ------------------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
+    public boolean test(L left, R right) {
+        return left == right;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean equals(Object that) {
+        return that instanceof IsSame;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int hashCode() {
+        return "IsSame".hashCode();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString() {
+        return "IsSame";
+    }
+
+    // static methods
+    // ------------------------------------------------------------------------
+    /**
+     * Get an IsSame instance.
+     * @return IsSame
+     */
+    public static <L, R> IsSame<L, R> instance() {
+        return new IsSame<L, R>();
+    }
+
+    /**
+     * Get an IsSame UnaryPredicate.
+     * @param <L>
+     * @param <R>
+     * @param object bound comparison object
+     * @return UnaryPredicate<L>
+     */
+    public static <L, R> UnaryPredicate<L> to(R object) {
+        return new RightBoundPredicate<L, R>(new IsSame<L, R>(), object);
+    }
+}

Propchange: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/IsSame.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/IsSame.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Aug 28 14:08:46 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL

Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestAll.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestAll.java?rev=689985&r1=689984&r2=689985&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestAll.java
(original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestAll.java
Thu Aug 28 14:08:46 2008
@@ -43,6 +43,8 @@
         suite.addTest(TestIsNotNull.suite());
         suite.addTest(TestIsEqual.suite());
         suite.addTest(TestIsNotEqual.suite());
+        suite.addTest(TestIsSame.suite());
+        suite.addTest(TestIsNotSame.suite());
 
         suite.addTest(TestLimit.suite());
         suite.addTest(TestOffset.suite());

Added: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsNotSame.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsNotSame.java?rev=689985&view=auto
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsNotSame.java
(added)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsNotSame.java
Thu Aug 28 14:08:46 2008
@@ -0,0 +1,93 @@
+/*
+ * 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.core;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.functor.BaseFunctorTest;
+import org.apache.commons.functor.BinaryPredicate;
+
+/**
+ * @version $Revision$ $Date$
+ * @author Matt Benson
+ */
+public class TestIsNotSame extends BaseFunctorTest {
+
+    // Conventional
+    // ------------------------------------------------------------------------
+
+    public TestIsNotSame(String testName) {
+        super(testName);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestIsNotSame.class);
+    }
+
+    // Functor Testing Framework
+    // ------------------------------------------------------------------------
+
+    protected Object makeFunctor() {
+        return new IsNotSame<Object, Object>();
+    }
+
+    // Lifecycle
+    // ------------------------------------------------------------------------
+
+    public void setUp() throws Exception {
+        super.setUp();
+    }
+
+    public void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    // Tests
+    // ------------------------------------------------------------------------
+
+    public void testTest() throws Exception {
+        IsNotSame<Object, Object> p = new IsNotSame<Object, Object>();
+        assertFalse("For symmetry, two nulls should be same", p.test(null, null));
+        assertFalse(p.test("foo", "foo"));
+        assertTrue(p.test(null, "foo"));
+        assertTrue(p.test("foo", null));
+        assertTrue(p.test(new Integer(3), new Integer(3)));
+        assertTrue(p.test(null, new Integer(3)));
+        assertTrue(p.test(new Integer(3), null));
+
+        assertTrue(p.test(new Integer(3), new Integer(4)));
+        assertTrue(p.test(new Integer(4), new Integer(3)));
+        assertTrue(p.test("3", new Integer(3)));
+        assertTrue(p.test(new Integer(3), "3"));
+    }
+
+    public void testEquals() throws Exception {
+        BinaryPredicate<Object, Object> f = new IsNotSame<Object, Object>();
+        assertEquals(f, f);
+
+        assertObjectsAreEqual(f, new IsNotSame<Object, Object>());
+        assertObjectsAreEqual(f, IsNotSame.instance());
+        assertObjectsAreNotEqual(f, Constant.truePredicate());
+    }
+
+    public void testConstant() throws Exception {
+        assertEquals(IsNotSame.instance(), IsNotSame.instance());
+        assertNotSame(IsNotSame.instance(), IsNotSame.instance());
+        assertSame(IsNotSame.INSTANCE, IsNotSame.INSTANCE);
+    }
+}

Propchange: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsNotSame.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsNotSame.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Aug 28 14:08:46 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL

Added: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsSame.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsSame.java?rev=689985&view=auto
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsSame.java
(added)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsSame.java
Thu Aug 28 14:08:46 2008
@@ -0,0 +1,93 @@
+/*
+ * 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.core;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.functor.BaseFunctorTest;
+import org.apache.commons.functor.BinaryPredicate;
+
+/**
+ * @version $Revision$ $Date$
+ * @author Matt Benson
+ */
+public class TestIsSame extends BaseFunctorTest {
+
+    // Conventional
+    // ------------------------------------------------------------------------
+
+    public TestIsSame(String testName) {
+        super(testName);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestIsSame.class);
+    }
+
+    // Functor Testing Framework
+    // ------------------------------------------------------------------------
+
+    protected Object makeFunctor() {
+        return new IsSame<Object, Object>();
+    }
+
+    // Lifecycle
+    // ------------------------------------------------------------------------
+
+    public void setUp() throws Exception {
+        super.setUp();
+    }
+
+    public void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    // Tests
+    // ------------------------------------------------------------------------
+
+    public void testTest() throws Exception {
+        IsSame<Object, Object> p = new IsSame<Object, Object>();
+        assertTrue("For symmetry, two nulls should be same", p.test(null, null));
+        assertTrue(p.test("foo", "foo"));
+        assertFalse(p.test(null, "foo"));
+        assertFalse(p.test("foo", null));
+        assertFalse(p.test(new Integer(3), new Integer(3)));
+        assertFalse(p.test(null, new Integer(3)));
+        assertFalse(p.test(new Integer(3), null));
+
+        assertFalse(p.test(new Integer(3), new Integer(4)));
+        assertFalse(p.test(new Integer(4), new Integer(3)));
+        assertFalse(p.test("3", new Integer(3)));
+        assertFalse(p.test(new Integer(3), "3"));
+    }
+
+    public void testEquals() throws Exception {
+        BinaryPredicate<Object, Object> f = new IsSame<Object, Object>();
+        assertEquals(f, f);
+
+        assertObjectsAreEqual(f, new IsSame<Object, Object>());
+        assertObjectsAreEqual(f, IsSame.instance());
+        assertObjectsAreNotEqual(f, Constant.truePredicate());
+    }
+
+    public void testConstant() throws Exception {
+        assertEquals(IsSame.instance(), IsSame.instance());
+        assertNotSame(IsSame.instance(), IsSame.instance());
+        assertSame(IsSame.INSTANCE, IsSame.INSTANCE);
+    }
+}

Propchange: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsSame.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsSame.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Aug 28 14:08:46 2008
@@ -0,0 +1,5 @@
+Date
+Author
+Id
+Revision
+HeadURL



Mime
View raw message