public abstract class ObjectUtils extends Object
Constructor and Description |
---|
ObjectUtils() |
Modifier and Type | Method and Description |
---|---|
static <T> T[] |
addObjectToArray(T[] array,
T obj)
Append the given Object to the given array, returning a new array consisting of the input
array contents plus the given Object.
|
static <T> T |
assertArgumentNotNull(T argument,
String argumentName)
Throws an IllegalArgumentException if the provided argument is null.
|
static boolean |
equals(Object o1,
Object o2) |
static Object |
getDefaultValue(Class<?> type)
Returns null for reference types and a boxed default value for primitive types
|
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 Class<?> |
getPrimitive(String typeName)
Gets the class represeting the primitive type denoted by 'name' if 'name' denotes a primitive
and null otherwise.
|
static int |
hashCode(boolean bool)
Return the same value as
. |
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 int |
hashCode(Object o) |
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 boolean |
isPrimitive(String typeName)
Returns whether the specified type name is of primitive type
|
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 obj)
Return as hash code for the given object; typically the value of
. |
static int |
nullSafeHashCode(Object[] array)
Return a hash code based on the contents of the specified array.
|
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 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 |
nullSafeToString(short[] array)
Return a String representation of the contents of the specified array.
|
public static boolean isCheckedException(Throwable ex)
ex
- the throwable to checkException
,
RuntimeException
,
Error
public static boolean isCompatibleWithThrowsClause(Throwable ex, Class<?>[] declaredExceptions)
ex
- the exception to checkeddeclaredExceptions
- the exceptions declared in the throws clausepublic static boolean isEmpty(Object[] array)
null
or of zero length.array
- the array to checkpublic static <T> T[] addObjectToArray(T[] array, T obj)
array
- the array to append to (can be null
)obj
- the Object to appendnull
)public static int hashCode(Object o)
public 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 compareArrays.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.public static int nullSafeHashCode(Object[] array)
array
is
null
, this method returns 0.public static int nullSafeHashCode(boolean[] array)
array
is
null
, this method returns 0.public static int nullSafeHashCode(byte[] array)
array
is
null
, this method returns 0.public static int nullSafeHashCode(char[] array)
array
is
null
, this method returns 0.public static int nullSafeHashCode(double[] array)
array
is
null
, this method returns 0.public static int nullSafeHashCode(float[] array)
array
is
null
, this method returns 0.public static int nullSafeHashCode(int[] array)
array
is
null
, this method returns 0.public static int nullSafeHashCode(long[] array)
array
is
null
, this method returns 0.public static int nullSafeHashCode(short[] array)
array
is
null
, this method returns 0.public static int hashCode(boolean bool)
Boolean.hashCode()
.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 nullSafeToString(Object obj)
Returns the
String 'null'
if obj
is null
.
obj
- the object whose String representation to returnobj
public static String nullSafeToString(Object[] array)
"{}"
). Adjacent elements are separated by the characters ", "
(a
comma followed by a space). Returns "null"
if array
is
null
.array
- the array whose String representation to returnarray
public static String nullSafeToString(boolean[] array)
"{}"
). Adjacent elements are separated by the characters ", "
(a
comma followed by a space). Returns "null"
if array
is
null
.array
- the array whose String representation to returnarray
public static String nullSafeToString(byte[] array)
"{}"
). Adjacent elements are separated by the characters ", "
(a
comma followed by a space). Returns "null"
if array
is
null
.array
- the array whose String representation to returnarray
public static String nullSafeToString(char[] array)
"{}"
). Adjacent elements are separated by the characters ", "
(a
comma followed by a space). Returns "null"
if array
is
null
.array
- the array whose String representation to returnarray
public static String nullSafeToString(double[] array)
"{}"
). Adjacent elements are separated by the characters ", "
(a
comma followed by a space). Returns "null"
if array
is
null
.array
- the array whose String representation to returnarray
public static String nullSafeToString(float[] array)
"{}"
). Adjacent elements are separated by the characters ", "
(a
comma followed by a space). Returns "null"
if array
is
null
.array
- the array whose String representation to returnarray
public static String nullSafeToString(int[] array)
"{}"
). Adjacent elements are separated by the characters ", "
(a
comma followed by a space). Returns "null"
if array
is
null
.array
- the array whose String representation to returnarray
public static String nullSafeToString(long[] array)
"{}"
). Adjacent elements are separated by the characters ", "
(a
comma followed by a space). Returns "null"
if array
is
null
.array
- the array whose String representation to returnarray
public static String nullSafeToString(short[] array)
"{}"
). Adjacent elements are separated by the characters ", "
(a
comma followed by a space). Returns "null"
if array
is
null
.array
- the array whose String representation to returnarray
public static String identityToString(Object obj)
obj
- the object (may be null
)null
if the object
was null
public static String getIdentityHexString(Object obj)
obj
- the objectpublic static String getDisplayString(Object obj)
obj
is not null
;
otherwise returns an empty String
. Differs from nullSafeToString
in that it returns an empty String rather than "null" for a null
value.
nullSafeToString(Object)
public static boolean isPrimitive(String typeName)
public static Class<?> getPrimitive(String typeName)
public static Object getDefaultValue(Class<?> type)
public static <T> T assertArgumentNotNull(T argument, String argumentName)
T
- The argument type.argument
- The argument instance to check.argumentName
- The argument name (for thrown Exception message).Copyright © GigaSpaces.