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>
*/
public final class NonNullUtils {
- private NonNullUtils() {}
+ private NonNullUtils() {
+ }
/**
* Returns a non-null {@link String} for a potentially null object. This
}
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);
+ }
}