package org.springframework.util;
Miscellaneous object utility methods. Mainly for internal use within the
framework; consider Jakarta's Commons Lang for a more comprehensive suite
of object utilities.
- Author(s):
- Juergen Hoeller
- Keith Donald
- Rod Johnson
- Rob Harrop
- Alex Ruiz
- Since:
- 19.03.2004
- See also:
org.apache.commons.lang.ObjectUtils
Return whether the given throwable is a checked exception:
that is, neither a RuntimeException nor an Error.
Check whether the given exception is compatible with the exceptions
declared in a throws clause.
- Parameters:
ex the exception to checkeddeclaredExceptions the exceptions declared in the throws clause- Returns:
- whether the given exception is compatible
if (declaredExceptions != null) { for (int i = 0; i < declaredExceptions.length; i++) { Return whether the given array is empty: that is,
null
or of zero length.
- Parameters:
array the array to check- Returns:
- whether the given array is empty
return (array == null || array.length == 0);
Check whether the given array contains the given element.
- Parameters:
array the array to check (may be null,
in which case the return value will always be false)element the element to check for- Returns:
- whether the element has been found in the given array
for (int i = 0; i < array.length; i++) { Append the given Object to the given array, returning a new array
consisting of the input array contents plus the given Object.
- Parameters:
array the array to append to (can be null)obj the Object to append- Returns:
- the new array (of the same component type; never
null)
int newArrLength = (array != null ? array.length + 1 : 1);
System.arraycopy(array, 0, newArr, 0, array.length);
newArr[newArr.length - 1] = obj;
Convert the given array (which may be a primitive array) to an
object array (if necessary of primitive wrapper objects).
A null source value will be converted to an
empty Object array.
- Parameters:
source the (potentially primitive) array- Returns:
- the corresponding object array (never
null) - Throws:
java.lang.IllegalArgumentException if the parameter is not an array
if (source instanceof Object[]) { for (int i = 0; i < length; i++) { newArray[i] = Array.get(source, i);
Determine if the given objects are equal, returning
true
if both are
null or
false if only one is
null.
Compares arrays with Arrays.equals, performing an equality
check based on the array elements rather than the array reference.
if (o1 == null || o2 == null) { if (o1 instanceof boolean[] && o2 instanceof boolean[]) { return Arrays.equals((boolean[]) o1, (boolean[]) o2);
if (o1 instanceof byte[] && o2 instanceof byte[]) { return Arrays.equals((byte[]) o1, (byte[]) o2);
if (o1 instanceof char[] && o2 instanceof char[]) { return Arrays.equals((char[]) o1, (char[]) o2);
if (o1 instanceof double[] && o2 instanceof double[]) { return Arrays.equals((double[]) o1, (double[]) o2);
if (o1 instanceof float[] && o2 instanceof float[]) { return Arrays.equals((float[]) o1, (float[]) o2);
if (o1 instanceof int[] && o2 instanceof int[]) { return Arrays.equals((int[]) o1, (int[]) o2);
if (o1 instanceof long[] && o2 instanceof long[]) { return Arrays.equals((long[]) o1, (long[]) o2);
if (o1 instanceof short[] && o2 instanceof short[]) { return Arrays.equals((short[]) o1, (short[]) o2);
Return as hash code for the given object; typically the value of
java.lang.Object.hashCode(). If the object is an array,
this method will delegate to any of the
nullSafeHashCode
methods for arrays in this class. If the object is
null,
this method returns 0.
if (obj instanceof Object[]) { if (obj instanceof boolean[]) { if (obj instanceof byte[]) { if (obj instanceof char[]) { if (obj instanceof double[]) { if (obj instanceof float[]) { if (obj instanceof int[]) { if (obj instanceof long[]) { if (obj instanceof short[]) { Return a hash code based on the contents of the specified array.
If
array is
null, this method returns 0.
int arraySize = array.length;
for (int i = 0; i < arraySize; i++) { Return a hash code based on the contents of the specified array.
If
array is
null, this method returns 0.
int arraySize = array.length;
for (int i = 0; i < arraySize; i++) { Return a hash code based on the contents of the specified array.
If
array is
null, this method returns 0.
int arraySize = array.length;
for (int i = 0; i < arraySize; i++) { Return a hash code based on the contents of the specified array.
If
array is
null, this method returns 0.
int arraySize = array.length;
for (int i = 0; i < arraySize; i++) { Return a hash code based on the contents of the specified array.
If
array is
null, this method returns 0.
int arraySize = array.length;
for (int i = 0; i < arraySize; i++) { Return a hash code based on the contents of the specified array.
If
array is
null, this method returns 0.
int arraySize = array.length;
for (int i = 0; i < arraySize; i++) { Return a hash code based on the contents of the specified array.
If
array is
null, this method returns 0.
int arraySize = array.length;
for (int i = 0; i < arraySize; i++) { Return a hash code based on the contents of the specified array.
If
array is
null, this method returns 0.
int arraySize = array.length;
for (int i = 0; i < arraySize; i++) { Return a hash code based on the contents of the specified array.
If
array is
null, this method returns 0.
int arraySize = array.length;
for (int i = 0; i < arraySize; i++) { public static int hashCode(boolean bool) { return bool ? 1231 : 1237;
public static int hashCode(double dbl) { return (int) (lng ^ (lng >>> 32));
Return a String representation of an object's overall identity.
- Parameters:
obj the object (may be null)- Returns:
- the object's identity as String representation,
or an empty String if the object was
null
Return a hex String form of an object's identity hash code.
- Parameters:
obj the object- Returns:
- the object's identity code in hex notation
Return a content-based String representation if
obj is
not
null; otherwise returns an empty String.
Differs from nullSafeToString(java.lang.Object) in that it returns
an empty String rather than "null" for a null value.
Determine the class name for the given object.
Returns "null" if obj is null.
- Parameters:
obj the object to introspect (may be null)- Returns:
- the corresponding class name
Return a String representation of the specified Object.
Builds a String representation of the contents in case of an array.
Returns "null" if obj is null.
- Parameters:
obj the object to build a String representation for- Returns:
- a String representation of
obj
if (obj instanceof Object[]) { if (obj instanceof boolean[]) { if (obj instanceof byte[]) { if (obj instanceof char[]) { if (obj instanceof double[]) { if (obj instanceof float[]) { if (obj instanceof int[]) { if (obj instanceof long[]) { if (obj instanceof short[]) { 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" if array is null.
- Parameters:
array the array to build a String representation for- Returns:
- a String representation of
array
int length = array.length;
for (int i = 0; i < length; i++) { 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" if array is null.
- Parameters:
array the array to build a String representation for- Returns:
- a String representation of
array
int length = array.length;
for (int i = 0; i < length; i++) { 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" if array is null.
- Parameters:
array the array to build a String representation for- Returns:
- a String representation of
array
int length = array.length;
for (int i = 0; i < length; i++) { 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" if array is null.
- Parameters:
array the array to build a String representation for- Returns:
- a String representation of
array
int length = array.length;
for (int i = 0; i < length; i++) { 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" if array is null.
- Parameters:
array the array to build a String representation for- Returns:
- a String representation of
array
int length = array.length;
for (int i = 0; i < length; i++) { 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" if array is null.
- Parameters:
array the array to build a String representation for- Returns:
- a String representation of
array
int length = array.length;
for (int i = 0; i < length; i++) { 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" if array is null.
- Parameters:
array the array to build a String representation for- Returns:
- a String representation of
array
int length = array.length;
for (int i = 0; i < length; i++) { 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" if array is null.
- Parameters:
array the array to build a String representation for- Returns:
- a String representation of
array
int length = array.length;
for (int i = 0; i < length; i++) { 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" if array is null.
- Parameters:
array the array to build a String representation for- Returns:
- a String representation of
array
int length = array.length;
for (int i = 0; i < length; i++) {