org.apache.commons.lang
クラス ObjectUtils

java.lang.Object
  拡張org.apache.commons.lang.ObjectUtils

public class ObjectUtils
extends Object

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.

導入されたバージョン:
1.0
バージョン:
$Id: ObjectUtils.java,v 1.1.1.1 2004/02/13 10:02:05 hioki Exp $
作成者:
Nissim Karpenstein, Janek Bogucki, Daniel Rall, Stephen Colebourne, Gary Gregory

入れ子クラスの概要
static class ObjectUtils.Null
          Class used as a null placeholder where null has another meaning.
 
フィールドの概要
static ObjectUtils.Null NULL
          Singleton used as a null placeholder where null has another meaning.
 
コンストラクタの概要
ObjectUtils()
          ObjectUtils instances should NOT be constructed in standard programming.
 
メソッドの概要
static StringBuffer appendIdentityToString(StringBuffer buffer, Object object)
          Appends the toString that would be produced by Object if a class did not override toString itself.
static Object defaultIfNull(Object object, Object defaultValue)
          Returns a default value if the object passed is null.
static boolean equals(Object object1, Object object2)
          Compares two objects for equality, where either one or both objects may be null.
static String identityToString(Object object)
          Gets the toString that would be produced by Object if a class did not override toString itself.
static String toString(Object obj)
          Gets the toString of an Object returning an empty string ("") if null input.
static String toString(Object obj, String nullStr)
          Gets the toString of an Object returning a specified text if null input.
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

フィールドの詳細

NULL

public static final ObjectUtils.Null NULL

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

For example, in a HashMap the 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.

コンストラクタの詳細

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.

メソッドの詳細

defaultIfNull

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
 

パラメータ:
object - the Object to test, may be null
defaultValue - the default value to return, may be null
戻り値:
object if it is not null, defaultValue otherwise

equals

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
 

パラメータ:
object1 - the first object, may be null
object2 - the second object, may be null
戻り値:
true if the values of both objects are the same

identityToString

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"
 

パラメータ:
object - the object to create a toString for, may be null
戻り値:
the default toString text, or null if null passed in

appendIdentityToString

public static StringBuffer appendIdentityToString(StringBuffer buffer,
                                                  Object 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")
 

パラメータ:
buffer - the buffer to append to, may be null
object - the object to create a toString for, may be null
戻り値:
the default toString text, or null if null passed in
導入されたバージョン:
2.0

toString

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"
 

パラメータ:
obj - the Object to toString, may be null
戻り値:
the passed in Object's toString, or nullStr if null input
導入されたバージョン:
2.0
関連項目:
StringUtils.defaultString(String), String.valueOf(Object)

toString

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"
 

パラメータ:
obj - the Object to toString, may be null
nullStr - the String to return if null input, may be null
戻り値:
the passed in Object's toString, or nullStr if null input
導入されたバージョン:
2.0
関連項目:
StringUtils.defaultString(String,String), String.valueOf(Object)


このドキュメントは、Ja-Jakartaにより訳されました。 コメントがある場合は report@jajakarta.orgまでお願いします。
Translated into Japanese by jajakarta.org. The original page is here.
Copyright (c) 2002-2003 - Apache Software Foundation