|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.shell.support.util.ObjectUtils
public final class ObjectUtils
Miscellaneous object utility methods. Mainly for internal use within the framework; consider Jakarta's Commons Lang for a more comprehensive suite of object utilities.
org.apache.commons.lang.ObjectUtils
Method Summary | ||
---|---|---|
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 boolean |
containsElement(Object[] array,
Object element)
Check whether the given array contains the given element. |
|
static
|
defaultIfNull(T object,
T defaultValue)
Returns the given object if not null , otherwise the given
default value |
|
static String |
getDisplayString(Object obj)
Return a content-based String representation if obj is
not null ; otherwise returns an empty String. |
|
static String |
getIdentityHexString(Object obj)
Return a hex String form of an object's identity hash code. |
|
static int |
hashCode(boolean bool)
Returns the hash code of the given boolean value. |
|
static int |
hashCode(double dbl)
Return the same value as . |
|
static int |
hashCode(float flt)
Return the same value as . |
|
static int |
hashCode(long lng)
Return the same value as . |
|
static String |
identityToString(Object obj)
Return a String representation of an object's overall identity. |
|
static boolean |
isCheckedException(Throwable ex)
Return whether the given throwable is a checked exception: that is, neither a RuntimeException nor an Error. |
|
static boolean |
isCompatibleWithThrowsClause(Throwable ex,
Class<?>... declaredExceptions)
Check whether the given exception is compatible with the exceptions declared in a throws clause. |
|
static boolean |
isEmpty(Object[] array)
Return whether the given array is empty: that is, null
or of zero length. |
|
static String |
nullSafeClassName(Object obj)
Determine the class name for the given object. |
|
static
|
nullSafeComparison(Comparable<T> one,
T other)
Compares the two given objects, with null equivalent to
null and null "less than" any
non-null instance. |
|
static boolean |
nullSafeEquals(Object o1,
Object o2)
Determine if the given objects are equal, returning true
if both are null or false if only one is
null . |
|
static int |
nullSafeHashCode(boolean... array)
Return a hash code based on the contents of the specified array. |
|
static int |
nullSafeHashCode(byte... array)
Return a hash code based on the contents of the specified array. |
|
static int |
nullSafeHashCode(char... array)
Return a hash code based on the contents of the specified array. |
|
static int |
nullSafeHashCode(double... array)
Return a hash code based on the contents of the specified array. |
|
static int |
nullSafeHashCode(float... array)
Return a hash code based on the contents of the specified array. |
|
static int |
nullSafeHashCode(int... array)
Return a hash code based on the contents of the specified array. |
|
static int |
nullSafeHashCode(long... array)
Return a hash code based on the contents of the specified array. |
|
static int |
nullSafeHashCode(Object... array)
Return a hash code based on the contents of the specified array. |
|
static int |
nullSafeHashCode(Object obj)
Return as hash code for the given object; typically the value of . |
|
static int |
nullSafeHashCode(short... array)
Return a hash code based on the contents of the specified array. |
|
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(Object... 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(short... 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 String |
toString(Object object,
String defaultValue)
Returns the String representation of the given object, or if it's null , the given default string |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static boolean isCheckedException(Throwable ex)
ex
- the throwable to check
Exception
,
RuntimeException
,
Error
public static boolean isCompatibleWithThrowsClause(Throwable ex, Class<?>... declaredExceptions)
ex
- the exception to checkeddeclaredExceptions
- the exceptions declared in the throws clause
public static boolean isEmpty(Object[] array)
null
or of zero length.
array
- the array to check
public static boolean containsElement(Object[] array, Object element)
array
- the array to check (may be null
,
in which case the return value will always be false
)element
- the element to check for
public static Object[] addObjectToArray(Object[] array, Object obj)
array
- the array to append to (can be null
)obj
- the Object to append
null
)public static Object[] toObjectArray(Object source)
A null
source value will be converted to an
empty Object array.
source
- the (potentially primitive) array
null
)
IllegalArgumentException
- if the parameter is not an arraypublic static boolean nullSafeEquals(Object o1, Object o2)
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.
o1
- first Object to compareo2
- second Object to compare
Arrays.equals(long[], long[])
public static int nullSafeHashCode(Object obj)
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.
nullSafeHashCode(Object[])
,
nullSafeHashCode(boolean[])
,
nullSafeHashCode(byte[])
,
nullSafeHashCode(char[])
,
nullSafeHashCode(double[])
,
nullSafeHashCode(float[])
,
nullSafeHashCode(int[])
,
nullSafeHashCode(long[])
,
nullSafeHashCode(short[])
public static int nullSafeHashCode(Object... array)
array
- the array from whose elements to calculate the hash code (can be null
)
null
public static int nullSafeHashCode(boolean... array)
array
- can be null
array
is null
public static int nullSafeHashCode(byte... array)
array
- can be null
array
is null
public static int nullSafeHashCode(char... array)
array
- can be null
array
is null
public static int nullSafeHashCode(double... array)
array
- can be null
array
is null
public static int nullSafeHashCode(float... array)
array
- can be null
array
is null
public static int nullSafeHashCode(int... array)
array
- can be null
array
is null
public static int nullSafeHashCode(long... array)
array
- can be null
array
is null
public static int nullSafeHashCode(short... array)
array
- can be null
array
is null
public static int hashCode(boolean bool)
bool
- the boolean for which to return the hash code
Boolean.hashCode()
public static int hashCode(double dbl)
Double.hashCode()
.
Double.hashCode()
public static int hashCode(float flt)
Float.hashCode()
.
Float.hashCode()
public static int hashCode(long lng)
Long.hashCode()
.
Long.hashCode()
public static String identityToString(Object obj)
obj
- the object (may be null
)
null
public static String getIdentityHexString(Object obj)
obj
- the object
public static String getDisplayString(Object obj)
obj
is
not null
; otherwise returns an empty String.
Differs from nullSafeToString(Object)
in that it returns
an empty String rather than "null" for a null
value.
obj
- the object to build a display String for
obj
nullSafeToString(Object)
public static String nullSafeClassName(Object obj)
Returns "null"
if obj
is null
.
obj
- the object to introspect (may be null
)
public static String nullSafeToString(Object obj)
Builds a String representation of the contents in case of an array.
Returns "null"
if obj
is null
.
obj
- the object to build a String representation for
obj
public static String nullSafeToString(Object... 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
.
array
- the array to build a String representation for
array
public static String nullSafeToString(boolean... 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
.
array
- the array to build a String representation for
array
public static String nullSafeToString(byte... 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
.
array
- the array to build a String representation for
array
public static String nullSafeToString(char... 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
.
array
- the array to build a String representation for
array
public static String nullSafeToString(double... 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
.
array
- the array to build a String representation for
array
public static String nullSafeToString(float... 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
.
array
- the array to build a String representation for
array
public static String nullSafeToString(int... 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
.
array
- the array to build a String representation for
array
public static String nullSafeToString(long... 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
.
array
- the array to build a String representation for
array
public static String nullSafeToString(short... 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
.
array
- the array to build a String representation for
array
public static <T> int nullSafeComparison(Comparable<T> one, T other)
null
equivalent to
null
and null
"less than" any
non-null
instance. Two non-null
instances are
compared using the first one's Comparable.compareTo(Object)
method.
T
- the type of objects being comparedone
- the first object being compared (can be null
)other
- the second object being compared (can be null
)
Comparable.compareTo(Object)
public static String toString(Object object, String defaultValue)
null
, the given default string
object
- the object to represent as a String (can be null
)defaultValue
- the value to return if the given object is null
(can itself be blank)
public static <T> T defaultIfNull(T object, T defaultValue)
null
, otherwise the given
default value
T
- the type of object being defaultedobject
- the object to check (can be null
)defaultValue
- the default value (can be null
)
null
iff both values are null
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |