Class ObjectUtils
This class is a clone of org.springframework.util.ObjectUtils
Miscellaneous object utility methods.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
getDisplayString
(Object obj) Return a content-based String representation ifobj
is notnull
; otherwise returns an empty String.static String
Return a hex String form of an object's identity hash code.static String
identityToString
(Object obj) Return a String representation of an object's overall identity.static boolean
Determine whether the given object is an array: either an Object array or a primitive array.static boolean
Determine whether the given object is empty.static boolean
Determine whether the given array is empty: i.e.static String
nullSafeClassName
(Object obj) Determine the class name for the given object.static boolean
nullSafeEquals
(Object o1, Object o2) Determine if the given objects are equal, returningtrue
if both arenull
orfalse
if only one isnull
.static int
nullSafeHash
(Object... elements) Return a hash code for the given elements, delegating tonullSafeHashCode(Object)
for each element.static int
nullSafeHashCode
(Object obj) Return a hash code for the given object; typically the value ofObject#hashCode()
}.static String
nullSafeToString
(boolean[] array) Return a String representation of the contents of the specified array.static String
nullSafeToString
(byte[] array) Return a String representation of the contents of the specified array.static String
nullSafeToString
(char[] array) Return a String representation of the contents of the specified array.static String
nullSafeToString
(double[] array) Return a String representation of the contents of the specified array.static String
nullSafeToString
(float[] array) Return a String representation of the contents of the specified array.static String
nullSafeToString
(int[] array) Return a String representation of the contents of the specified array.static String
nullSafeToString
(long[] array) Return a String representation of the contents of the specified array.static String
nullSafeToString
(short[] array) Return a String representation of the contents of the specified array.static String
nullSafeToString
(Object obj) Return a String representation of the specified Object.static String
nullSafeToString
(Object[] array) Return a String representation of the contents of the specified array.static String
Return a simple String representation of an object's overall identity.static String
simpleIdentityToString
(Object obj, String name) Return a simple String representation of an object's overall identity, with its name.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).
-
Constructor Details
-
ObjectUtils
public ObjectUtils()
-
-
Method Details
-
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.null
or 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 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:
true
if the object isnull
or empty- See Also:
-
toObjectArray
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:
IllegalArgumentException
- if the parameter is not an array
-
nullSafeEquals
Determine if the given objects are equal, returningtrue
if both arenull
orfalse
if 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
-
nullSafeHash
Return a hash code for the given elements, delegating tonullSafeHashCode(Object)
for each element. Contrary toObjects.hash(Object...)
, this method can handle an element that is an array.- Parameters:
elements
- the elements to be hashed- Returns:
- a hash value of the elements
-
nullSafeHashCode
Return a hash code for the given object; typically the value ofObject#hashCode()
}. If the object is an array, this method will delegate to any of theArrays.hashCode
methods. If the object isnull
, this method returns 0.- See Also:
-
identityToString
Return a String representation of an object's overall identity.- Parameters:
obj
- the object (may benull
)- Returns:
- the object's identity as String representation,
or an empty String if the object was
null
-
simpleIdentityToString
Return a simple String representation of an object's overall identity.- Parameters:
obj
- the object (may benull
)- Returns:
- the object's identity as simple String representation,
or an empty String if the object was
null
-
simpleIdentityToString
Return a simple String representation of an object's overall identity, with its name.- Parameters:
obj
- the object (may benull
)- Returns:
- the object's identity as simple String representation,
or an empty String if the object was
null
-
getIdentityHexString
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
-
getDisplayString
Return a content-based String representation ifobj
is notnull
; otherwise returns an empty String.Differs from
nullSafeToString(Object)
in that it returns an empty String rather than "null" for anull
value.- Parameters:
obj
- the object to build a display String for- Returns:
- a display String representation of
obj
- See Also:
-
nullSafeClassName
Determine the class name for the given object.Returns a
"null"
String ifobj
isnull
.- Parameters:
obj
- the object to introspect (may benull
)- Returns:
- 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 a
"null"
String ifobj
isnull
.- Parameters:
obj
- the object to build a String representation for- Returns:
- 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 a"null"
String ifarray
isnull
.- Parameters:
array
- the array to build a String representation for- Returns:
- 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 a"null"
String ifarray
isnull
.- Parameters:
array
- the array to build a String representation for- Returns:
- 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 a"null"
String ifarray
isnull
.- Parameters:
array
- the array to build a String representation for- Returns:
- 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 a"null"
String ifarray
isnull
.- Parameters:
array
- the array to build a String representation for- Returns:
- 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 a"null"
String ifarray
isnull
.- Parameters:
array
- the array to build a String representation for- Returns:
- 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 a"null"
String ifarray
isnull
.- Parameters:
array
- the array to build a String representation for- Returns:
- 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 a"null"
String ifarray
isnull
.- Parameters:
array
- the array to build a String representation for- Returns:
- 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 a"null"
String ifarray
isnull
.- Parameters:
array
- the array to build a String representation for- Returns:
- 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 a"null"
String ifarray
isnull
.- Parameters:
array
- the array to build a String representation for- Returns:
- a String representation of
array
-