Class ObjectUtils
- java.lang.Object
-
- com.aspectran.core.util.ObjectUtils
-
public abstract class ObjectUtils extends java.lang.ObjectThis class is a clone of org.springframework.util.ObjectUtils
Miscellaneous object utility methods.
-
-
Constructor Summary
Constructors Constructor Description ObjectUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringgetDisplayString(java.lang.Object obj)Return a content-based String representation ifobjis notnull; otherwise returns an empty String.static booleanisArray(java.lang.Object obj)Determine whether the given object is an array: either an Object array or a primitive array.static booleanisEmpty(java.lang.Object obj)Determine whether the given object is empty.static booleanisEmpty(java.lang.Object[] array)Determine whether the given array is empty: i.e.static java.lang.StringnullSafeClassName(java.lang.Object obj)Determine the class name for the given object.static booleannullSafeEquals(java.lang.Object o1, java.lang.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(java.lang.Object obj)Return as hash code for the given object; typically the value ofObject#hashCode()}.static intnullSafeHashCode(java.lang.Object[] array)Return a hash code based on the contents of the specified array.static java.lang.StringnullSafeToString(boolean[] array)Return a String representation of the contents of the specified array.static java.lang.StringnullSafeToString(byte[] array)Return a String representation of the contents of the specified array.static java.lang.StringnullSafeToString(char[] array)Return a String representation of the contents of the specified array.static java.lang.StringnullSafeToString(double[] array)Return a String representation of the contents of the specified array.static java.lang.StringnullSafeToString(float[] array)Return a String representation of the contents of the specified array.static java.lang.StringnullSafeToString(int[] array)Return a String representation of the contents of the specified array.static java.lang.StringnullSafeToString(long[] array)Return a String representation of the contents of the specified array.static java.lang.StringnullSafeToString(short[] array)Return a String representation of the contents of the specified array.static java.lang.StringnullSafeToString(java.lang.Object obj)Return a String representation of the specified Object.static java.lang.StringnullSafeToString(java.lang.Object[] array)Return a String representation of the contents of the specified array.static java.lang.Object[]toObjectArray(java.lang.Object source)Convert the given array (which may be a primitive array) to an object array (if necessary of primitive wrapper objects).
-
-
-
Method Detail
-
isArray
public static boolean isArray(@Nullable java.lang.Object obj)
Determine whether the given object is an array: either an Object array or a primitive array.- Parameters:
obj- the object to check
-
isEmpty
public static boolean isEmpty(@Nullable java.lang.Object[] array)
Determine whether the given array is empty: i.e.nullor of zero length.- Parameters:
array- the array to check- See Also:
isEmpty(Object)
-
isEmpty
public static boolean isEmpty(@Nullable java.lang.Object obj)
Determine whether the given object is empty.This method supports the following object types.
Optional: considered empty ifOptional.empty()Array: considered empty if its length is zeroCharSequence: considered empty if its length is zeroCollection: delegates toCollection.isEmpty()Map: delegates toMap.isEmpty()
If the given object is non-null and not one of the aforementioned supported types, this method returns
false.- Parameters:
obj- the object to check- Returns:
trueif the object isnullor empty- See Also:
Optional.isPresent(),isEmpty(Object[]),StringUtils.hasLength(CharSequence)
-
toObjectArray
public static java.lang.Object[] toObjectArray(@Nullable java.lang.Object source)
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.- Parameters:
source- the (potentially primitive) array- Returns:
- the corresponding object array (never
null) - Throws:
java.lang.IllegalArgumentException- if the parameter is not an array
-
nullSafeEquals
public static boolean nullSafeEquals(java.lang.Object o1, java.lang.Object o2)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.- Parameters:
o1- first Object to compareo2- second Object to compare- Returns:
- whether the given objects are equal
-
nullSafeHashCode
public static int nullSafeHashCode(java.lang.Object obj)
Return as hash code for the given object; typically the value ofObject#hashCode()}. If the object is an array, this method will delegate to any of thenullSafeHashCodemethods for arrays in this class. If the object isnull, this method returns 0.- Parameters:
obj- the given object- Returns:
- a hash code value
-
nullSafeHashCode
public static int nullSafeHashCode(java.lang.Object[] array)
Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0.- Parameters:
array- the specified array- Returns:
- a hash code value
-
nullSafeHashCode
public static int nullSafeHashCode(boolean[] array)
Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0.- Parameters:
array- the specified array- Returns:
- a hash code value
-
nullSafeHashCode
public static int nullSafeHashCode(byte[] array)
Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0.- Parameters:
array- the specified array- Returns:
- a hash code value
-
nullSafeHashCode
public static int nullSafeHashCode(char[] array)
Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0.- Parameters:
array- the specified array- Returns:
- a hash code value
-
nullSafeHashCode
public static int nullSafeHashCode(double[] array)
Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0.- Parameters:
array- the specified array- Returns:
- a hash code value
-
nullSafeHashCode
public static int nullSafeHashCode(float[] array)
Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0.- Parameters:
array- the specified array- Returns:
- a hash code value
-
nullSafeHashCode
public static int nullSafeHashCode(int[] array)
Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0.- Parameters:
array- the specified array- Returns:
- a hash code value
-
nullSafeHashCode
public static int nullSafeHashCode(long[] array)
Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0.- Parameters:
array- the specified array- Returns:
- a hash code value
-
nullSafeHashCode
public static int nullSafeHashCode(short[] array)
Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0.- Parameters:
array- the specified array- Returns:
- a hash code value
-
getDisplayString
public static java.lang.String getDisplayString(@Nullable java.lang.Object obj)
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.- Parameters:
obj- the object to build a display String for- Returns:
- a display String representation of
obj - See Also:
nullSafeToString(Object)
-
nullSafeClassName
public static java.lang.String nullSafeClassName(@Nullable java.lang.Object obj)
Determine the class name for the given object.Returns a
"null"String ifobjisnull.- Parameters:
obj- the object to introspect (may benull)- Returns:
- the corresponding class name
-
nullSafeToString
public static java.lang.String nullSafeToString(@Nullable java.lang.Object obj)
Return a String representation of the specified Object.Builds a String representation of the contents in case of an array. Returns a
"null"String ifobjisnull.- Parameters:
obj- the object to build a String representation for- Returns:
- a String representation of
obj
-
nullSafeToString
public static java.lang.String nullSafeToString(@Nullable java.lang.Object[] array)
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 a"null"String ifarrayisnull.- Parameters:
array- the array to build a String representation for- Returns:
- a String representation of
array
-
nullSafeToString
public static java.lang.String nullSafeToString(@Nullable boolean[] array)
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 a"null"String ifarrayisnull.- Parameters:
array- the array to build a String representation for- Returns:
- a String representation of
array
-
nullSafeToString
public static java.lang.String nullSafeToString(@Nullable byte[] array)
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 a"null"String ifarrayisnull.- Parameters:
array- the array to build a String representation for- Returns:
- a String representation of
array
-
nullSafeToString
public static java.lang.String nullSafeToString(@Nullable char[] array)
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 a"null"String ifarrayisnull.- Parameters:
array- the array to build a String representation for- Returns:
- a String representation of
array
-
nullSafeToString
public static java.lang.String nullSafeToString(@Nullable double[] array)
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 a"null"String ifarrayisnull.- Parameters:
array- the array to build a String representation for- Returns:
- a String representation of
array
-
nullSafeToString
public static java.lang.String nullSafeToString(@Nullable float[] array)
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 a"null"String ifarrayisnull.- Parameters:
array- the array to build a String representation for- Returns:
- a String representation of
array
-
nullSafeToString
public static java.lang.String nullSafeToString(@Nullable int[] array)
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 a"null"String ifarrayisnull.- Parameters:
array- the array to build a String representation for- Returns:
- a String representation of
array
-
nullSafeToString
public static java.lang.String nullSafeToString(@Nullable long[] array)
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 a"null"String ifarrayisnull.- Parameters:
array- the array to build a String representation for- Returns:
- a String representation of
array
-
nullSafeToString
public static java.lang.String nullSafeToString(@Nullable short[] array)
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 a"null"String ifarrayisnull.- Parameters:
array- the array to build a String representation for- Returns:
- a String representation of
array
-
-