public final class Objects extends Object
Modifier and Type | Method and Description |
---|---|
static <A,O extends 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 <E extends Enum<?>> |
caseInsensitiveValueOf(E[] enumValues,
String constant)
Case insensitive alternative to
Enum.valueOf(Class, String) . |
static boolean |
containsConstant(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 boolean |
containsConstant(Enum<?>[] enumValues,
String constant,
boolean caseSensitive)
Check whether the given array of enum constants contains a constant with the given name.
|
static boolean |
containsElement(Object[] array,
Object element)
Check whether the given array contains the given element.
|
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)
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 String |
identityToString(Object obj)
Return a String representation of an object's overall identity.
|
static boolean |
isArray(Object obj)
Returns
true if the specified argument is an Object or primitive array, false otherwise. |
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(byte[] array)
Returns
true if the specified byte array is null or of zero length, false if populated. |
static boolean |
isEmpty(char[] chars)
Returns
true if the specified character array is null or of zero length, false otherwise. |
static boolean |
isEmpty(Object v)
Returns
true if the specified argument:
is null , or
is a CharSequence and Strings.hasText(CharSequence) is false , or
is a Collection or Map with zero size, or
is an empty array
|
static boolean |
isEmpty(Object[] array)
true if the specified array is null or zero length, false if populated. |
static String |
nullSafeClassName(Object obj)
Determine the class name for the given object.
|
static void |
nullSafeClose(Closeable... closeables)
Iterate over the specified
Closeable instances, invoking
Closeable.close() on each one, ignoring any potential IOException s. |
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 void |
nullSafeFlush(Flushable... flushables)
Iterate over the specified
Flushable instances, invoking
Flushable.flush() on each one, ignoring any potential IOException s. |
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 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.
|
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).
|
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 isArray(Object obj)
true
if the specified argument is an Object or primitive array, false
otherwise.obj
- the object instance to checktrue
if the specified argument is an Object or primitive array, false
otherwise.public static boolean isEmpty(Object v)
true
if the specified argument:
null
, orStrings.hasText(CharSequence)
is false
, oror false
otherwise.
v
- object to checktrue
if the specified argument is empty, false
otherwise.public static boolean isEmpty(Object[] array)
true
if the specified array is null or zero length, false
if populated.array
- the array to checktrue
if the specified array is null or zero length, false
if populated.public static boolean isEmpty(byte[] array)
true
if the specified byte array is null or of zero length, false
if populated.array
- the byte array to checktrue
if the specified byte array is null or of zero length, false
if populated.public static boolean isEmpty(char[] chars)
true
if the specified character array is null or of zero length, false
otherwise.chars
- the character array to checktrue
if the specified character array is null or of zero length, false
otherwise.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 forpublic static boolean containsConstant(Enum<?>[] enumValues, String constant)
enumValues
- the enum values to check, typically the product of a call to MyEnum.values()constant
- the constant name to find (must not be null or empty string)public static boolean containsConstant(Enum<?>[] enumValues, String constant, boolean caseSensitive)
enumValues
- the enum values to check, typically the product of a call to MyEnum.values()constant
- the constant name to find (must not be null or empty string)caseSensitive
- whether case is significant in determining a matchpublic static <E extends Enum<?>> E caseInsensitiveValueOf(E[] enumValues, String constant)
Enum.valueOf(Class, String)
.E
- the concrete Enum typeenumValues
- the array of all Enum constants in question, usually per Enum.values()constant
- the constant to get the enum value ofIllegalArgumentException
- if the given constant is not found in the given array
of enum values. Use containsConstant(Enum[], String)
as a guard to
avoid this exception.public static <A,O extends A> A[] addObjectToArray(A[] array, O obj)
A
- the type of each element in the specified array
O
- the type of the specified object, which must be equal to or extend the <A>
type.array
- the array to append to (can be null
)obj
- the object to appendnull
)public static Object[] toObjectArray(Object source)
A null
source value will be converted to an
empty Object array.
source
- the (potentially primitive) arraynull
)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 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.obj
- the object to use for obtaining a hashcodenullSafeHashCode(Object[])
,
nullSafeHashCode(boolean[])
,
nullSafeHashCode(byte[])
,
nullSafeHashCode(char[])
,
nullSafeHashCode(double[])
,
nullSafeHashCode(float[])
,
nullSafeHashCode(int[])
,
nullSafeHashCode(long[])
,
nullSafeHashCode(short[])
public static int nullSafeHashCode(Object... array)
array
is null
, this method returns 0.array
- the array to obtain a hashcodepublic static int nullSafeHashCode(boolean[] array)
array
is null
, this method returns 0.array
- the boolean array to obtain a hashcodepublic static int nullSafeHashCode(byte[] array)
array
is null
, this method returns 0.array
- the byte array to obtain a hashcodepublic static int nullSafeHashCode(char[] array)
array
is null
, this method returns 0.array
- the char array to obtain a hashcodepublic static int nullSafeHashCode(double[] array)
array
is null
, this method returns 0.array
- the double array to obtain a hashcodepublic static int nullSafeHashCode(float[] array)
array
is null
, this method returns 0.array
- the float array to obtain a hashcodepublic static int nullSafeHashCode(int[] array)
array
is null
, this method returns 0.array
- the int array to obtain a hashcodepublic static int nullSafeHashCode(long[] array)
array
is null
, this method returns 0.array
- the long array to obtain a hashcodepublic static int nullSafeHashCode(short[] array)
array
is null
, this method returns 0.array
- the short array to obtain a hashcodepublic static int hashCode(boolean bool)
Boolean.hashCode()
.bool
- the boolean to get a hashcodeBoolean.hashCode()
.Boolean.hashCode()
public static int hashCode(double dbl)
Double.hashCode()
.dbl
- the double to get a hashcodeDouble.hashCode()
.Double.hashCode()
public static int hashCode(float flt)
Float.hashCode()
.flt
- the float to get a hashcodeFloat.hashCode()
.Float.hashCode()
public static int hashCode(long lng)
Long.hashCode()
.lng
- the long to get a hashcodeLong.hashCode()
.Long.hashCode()
public static String identityToString(Object obj)
obj
- the object (which may be null
).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(Object)
in that it returns
an empty String rather than "null" for a null
value.
obj
- the object to build a display String forobj
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 forobj
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 forarray
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 forarray
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 forarray
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 forarray
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 forarray
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 forarray
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 forarray
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 forarray
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 forarray
public static void nullSafeClose(Closeable... closeables)
Closeable
instances, invoking
Closeable.close()
on each one, ignoring any potential IOException
s.closeables
- the closeables to close.public static void nullSafeFlush(Flushable... flushables)
Flushable
instances, invoking
Flushable.flush()
on each one, ignoring any potential IOException
s.flushables
- the flushables to flush.Copyright © 2014–2025 jsonwebtoken.io. All rights reserved.