org.apache.commons.lang
Class ObjectUtils

java.lang.Object
  |
  +--org.apache.commons.lang.ObjectUtils

public class ObjectUtils
extends java.lang.Object

Common Object manipulation routines.

Version:
$Id: ObjectUtils.java,v 1.4 2002/09/22 09:18:33 scolebourne Exp $
Author:
Nissim Karpenstein, Janek Bogucki, Daniel Rall, Stephen Colebourne

Inner Class Summary
static class ObjectUtils.Null
          Class used as a null placeholder where null has another meaning.
 
Field Summary
static ObjectUtils.Null NULL
          Singleton used as a null placeholder where null has another meaning.
 
Constructor Summary
ObjectUtils()
          ObjectUtils instances should NOT be constructed in standard programming.
 
Method Summary
static java.lang.Object defaultIfNull(java.lang.Object object, java.lang.Object defaultValue)
          Returns a default value if the object passed is null.
static boolean equals(java.lang.Object object1, java.lang.Object object2)
          Compares two objects for equality, where either one or both objects may be null.
static java.lang.String identityToString(java.lang.Object object)
          Gets the toString that would be produced by Object if a class did not override toString itself.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

NULL

public static final ObjectUtils.Null NULL
Singleton used as a null placeholder where null has another meaning.

For example, in a HashMap the get(key) 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 Detail

ObjectUtils

public ObjectUtils()
ObjectUtils instances should NOT be constructed in standard programming. Instead, the class should be used as ObjectUtils.defaultIfNull("a","b");. This constructor is public to permit tools that require a JavaBean instance to operate.
Method Detail

defaultIfNull

public static java.lang.Object defaultIfNull(java.lang.Object object,
                                             java.lang.Object defaultValue)
Returns a default value if the object passed is null.
Parameters:
object - the object to test
defaultValue - the default value to return
Returns:
object if it is not null, defaultValue otherwise

equals

public static boolean equals(java.lang.Object object1,
                             java.lang.Object object2)
Compares two objects for equality, where either one or both objects may be null.
Parameters:
object1 - the first object
object2 - the second object
Returns:
true if the values of both objects are the same

identityToString

public static java.lang.String identityToString(java.lang.Object object)
Gets the toString that would be produced by Object if a class did not override toString itself. Null will return null.
Parameters:
object - the object to create a toString for, may be null
Returns:
the default toString text, or null if null passed in


Copyright (c) 2001-2002 - Apache Software Foundation