com.evanmclean.evlib.lang
Class Obj

java.lang.Object
  extended by com.evanmclean.evlib.lang.Obj

public final class Obj
extends Object

Misc functions for various object related operations.

Author:
Evan McLean McLean Computer Services (see the overview for copyright and licensing.)

Method Summary
static boolean equals(Object lhs, Object rhs)
          Compares two objects, handling nulls.
static boolean equalsOneOf(Object lhs, Object... rhs)
          Calls lhs.equals() for each of the other objects until one of them returns true.
static
<T,O extends T,A extends T>
T
ifNull(O obj, A alt)
          If the first argument is null, returns the second argument.
static boolean notEquals(Object lhs, Object rhs)
          Compares two objects, handling nulls.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

equals

public static boolean equals(Object lhs,
                             Object rhs)
Compares two objects, handling nulls.
 Obj.equals(null, null) = true
 Obj.equals(null, "") = false
 Obj.equals("", "") = true
 Obj.equals(Boolean.TRUE, "true") = false
 Obj.equals(Boolean.TRUE, new Boolean(true)) = true
 

Parameters:
lhs -
rhs -
Returns:
True if both parameters are null, or lhs.equals(rhs) returns true.

equalsOneOf

public static boolean equalsOneOf(Object lhs,
                                  Object... rhs)
Calls lhs.equals() for each of the other objects until one of them returns true.

Parameters:
lhs - The object to compare.
rhs - One or more objects to compare against for equality.
Returns:
True if lhs.equals(rhs) returns true for one of the rhs objects specified. Returns true if lhs is null and one of the rhs objects is null.

ifNull

public static <T,O extends T,A extends T> T ifNull(O obj,
                                                   A alt)
If the first argument is null, returns the second argument.

Type Parameters:
T - Return type. Will be common ancestor type of the two parameters.
O - Type of the first argument.
A - Type of the second argument.
Parameters:
obj - The object to check.
alt - The object to return if obj is null.
Returns:
The returned argument.

notEquals

public static boolean notEquals(Object lhs,
                                Object rhs)
Compares two objects, handling nulls.
 Obj.equals(null, null) = false
 Obj.equals(null, "") = true
 Obj.equals("", "") = false
 Obj.equals(Boolean.TRUE, "true") = true
 Obj.equals(Boolean.TRUE, new Boolean(true)) = false
 

Parameters:
lhs -
rhs -
Returns:
True if both parameters are null, or lhs.equals(rhs) returns true.