commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r1057410 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/ObjectUtils.java test/java/org/apache/commons/lang3/ObjectUtilsTest.java
Date Mon, 10 Jan 2011 23:10:16 GMT
Author: niallp
Date: Mon Jan 10 23:10:16 2011
New Revision: 1057410

URL: http://svn.apache.org/viewvc?rev=1057410&view=rev
Log:
LANG-670 Add notEqual() method to ObjectUtils

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ObjectUtils.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ObjectUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ObjectUtils.java?rev=1057410&r1=1057409&r2=1057410&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ObjectUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ObjectUtils.java Mon
Jan 10 23:10:16 2011
@@ -159,6 +159,29 @@ public class ObjectUtils {
     }
 
     /**
+     * <p>Compares two objects for inequality, where either one or both
+     * objects may be <code>null</code>.</p>
+     *
+     * <pre>
+     * ObjectUtils.notEqual(null, null)                  = false
+     * ObjectUtils.notEqual(null, "")                    = true
+     * ObjectUtils.notEqual("", null)                    = true
+     * ObjectUtils.notEqual("", "")                      = false
+     * ObjectUtils.notEqual(Boolean.TRUE, null)          = true
+     * ObjectUtils.notEqual(Boolean.TRUE, "true")        = true
+     * ObjectUtils.notEqual(Boolean.TRUE, Boolean.TRUE)  = false
+     * ObjectUtils.notEqual(Boolean.TRUE, Boolean.FALSE) = true
+     * </pre>
+     *
+     * @param object1  the first object, may be <code>null</code>
+     * @param object2  the second object, may be <code>null</code>
+     * @return <code>false</code> if the values of both objects are the same
+     */
+    public static boolean notEqual(Object object1, Object object2) {
+        return ObjectUtils.equals(object1, object2) == false;
+    }
+
+    /**
      * <p>Gets the hash code of an object returning zero when the
      * object is <code>null</code>.</p>
      *

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java?rev=1057410&r1=1057409&r2=1057410&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java
Mon Jan 10 23:10:16 2011
@@ -88,6 +88,14 @@ public class ObjectUtilsTest extends Tes
         assertTrue("ObjectUtils.equals(\"foo\", \"foo\") returned false", ObjectUtils.equals(FOO,
FOO));
     }
 
+    public void testNotEqual() {
+        assertFalse("ObjectUtils.notEqual(null, null) returned false", ObjectUtils.notEqual(null,
null));
+        assertTrue("ObjectUtils.notEqual(\"foo\", null) returned true", ObjectUtils.notEqual(FOO,
null));
+        assertTrue("ObjectUtils.notEqual(null, \"bar\") returned true", ObjectUtils.notEqual(null,
BAR));
+        assertTrue("ObjectUtils.notEqual(\"foo\", \"bar\") returned true", ObjectUtils.notEqual(FOO,
BAR));
+        assertFalse("ObjectUtils.notEqual(\"foo\", \"foo\") returned false", ObjectUtils.notEqual(FOO,
FOO));
+    }
+
     public void testHashCode() {
         assertEquals(0, ObjectUtils.hashCode(null));
         assertEquals("a".hashCode(), ObjectUtils.hashCode("a"));



Mime
View raw message