Package org.springframework.util
Class ObjectUtils
java.lang.Object
org.springframework.util.ObjectUtils
Miscellaneous object utility methods.
Mainly for internal use within the framework.
Thanks to Alex Ruiz for contributing several enhancements to this class!
- Since:
- 19.03.2004
- Author:
- Juergen Hoeller, Keith Donald, Rod Johnson, Rob Harrop, Chris Beams, Sam Brannen
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <A,O extends A>
A[]addObjectToArray(A[] array, O obj) Append the given object to the given array, returning a new array consisting of the input array contents plus the given object.static <A,O extends A>
A[]addObjectToArray(A[] array, O obj, int position) Add the given object to the given array at the specified position, returning a new array consisting of the input array contents plus the given object.static <E extends Enum<?>>
EcaseInsensitiveValueOf(E[] enumValues, String constant) Case insensitive alternative toEnum.valueOf(Class, String).static booleancontainsConstant(Enum<?>[] enumValues, String constant) Check whether the given array of enum constants contains a constant with the given name, ignoring case when determining a match.static booleancontainsConstant(Enum<?>[] enumValues, String constant, boolean caseSensitive) Check whether the given array of enum constants contains a constant with the given name.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 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 specified exception types, as declared in athrowsclause.static booleanDetermine whether the given object is empty.static booleanDetermine whether the given array is empty: i.e.static StringnullSafeClassName(Object obj) Determine the class name for the given object.static StringGenerate a null-safe, concise string representation of the supplied object as described below.static booleannullSafeEquals(Object o1, Object o2) Determine if the given objects are equal, returningtrueif both arenullorfalseif only one isnull.static intnullSafeHash(Object... elements) Return a hash code for the given elements, delegating tonullSafeHashCode(Object)for each element.static intnullSafeHashCode(boolean[] array) Deprecated.static intnullSafeHashCode(byte[] array) Deprecated.as of 6.1 in favor ofArrays.hashCode(byte[])static intnullSafeHashCode(char[] array) Deprecated.as of 6.1 in favor ofArrays.hashCode(char[])static intnullSafeHashCode(double[] array) Deprecated.as of 6.1 in favor ofArrays.hashCode(double[])static intnullSafeHashCode(float[] array) Deprecated.as of 6.1 in favor ofArrays.hashCode(float[])static intnullSafeHashCode(int[] array) Deprecated.as of 6.1 in favor ofArrays.hashCode(int[])static intnullSafeHashCode(long[] array) Deprecated.as of 6.1 in favor ofArrays.hashCode(long[])static intnullSafeHashCode(short[] array) Deprecated.as of 6.1 in favor ofArrays.hashCode(short[])static intnullSafeHashCode(Object obj) Return a hash code for the given object; typically the value ofObject#hashCode()}.static intnullSafeHashCode(Object[] array) Deprecated.as of 6.1 in favor ofArrays.hashCode(Object[])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).static ObjectunwrapOptional(Object obj) Unwrap the given object which is potentially aOptional.
-
Constructor Details
-
ObjectUtils
public ObjectUtils()
-
-
Method Details
-
isCheckedException
Return whether the given throwable is a checked exception: that is, neither a RuntimeException nor an Error.- Parameters:
ex- the throwable to check- Returns:
- whether the throwable is a checked exception
- See Also:
-
isCompatibleWithThrowsClause
public static boolean isCompatibleWithThrowsClause(Throwable ex, @Nullable Class<?>... declaredExceptions) Check whether the given exception is compatible with the specified exception types, as declared in athrowsclause.- Parameters:
ex- the exception to checkdeclaredExceptions- the exception types declared in the throws clause- Returns:
- whether the given exception is compatible
-
isArray
Determine whether the given object is an array: either an Object array or a primitive array.- Parameters:
obj- the object to check
-
isEmpty
Determine whether the given array is empty: i.e.nullor of zero length.- Parameters:
array- the array to check- See Also:
-
isEmpty
Determine whether the given object is empty.This method supports the following object types.
Optional: considered empty if notOptional.isPresent()Array: considered empty if its length is zeroCharSequence: considered empty if its length is zeroCollection: delegates toCollection.isEmpty()
-
Arrays.hashCode(boolean[])