common: add equalsNullable
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 26 Feb 2015 18:05:45 +0000 (13:05 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Fri, 27 Feb 2015 21:01:21 +0000 (16:01 -0500)
check if two objects are null or equals().

Change-Id: Ic1e3266e84e88aece077ab45c20b995199125f70
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/42821
Reviewed-by: Hudson CI
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
org.eclipse.tracecompass.common.core/src/org/eclipse/tracecompass/common/core/NonNullUtils.java

index bcf6a27707ac4888bd4d09e92eeaa34f18781098..369459e24c803ff896f7d4f2ae777579230f3f8b 100644 (file)
@@ -23,7 +23,8 @@ import org.eclipse.jdt.annotation.Nullable;
  */
 public final class NonNullUtils {
 
-    private NonNullUtils() {}
+    private NonNullUtils() {
+    }
 
     /**
      * Returns a non-null {@link String} for a potentially null object. This
@@ -61,4 +62,23 @@ public final class NonNullUtils {
         }
         return obj;
     }
+
+    /**
+     * Checks equality with two nullable objects
+     *
+     * @param o1
+     *            the first object to compare
+     * @param o2
+     *            the second object to compare
+     * @return true if o1.equals(o2) or o1 == o2
+     */
+    public static boolean equalsNullable(final @Nullable Object o1, final @Nullable Object o2) {
+        if (o1 == o2) {
+            return true;
+        }
+        if (o1 == null) {
+            return false;
+        }
+        return o1.equals(o2);
+    }
 }
This page took 0.026506 seconds and 5 git commands to generate.