edu.utexas.its.eis.tools.qwicap.util
Class Null

java.lang.Object
  extended by edu.utexas.its.eis.tools.qwicap.util.Null

public final class Null
extends Object

This class provides a set of static utility methods that perform common tasks associated with the handling of null values.

Author:
Chris W. Johnson

Method Summary
static String fromEmptyString(String PotentiallyEmptyStr)
          Returns null if passed an empty (zero-length) String (or null), otherwise it returns the same String object that was passed to it.
static String fromNullString(String PotentiallyNullStr)
          If the supplied string literally reads "null", in other words it consists of the characters 'n', 'u', 'l', 'l' and no others, the value null is returned.
static String fromSomeString(String PotentiallyRepresentingNullStr, String NullRepresentationStr)
          If the PotentiallyRepresentingNullStr parameter is a string that matches the string supplied in the NullRepresentationStr parameter, the value null is returned.
static boolean orEmpty(String PotentiallyNullOrEmptyStr)
          Returns true if passed null, or an empty (zero length) String object; returns false otherwise.
static boolean safeEquals(Object A, Object B)
          Safely compares two objects for equality, where one, both, or none of the objects may be null.
static String toEmptyString(Object PotentiallyNullObject)
          Returns an empty (zero-length) String if passed null, otherwise it returns the object reference that was passed-in.
static String toNullString(Object PotentiallyNullObject)
          Returns a string reading "null", if the supplied object reference is null.
static String toSomeString(Object PotentiallyNullObject, String NullSubstituteString)
          Returns the supplied NullSubstituteStr, if the object reference supplied in PotentiallyNullObject is null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

orEmpty

public static boolean orEmpty(String PotentiallyNullOrEmptyStr)
Returns true if passed null, or an empty (zero length) String object; returns false otherwise.

Parameters:
PotentiallyNullOrEmptyStr - null or a String object.
Returns:
true if passed null, or an empty (zero length) String object; returns false otherwise.

fromEmptyString

public static String fromEmptyString(String PotentiallyEmptyStr)
Returns null if passed an empty (zero-length) String (or null), otherwise it returns the same String object that was passed to it.

Parameters:
PotentiallyEmptyStr - A String that may be empty, non-empty, or null.
Returns:
null if the String was empty or null, otherwise the String object that was passed-in.

fromNullString

public static String fromNullString(String PotentiallyNullStr)
If the supplied string literally reads "null", in other words it consists of the characters 'n', 'u', 'l', 'l' and no others, the value null is returned. Otherwise, the supplied string is returned.

Parameters:
PotentiallyNullStr - Any String object, or null.
Returns:
null if the characters in the string spell the word "null", otherwise the value passed-in as PotentiallyNullStr is returned.

fromSomeString

public static String fromSomeString(String PotentiallyRepresentingNullStr,
                                    String NullRepresentationStr)
If the PotentiallyRepresentingNullStr parameter is a string that matches the string supplied in the NullRepresentationStr parameter, the value null is returned. Otherwise, the value of the PotentiallyRepresentingNullStr parameter is returned.

Parameters:
PotentiallyRepresentingNullStr - Any String object, or null.
NullRepresentationStr - The string that should be considered to represent a null value.
Returns:
null, or the value passed-in as PotentiallyRepresentingNullStr.

toEmptyString

public static String toEmptyString(Object PotentiallyNullObject)
Returns an empty (zero-length) String if passed null, otherwise it returns the object reference that was passed-in.

Parameters:
PotentiallyNullObject - Any object reference, or null.
Returns:
An empty (zero-length) String if this method was passed null, otherwise the object reference that was passed-in.

toNullString

public static String toNullString(Object PotentiallyNullObject)
Returns a string reading "null", if the supplied object reference is null. Otherwise, the supplied object is converted to a String by invoking its Object.toString() method, and that String is returned.

Parameters:
PotentiallyNullObject - Any object reference, or null.
Returns:
A String object containing the word "null", or the String returned by invoking PotentiallyNullObject.toString().

toSomeString

public static String toSomeString(Object PotentiallyNullObject,
                                  String NullSubstituteString)
Returns the supplied NullSubstituteStr, if the object reference supplied in PotentiallyNullObject is null. Otherwise, PotentiallyNullObject is converted to a String by invoking its Object.toString() method, and that String is returned.

Parameters:
PotentiallyNullObject - Any object reference, or null.
NullSubstituteString - The String to returned when PotentiallyNullObject is null.
Returns:
The String object passed-in as the PotentiallyNullObject parameter, or the String returned by invoking PotentiallyNullObject.toString().

safeEquals

public static boolean safeEquals(Object A,
                                 Object B)
Safely compares two objects for equality, where one, both, or none of the objects may be null.

Parameters:
A - The first object to be used in the comparison. May be null.
B - The second object to be used in the comparison. May be null.
Returns:
true if the parameters are equal, either by reference or value, otherwise false.