类 AbstractObjectUtils
- java.lang.Object
-
- com.alibaba.nacos.common.utils.AbstractObjectUtils
-
public abstract class AbstractObjectUtils extends java.lang.ObjectCopy from https://github.com/spring-projects/spring-framework.git, with less modifications Miscellaneous object utility methods.Mainly for internal use within the framework.
Thanks to Alex Ruiz for contributing several enhancements to this class!
- 从以下版本开始:
- 19.03.2004
- 作者:
- Juergen Hoeller, Keith Donald, Rod Johnson, Rob Harrop, Chris Beams, Sam Brannen
-
-
字段概要
字段 修饰符和类型 字段 说明 private static java.lang.StringARRAY_ELEMENT_SEPARATORprivate static java.lang.StringARRAY_ENDprivate static java.lang.StringARRAY_STARTprivate static java.lang.StringEMPTY_ARRAYprivate static java.lang.Object[]EMPTY_OBJECT_ARRAYprivate static java.lang.StringEMPTY_STRINGprivate static intINITIAL_HASHprivate static intMULTIPLIERprivate static java.lang.StringNULL_STRING
-
构造器概要
构造器 构造器 说明 AbstractObjectUtils()
-
方法概要
所有方法 静态方法 具体方法 已过时的方法 修饰符和类型 方法 说明 static <A,O extends A>
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.private static booleanarrayEquals(java.lang.Object o1, java.lang.Object o2)Compare the given arrays withArrays.equals, performing an equality check based on the array elements rather than the array reference.static <E extends java.lang.Enum<?>>
EcaseInsensitiveValueOf(E[] enumValues, java.lang.String constant)Case insensitive alternative toEnum.valueOf(Class, String).static booleancontainsConstant(java.lang.Enum<?>[] enumValues, java.lang.String constant)Check whether the given array of enum constants contains a constant with the given name, ignoring case when determining a match.static booleancontainsConstant(java.lang.Enum<?>[] enumValues, java.lang.String constant, boolean caseSensitive)Check whether the given array of enum constants contains a constant with the given name.static booleancontainsElement(java.lang.Object[] array, java.lang.Object element)Check whether the given array contains the given element.static java.lang.StringgetDisplayString(java.lang.Object obj)Return a content-based String representation ifobjis notnull; otherwise returns an empty String.static java.lang.StringgetIdentityHexString(java.lang.Object obj)Return a hex String form of an object's identity hash code.static inthashCode(boolean bool)已过时。as of Spring Framework 5.0, in favor of the native JDK 8 variantstatic inthashCode(double dbl)已过时。as of Spring Framework 5.0, in favor of the native JDK 8 variantstatic inthashCode(float flt)已过时。as of Spring Framework 5.0, in favor of the native JDK 8 variantstatic inthashCode(long lng)已过时。as of Spring Framework 5.0, in favor of the native JDK 8 variantstatic java.lang.StringidentityToString(java.lang.Object obj)Return a String representation of an object's overall identity.static booleanisArray(java.lang.Object obj)Determine whether the given object is an array: either an Object array or a primitive array.static booleanisCheckedException(java.lang.Throwable ex)Return whether the given throwable is a checked exception: that is, neither a RuntimeException nor an Error.static booleanisCompatibleWithThrowsClause(java.lang.Throwable ex, java.lang.Class<?>... declaredExceptions)Check whether the given exception is compatible with the specified exception types, as declared in a throws clause.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).static java.lang.ObjectunwrapOptional(java.lang.Object obj)Unwrap the given object which is potentially aOptional.
-
-
-
字段详细资料
-
INITIAL_HASH
private static final int INITIAL_HASH
- 另请参阅:
- 常量字段值
-
MULTIPLIER
private static final int MULTIPLIER
- 另请参阅:
- 常量字段值
-
EMPTY_STRING
private static final java.lang.String EMPTY_STRING
- 另请参阅:
- 常量字段值
-
NULL_STRING
private static final java.lang.String NULL_STRING
- 另请参阅:
- 常量字段值
-
ARRAY_START
private static final java.lang.String ARRAY_START
- 另请参阅:
- 常量字段值
-
ARRAY_END
private static final java.lang.String ARRAY_END
- 另请参阅:
- 常量字段值
-
EMPTY_ARRAY
private static final java.lang.String EMPTY_ARRAY
- 另请参阅:
- 常量字段值
-
ARRAY_ELEMENT_SEPARATOR
private static final java.lang.String ARRAY_ELEMENT_SEPARATOR
- 另请参阅:
- 常量字段值
-
EMPTY_OBJECT_ARRAY
private static final java.lang.Object[] EMPTY_OBJECT_ARRAY
-
-
方法详细资料
-
isCheckedException
public static boolean isCheckedException(java.lang.Throwable ex)
Return whether the given throwable is a checked exception: that is, neither a RuntimeException nor an Error.- 参数:
ex- the throwable to check- 返回:
- whether the throwable is a checked exception
- 另请参阅:
Exception,RuntimeException,Error
-
isCompatibleWithThrowsClause
public static boolean isCompatibleWithThrowsClause(java.lang.Throwable ex, java.lang.Class<?>... declaredExceptions)Check whether the given exception is compatible with the specified exception types, as declared in a throws clause.- 参数:
ex- the exception to checkdeclaredExceptions- the exception types declared in the throws clause- 返回:
- whether the given exception is compatible
-
isArray
public static boolean isArray(java.lang.Object obj)
Determine whether the given object is an array: either an Object array or a primitive array.- 参数:
obj- the object to check
-
isEmpty
public static boolean isEmpty(java.lang.Object[] array)
Determine whether the given array is empty: i.e.nullor of zero length.- 参数:
array- the array to check- 另请参阅:
isEmpty(Object)
-
isEmpty
public static boolean isEmpty(java.lang.Object obj)
Determine whether the given object is empty.This method supports the following object types.
Optional: considered empty if notOptional.isPresent()Array: considered empty if its length is zeroCharSequence: considered empty if its length is zero
If the given object is non-null and not one of the aforementioned supported types, this method returns
false.- 参数:
obj- the object to check- 返回:
trueif the object isnullor empty- 从以下版本开始:
- 4.2
- 另请参阅:
Optional.isPresent(),isEmpty(Object[])
-
unwrapOptional
public static java.lang.Object unwrapOptional(java.lang.Object obj)
Unwrap the given object which is potentially aOptional.- 参数:
obj- the candidate object- 返回:
- either the value held within the
Optional,nullif theOptionalis empty, or simply the given object as-is - 从以下版本开始:
- 5.0
-
containsElement
public static boolean containsElement(java.lang.Object[] array, java.lang.Object element)Check whether the given array contains the given element.- 参数:
array- the array to check (may benull, in which case the return value will always befalse)element- the element to check for- 返回:
- whether the element has been found in the given array
-
containsConstant
public static boolean containsConstant(java.lang.Enum<?>[] enumValues, java.lang.String constant)Check whether the given array of enum constants contains a constant with the given name, ignoring case when determining a match.- 参数:
enumValues- the enum values to check, typically obtained viaMyEnum.values()constant- the constant name to find (must not be null or empty string)- 返回:
- whether the constant has been found in the given array
-
containsConstant
public static boolean containsConstant(java.lang.Enum<?>[] enumValues, java.lang.String constant, boolean caseSensitive)Check whether the given array of enum constants contains a constant with the given name.- 参数:
enumValues- the enum values to check, typically obtained viaMyEnum.values()constant- the constant name to find (must not be null or empty string)caseSensitive- whether case is significant in determining a match- 返回:
- whether the constant has been found in the given array
-
caseInsensitiveValueOf
public static <E extends java.lang.Enum<?>> E caseInsensitiveValueOf(E[] enumValues, java.lang.String constant)Case insensitive alternative toEnum.valueOf(Class, String).- 类型参数:
E- the concrete Enum type- 参数:
enumValues- the array of all Enum constants in question, usually perEnum.values()constant- the constant to get the enum value of- 抛出:
java.lang.IllegalArgumentException- if the given constant is not found in the given array of enum values. UsecontainsConstant(Enum[], String)as a guard to avoid this exception.
-
addObjectToArray
public static <A,O extends A> 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.- 参数:
array- the array to append to (can benull)obj- the object to append- 返回:
- the new array (of the same component type; never
null)
-
toObjectArray
public 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).A
nullsource value will be converted to an empty Object array.- 参数:
source- the (potentially primitive) array- 返回:
- the corresponding object array (never
null) - 抛出:
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.- 参数:
o1- first Object to compareo2- second Object to compare- 返回:
- whether the given objects are equal
- 另请参阅:
Object.equals(Object),Arrays.equals(long[], long[])
-
arrayEquals
private static boolean arrayEquals(java.lang.Object o1, java.lang.Object o2)Compare the given arrays withArrays.equals, performing an equality check based on the array elements rather than the array reference.- 参数:
o1- first array to compareo2- second array to compare- 返回:
- whether the given objects are equal
- 另请参阅:
nullSafeEquals(Object, Object),Arrays.equals(long[], long[])
-
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.
-
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.
-
nullSafeHashCode
public static int nullSafeHashCode(boolean[] array)
Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0.
-
nullSafeHashCode
public static int nullSafeHashCode(byte[] array)
Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0.
-
nullSafeHashCode
public static int nullSafeHashCode(char[] array)
Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0.
-
nullSafeHashCode
public static int nullSafeHashCode(double[] array)
Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0.
-
nullSafeHashCode
public static int nullSafeHashCode(float[] array)
Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0.
-
nullSafeHashCode
public static int nullSafeHashCode(int[] array)
Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0.
-
nullSafeHashCode
public static int nullSafeHashCode(long[] array)
Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0.
-
nullSafeHashCode
public static int nullSafeHashCode(short[] array)
Return a hash code based on the contents of the specified array. Ifarrayisnull, this method returns 0.
-
hashCode
@Deprecated public static int hashCode(boolean bool)
已过时。as of Spring Framework 5.0, in favor of the native JDK 8 variantReturn the same value asBoolean.hashCode(boolean)}.
-
hashCode
@Deprecated public static int hashCode(double dbl)
已过时。as of Spring Framework 5.0, in favor of the native JDK 8 variantReturn the same value asDouble.hashCode(double)}.
-
hashCode
@Deprecated public static int hashCode(float flt)
已过时。as of Spring Framework 5.0, in favor of the native JDK 8 variantReturn the same value asFloat.hashCode(float)}.
-
hashCode
@Deprecated public static int hashCode(long lng)
已过时。as of Spring Framework 5.0, in favor of the native JDK 8 variantReturn the same value asLong.hashCode(long)}.
-
identityToString
public static java.lang.String identityToString(java.lang.Object obj)
Return a String representation of an object's overall identity.- 参数:
obj- the object (may benull)- 返回:
- the object's identity as String representation,
or an empty String if the object was
null
-
getIdentityHexString
public static java.lang.String getIdentityHexString(java.lang.Object obj)
Return a hex String form of an object's identity hash code.- 参数:
obj- the object- 返回:
- the object's identity code in hex notation
-
getDisplayString
public static java.lang.String getDisplayString(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.- 参数:
obj- the object to build a display String for- 返回:
- a display String representation of
obj - 另请参阅:
nullSafeToString(Object)
-
nullSafeClassName
public static java.lang.String nullSafeClassName(java.lang.Object obj)
Determine the class name for the given object.Returns a
"null"String ifobjisnull.- 参数:
obj- the object to introspect (may benull)- 返回:
- the corresponding class name
-
nullSafeToString
public static java.lang.String nullSafeToString(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.- 参数:
obj- the object to build a String representation for- 返回:
- a String representation of
obj
-
nullSafeToString
public static java.lang.String nullSafeToString(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.- 参数:
array- the array to build a String representation for- 返回:
- a String representation of
array
-
nullSafeToString
public static java.lang.String nullSafeToString(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.- 参数:
array- the array to build a String representation for- 返回:
- a String representation of
array
-
nullSafeToString
public static java.lang.String nullSafeToString(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.- 参数:
array- the array to build a String representation for- 返回:
- a String representation of
array
-
nullSafeToString
public static java.lang.String nullSafeToString(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.- 参数:
array- the array to build a String representation for- 返回:
- a String representation of
array
-
nullSafeToString
public static java.lang.String nullSafeToString(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.- 参数:
array- the array to build a String representation for- 返回:
- a String representation of
array
-
nullSafeToString
public static java.lang.String nullSafeToString(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.- 参数:
array- the array to build a String representation for- 返回:
- a String representation of
array
-
nullSafeToString
public static java.lang.String nullSafeToString(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.- 参数:
array- the array to build a String representation for- 返回:
- a String representation of
array
-
nullSafeToString
public static java.lang.String nullSafeToString(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.- 参数:
array- the array to build a String representation for- 返回:
- a String representation of
array
-
nullSafeToString
public static java.lang.String nullSafeToString(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.- 参数:
array- the array to build a String representation for- 返回:
- a String representation of
array
-
-