Home » commons-lang-2.5-src » org.apache.commons » lang » [javadoc | source]
org.apache.commons.lang
public class: ObjectUtils [javadoc | source]
java.lang.Object
   org.apache.commons.lang.ObjectUtils

Operations on Object.

This class tries to handle null input gracefully. An exception will generally not be thrown for a null input. Each method documents its behaviour in more detail.

Nested Class Summary:
public static class  ObjectUtils.Null  

Class used as a null placeholder where null has another meaning.

For example, in a HashMap the {@link java.util.HashMap#get(java.lang.Object)} method returns null if the Map contains null or if there is no matching key. The Null placeholder can be used to distinguish between these two cases.

Another example is Hashtable, where null cannot be stored.

 
Field Summary
public static final  Null NULL   

Singleton used as a null placeholder where null has another meaning.

For example, in a HashMap the java.util.HashMap#get(java.lang.Object) method returns null if the Map contains null or if there is no matching key. The Null placeholder can be used to distinguish between these two cases.

Another example is Hashtable, where null cannot be stored.

This instance is Serializable.

 
Constructor:
 public ObjectUtils() 
Method from org.apache.commons.lang.ObjectUtils Summary:
appendIdentityToString,   defaultIfNull,   equals,   hashCode,   identityToString,   identityToString,   max,   min,   toString,   toString
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.commons.lang.ObjectUtils Detail:
 public static StringBuffer appendIdentityToString(StringBuffer buffer,
    Object object) 
Deprecated! The - design of this method is bad - see LANG-360. Instead, use identityToString(StringBuffer, Object).

    Appends the toString that would be produced by Object if a class did not override toString itself. null will return null.

    ObjectUtils.appendIdentityToString(*, null)            = null
    ObjectUtils.appendIdentityToString(null, "")           = "java.lang.String@1e23"
    ObjectUtils.appendIdentityToString(null, Boolean.TRUE) = "java.lang.Boolean@7fa"
    ObjectUtils.appendIdentityToString(buf, Boolean.TRUE)  = buf.append("java.lang.Boolean@7fa")
    
 public static Object defaultIfNull(Object object,
    Object defaultValue) 

    Returns a default value if the object passed is null.

    ObjectUtils.defaultIfNull(null, null)      = null
    ObjectUtils.defaultIfNull(null, "")        = ""
    ObjectUtils.defaultIfNull(null, "zz")      = "zz"
    ObjectUtils.defaultIfNull("abc", *)        = "abc"
    ObjectUtils.defaultIfNull(Boolean.TRUE, *) = Boolean.TRUE
    
 public static boolean equals(Object object1,
    Object object2) 

    Compares two objects for equality, where either one or both objects may be null.

    ObjectUtils.equals(null, null)                  = true
    ObjectUtils.equals(null, "")                    = false
    ObjectUtils.equals("", null)                    = false
    ObjectUtils.equals("", "")                      = true
    ObjectUtils.equals(Boolean.TRUE, null)          = false
    ObjectUtils.equals(Boolean.TRUE, "true")        = false
    ObjectUtils.equals(Boolean.TRUE, Boolean.TRUE)  = true
    ObjectUtils.equals(Boolean.TRUE, Boolean.FALSE) = false
    
 public static int hashCode(Object obj) 

    Gets the hash code of an object returning zero when the object is null.

    ObjectUtils.hashCode(null)   = 0
    ObjectUtils.hashCode(obj)    = obj.hashCode()
    
 public static String identityToString(Object object) 

    Gets the toString that would be produced by Object if a class did not override toString itself. null will return null.

    ObjectUtils.identityToString(null)         = null
    ObjectUtils.identityToString("")           = "java.lang.String@1e23"
    ObjectUtils.identityToString(Boolean.TRUE) = "java.lang.Boolean@7fa"
    
 public static  void identityToString(StringBuffer buffer,
    Object object) 

    Appends the toString that would be produced by Object if a class did not override toString itself. null will throw a NullPointerException for either of the two parameters.

    ObjectUtils.identityToString(buf, "")            = buf.append("java.lang.String@1e23"
    ObjectUtils.identityToString(buf, Boolean.TRUE)  = buf.append("java.lang.Boolean@7fa"
    ObjectUtils.identityToString(buf, Boolean.TRUE)  = buf.append("java.lang.Boolean@7fa")
    
 public static Object max(Comparable c1,
    Comparable c2) 
    Null safe comparison of Comparables.
 public static Object min(Comparable c1,
    Comparable c2) 
    Null safe comparison of Comparables.
 public static String toString(Object obj) 

    Gets the toString of an Object returning an empty string ("") if null input.

    ObjectUtils.toString(null)         = ""
    ObjectUtils.toString("")           = ""
    ObjectUtils.toString("bat")        = "bat"
    ObjectUtils.toString(Boolean.TRUE) = "true"
    
 public static String toString(Object obj,
    String nullStr) 

    Gets the toString of an Object returning a specified text if null input.

    ObjectUtils.toString(null, null)           = null
    ObjectUtils.toString(null, "null")         = "null"
    ObjectUtils.toString("", "null")           = ""
    ObjectUtils.toString("bat", "null")        = "bat"
    ObjectUtils.toString(Boolean.TRUE, "null") = "true"