commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r1057423 - in /commons/proper/lang/branches/LANG_2_X: RELEASE-NOTES.txt src/main/java/org/apache/commons/lang/ObjectUtils.java src/site/changes/changes.xml src/test/java/org/apache/commons/lang/ObjectUtilsTest.java
Date Tue, 11 Jan 2011 00:20:38 GMT
Author: niallp
Date: Tue Jan 11 00:20:38 2011
New Revision: 1057423

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

Modified:
    commons/proper/lang/branches/LANG_2_X/RELEASE-NOTES.txt
    commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ObjectUtils.java
    commons/proper/lang/branches/LANG_2_X/src/site/changes/changes.xml
    commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/ObjectUtilsTest.java

Modified: commons/proper/lang/branches/LANG_2_X/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/RELEASE-NOTES.txt?rev=1057423&r1=1057422&r2=1057423&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/RELEASE-NOTES.txt (original)
+++ commons/proper/lang/branches/LANG_2_X/RELEASE-NOTES.txt Tue Jan 11 00:20:38 2011
@@ -27,6 +27,7 @@ IMPROVEMENTS IN 2.6
     * [LANG-632] - DateUtils: provide a Date to Calendar convenience method
     * [LANG-576] - ObjectUtils: add clone methods to ObjectUtils
     * [LANG-667] - ObjectUtils: add a Null-safe compare() method
+    * [LANG-670] - ObjectUtils: add notEqual() method
     * [LANG-302] - StrBuilder: implement clone() method
     * [LANG-640] - StringUtils: add a normalizeSpace() method
     * [LANG-614] - StringUtils: add endsWithAny() method

Modified: commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ObjectUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ObjectUtils.java?rev=1057423&r1=1057422&r2=1057423&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ObjectUtils.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ObjectUtils.java
Tue Jan 11 00:20:38 2011
@@ -126,6 +126,30 @@ 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
+     * @since 2.6
+     */
+    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/branches/LANG_2_X/src/site/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/site/changes/changes.xml?rev=1057423&r1=1057422&r2=1057423&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/site/changes/changes.xml (original)
+++ commons/proper/lang/branches/LANG_2_X/src/site/changes/changes.xml Tue Jan 11 00:20:38
2011
@@ -28,6 +28,7 @@
     <action type="add" issue="LANG-632">DateUtils: provide a Date to Calendar convenience
method</action>
     <action type="add" issue="LANG-576">ObjectUtils: add clone methods to ObjectUtils</action>
     <action type="add" issue="LANG-667">ObjectUtils: add a Null-safe compare() method</action>
+    <action type="add" issue="LANG-670">ObjectUtils: add notEqual() method</action>
     <action type="add" issue="LANG-302">StrBuilder: implement clone() method</action>
     <action type="add" issue="LANG-640">StringUtils: add a normalizeSpace() method</action>
     <action type="add" issue="LANG-614">StringUtils: add endsWithAny() method</action>

Modified: commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/ObjectUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/ObjectUtilsTest.java?rev=1057423&r1=1057422&r2=1057423&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/ObjectUtilsTest.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/ObjectUtilsTest.java
Tue Jan 11 00:20:38 2011
@@ -69,6 +69,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