类 ObjectUtils
Mainly for internal use within the framework; consider Jakarta's Commons Lang for a more comprehensive suite of object utilities.
Thanks to Alex Ruiz for contributing several enhancements to this class!
- 从以下版本开始:
- 19.03.2004 // * @see org.apache.commons.lang.ObjectUtils
- 作者:
- Juergen Hoeller, Keith Donald, Rod Johnson, Rob Harrop
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static Object[]addObjectToArray(Object[] array, Object obj) Append the given Object to the given array, returning a new array consisting of the input array contents plus the given Object.static booleancontainsElement(Object[] array, Object element) Check whether the given array contains the given element.static StringgetDisplayString(Object obj) Return a content-based String representation ifobjis notnull; otherwise returns an empty String.static StringReturn a hex String form of an object's identity hash code.static inthashCode(boolean bool) Return the same value as.Boolean.hashCode()static inthashCode(double dbl) Return the same value as.Double.hashCode()static inthashCode(float flt) Return the same value as.Float.hashCode()static inthashCode(long lng) Return the same value as.Long.hashCode()static StringidentityToString(Object obj) Return a String representation of an object's overall identity.static booleanDetermine whether the given object is an array: either an Object array or a primitive array.static booleanReturn whether the given throwable is a checked exception: that is, neither a RuntimeException nor an Error.static booleanisCompatibleWithThrowsClause(Throwable ex, Class<?>[] declaredExceptions) Check whether the given exception is compatible with the exceptions declared in a throws clause.static booleanDetermine whether the given array is empty: i.e.static StringnullSafeClassName(Object obj) Determine the class name for the given object.static booleannullSafeEquals(Object o1, Object o2) Determine if the given objects are equal, returningtrueif both arenullorfalseif only one isnull.static intnullSafeHashCode(boolean[] array) Return a hash code based on the contents of the specified array.static intnullSafeHashCode(byte[] array) Return a hash code based on the contents of the specified array.static intnullSafeHashCode(char[] array) Return a hash code based on the contents of the specified array.static intnullSafeHashCode(double[] array) Return a hash code based on the contents of the specified array.static intnullSafeHashCode(float[] array) Return a hash code based on the contents of the specified array.static intnullSafeHashCode(int[] array) Return a hash code based on the contents of the specified array.static intnullSafeHashCode(long[] array) Return a hash code based on the contents of the specified array.static intnullSafeHashCode(short[] array) Return a hash code based on the contents of the specified array.static intnullSafeHashCode(Object obj) Return as hash code for the given object; typically the value of.Object.hashCode()static intnullSafeHashCode(Object[] array) Return a hash code based on the contents of the specified array.static StringnullSafeToString(boolean[] array) Return a String representation of the contents of the specified array.static StringnullSafeToString(byte[] array) Return a String representation of the contents of the specified array.static StringnullSafeToString(char[] array) Return a String representation of the contents of the specified array.static StringnullSafeToString(double[] array) Return a String representation of the contents of the specified array.static StringnullSafeToString(float[] array) Return a String representation of the contents of the specified array.static StringnullSafeToString(int[] array) Return a String representation of the contents of the specified array.static StringnullSafeToString(long[] array) Return a String representation of the contents of the specified array.static StringnullSafeToString(short[] array) Return a String representation of the contents of the specified array.static StringnullSafeToString(Object obj) Return a String representation of the specified Object.static StringnullSafeToString(Object[] array) Return a String representation of the contents of the specified array.static Object[]toObjectArray(Object source) Convert the given array (which may be a primitive array) to an object array (if necessary of primitive wrapper objects).
-
构造器详细资料
-
ObjectUtils
public ObjectUtils()
-
-
方法详细资料
-
isCheckedException
Return whether the given throwable is a checked exception: that is, neither a RuntimeException nor an Error.- 参数:
ex- the throwable to check- 返回:
- whether the throwable is a checked exception
- 另请参阅:
-
isCompatibleWithThrowsClause
Check whether the given exception is compatible with the exceptions declared in a throws clause.- 参数:
ex- the exception to checkeddeclaredExceptions- the exceptions declared in the throws clause- 返回:
- whether the given exception is compatible
-
isArray
Determine whether the given object is an array: either an Object array or a primitive array.- 参数:
obj- the object to check
-
isEmpty
Determine whether the given array is empty: i.e.nullor of zero length.- 参数:
array- the array to check
-
containsElement
Check whether the given array contains the given element.- 参数:
array- the array to check (may benull, in which case the return value will always befalse)element- the element to check for- 返回:
- whether the element has been found in the given array
-
addObjectToArray
Append the given Object to the given array, returning a new array consisting of the input array contents plus the given Object.- 参数:
array- the array to append to (can benull)obj- the Object to append- 返回:
- the new array (of the same component type; never
null)
-
toObjectArray
Convert the given array (which may be a primitive array) to an object array (if necessary of primitive wrapper objects).A
nullsource value will be converted to an empty Object array.- 参数:
source- the (potentially primitive) array- 返回:
- the corresponding object array (never
null) - 抛出:
IllegalArgumentException- if the parameter is not an array
-
nullSafeEquals
Determine if the given objects are equal, returningtrueif both arenullorfalseif only one isnull.Compares arrays with
Arrays.equals, performing an equality check based on the array elements rather than the array reference.- 参数:
o1- first Object to compareo2- second Object to compare- 返回:
- whether the given objects are equal
- 另请参阅:
-
nullSafeHashCode
Return as hash code for the given object; typically the value of. If the object is an array, this method will delegate to any of theObject.hashCode()nullSafeHashCodemethods for arrays in this class. If the object isnull, this method returns 0. -
nullSafeHashCode
Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0. -
nullSafeHashCode
public static int nullSafeHashCode(boolean[] array) Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0. -
nullSafeHashCode
public static int nullSafeHashCode(byte[] array) Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0. -
nullSafeHashCode
public static int nullSafeHashCode(char[] array) Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0. -
nullSafeHashCode
public static int nullSafeHashCode(double[] array) Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0. -
nullSafeHashCode
public static int nullSafeHashCode(float[] array) Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0. -
nullSafeHashCode
public static int nullSafeHashCode(int[] array) Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0. -
nullSafeHashCode
public static int nullSafeHashCode(long[] array) Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0. -
nullSafeHashCode
public static int nullSafeHashCode(short[] array) Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0. -
hashCode
public static int hashCode(boolean bool) Return the same value as.Boolean.hashCode()- 另请参阅:
-
hashCode
public static int hashCode(double dbl) Return the same value as.Double.hashCode()- 另请参阅:
-
hashCode
public static int hashCode(float flt) Return the same value as.Float.hashCode()- 另请参阅:
-
hashCode
public static int hashCode(long lng) Return the same value as.Long.hashCode()- 另请参阅:
-
identityToString
Return a String representation of an object's overall identity.- 参数:
obj- the object (may benull)- 返回:
- the object's identity as String representation,
or an empty String if the object was
null
-
getIdentityHexString
Return a hex String form of an object's identity hash code.- 参数:
obj- the object- 返回:
- the object's identity code in hex notation
-
getDisplayString
Return a content-based String representation ifobjis notnull; otherwise returns an empty String.Differs from
nullSafeToString(Object)in that it returns an empty String rather than "null" for anullvalue.- 参数:
obj- the object to build a display String for- 返回:
- a display String representation of
obj - 另请参阅:
-
nullSafeClassName
Determine the class name for the given object.Returns
"null"ifobjisnull.- 参数:
obj- the object to introspect (may benull)- 返回:
- the corresponding class name
-
nullSafeToString
Return a String representation of the specified Object.Builds a String representation of the contents in case of an array. Returns
"null"ifobjisnull.- 参数:
obj- the object to build a String representation for- 返回:
- a String representation of
obj
-
nullSafeToString
Return a String representation of the contents of the specified array.The String representation consists of a list of the array's elements, enclosed in curly braces (
"{}"). Adjacent elements are separated by the characters", "(a comma followed by a space). Returns"null"ifarrayisnull.- 参数:
array- the array to build a String representation for- 返回:
- a String representation of
array
-
nullSafeToString
Return a String representation of the contents of the specified array.The String representation consists of a list of the array's elements, enclosed in curly braces (
"{}"). Adjacent elements are separated by the characters", "(a comma followed by a space). Returns"null"ifarrayisnull.- 参数:
array- the array to build a String representation for- 返回:
- a String representation of
array
-
nullSafeToString
Return a String representation of the contents of the specified array.The String representation consists of a list of the array's elements, enclosed in curly braces (
"{}"). Adjacent elements are separated by the characters", "(a comma followed by a space). Returns"null"ifarrayisnull.- 参数:
array- the array to build a String representation for- 返回:
- a String representation of
array
-
nullSafeToString
Return a String representation of the contents of the specified array.The String representation consists of a list of the array's elements, enclosed in curly braces (
"{}"). Adjacent elements are separated by the characters", "(a comma followed by a space). Returns"null"ifarrayisnull.- 参数:
array- the array to build a String representation for- 返回:
- a String representation of
array
-
nullSafeToString
Return a String representation of the contents of the specified array.The String representation consists of a list of the array's elements, enclosed in curly braces (
"{}"). Adjacent elements are separated by the characters", "(a comma followed by a space). Returns"null"ifarrayisnull.- 参数:
array- the array to build a String representation for- 返回:
- a String representation of
array
-
nullSafeToString
Return a String representation of the contents of the specified array.The String representation consists of a list of the array's elements, enclosed in curly braces (
"{}"). Adjacent elements are separated by the characters", "(a comma followed by a space). Returns"null"ifarrayisnull.- 参数:
array- the array to build a String representation for- 返回:
- a String representation of
array
-
nullSafeToString
Return a String representation of the contents of the specified array.The String representation consists of a list of the array's elements, enclosed in curly braces (
"{}"). Adjacent elements are separated by the characters", "(a comma followed by a space). Returns"null"ifarrayisnull.- 参数:
array- the array to build a String representation for- 返回:
- a String representation of
array
-
nullSafeToString
Return a String representation of the contents of the specified array.The String representation consists of a list of the array's elements, enclosed in curly braces (
"{}"). Adjacent elements are separated by the characters", "(a comma followed by a space). Returns"null"ifarrayisnull.- 参数:
array- the array to build a String representation for- 返回:
- a String representation of
array
-
nullSafeToString
Return a String representation of the contents of the specified array.The String representation consists of a list of the array's elements, enclosed in curly braces (
"{}"). Adjacent elements are separated by the characters", "(a comma followed by a space). Returns"null"ifarrayisnull.- 参数:
array- the array to build a String representation for- 返回:
- a String representation of
array
-