Package com.gigaspaces.internal.utils
Class ObjectUtils
java.lang.Object
com.gigaspaces.internal.utils.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.
- Author:
- kimchy
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TassertArgumentNotNull(T argument, String argumentName) Throws an IllegalArgumentException if the provided argument is null.static <T> TdefaultIfNull(T object, T defaultValue) Returns default object if the requested one is nullstatic <T> TdefaultIfNullDeferred(T object, java.util.function.Supplier<T> defaultValueSupplier) static booleanstatic ObjectgetDefaultValue(Class<?> type) Returns null for reference types and a boxed default value for primitive typesstatic Class<?>getPrimitive(String typeName) Gets the class represeting the primitive type denoted by 'name' if 'name' denotes a primitive and null otherwise.static inthashCode(boolean bool) Return the same value as.Boolean.hashCode()static inthashCode(double dbl) Return the same value as.Double.hashCode()static inthashCode(float flt) Return the same value as.Float.hashCode()static inthashCode(long lng) Return the same value as.Long.hashCode()static intstatic booleanisPrimitive(String typeName) Returns whether the specified type name is of primitive typestatic booleannullSafeEquals(Object o1, 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(Object obj) Return as hash code for the given object; typically the value of.Object.hashCode()static intnullSafeHashCode(Object[] array) Return a hash code based on the contents of the specified array.
-
Constructor Details
-
ObjectUtils
public ObjectUtils()
-
-
Method Details
-
hashCode
-
equals
-
nullSafeEquals
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.- Parameters:
o1- first Object to compareo2- second Object to compare- Returns:
- whether the given objects are equal
- See Also:
-
nullSafeHashCode
Return as hash code for the given object; typically the value of. If the object is an array, this method will delegate to any of theObject.hashCode()nullSafeHashCodemethods for arrays in this class. If the object isnull, this method returns 0. -
nullSafeHashCode
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
public static int hashCode(boolean bool) Return the same value as.Boolean.hashCode()- See Also:
-
hashCode
public static int hashCode(double dbl) Return the same value as.Double.hashCode()- See Also:
-
hashCode
public static int hashCode(float flt) Return the same value as.Float.hashCode()- See Also:
-
hashCode
public static int hashCode(long lng) Return the same value as.Long.hashCode()- See Also:
-
isPrimitive
Returns whether the specified type name is of primitive type -
getPrimitive
Gets the class represeting the primitive type denoted by 'name' if 'name' denotes a primitive and null otherwise. -
getDefaultValue
Returns null for reference types and a boxed default value for primitive types -
defaultIfNull
public static <T> T defaultIfNull(T object, T defaultValue) Returns default object if the requested one is null -
defaultIfNullDeferred
public static <T> T defaultIfNullDeferred(T object, java.util.function.Supplier<T> defaultValueSupplier) -
assertArgumentNotNull
Throws an IllegalArgumentException if the provided argument is null.- Type Parameters:
T- The argument type.- Parameters:
argument- The argument instance to check.argumentName- The argument name (for thrown Exception message).- Returns:
- Returns the provided argument if exception wasn't thrown
-