Class ObjectUtils

java.lang.Object
com.aspectran.utils.ObjectUtils

public abstract class ObjectUtils extends Object

This class is a clone of org.springframework.util.ObjectUtils

Miscellaneous object utility methods.
  • Constructor Details

    • ObjectUtils

      public ObjectUtils()
  • Method Details

    • isArray

      public static boolean isArray(@Nullable Object obj)
      Determine whether the given object is an array: either an Object array or a primitive array.
      Parameters:
      obj - the object to check
    • isEmpty

      public static boolean isEmpty(@Nullable Object[] array)
      Determine whether the given array is empty: i.e. null or of zero length.
      Parameters:
      array - the array to check
      See Also:
    • isEmpty

      public static boolean isEmpty(@Nullable Object obj)
      Determine whether the given object is empty.

      This method supports the following object types.

      If the given object is non-null and not one of the aforementioned supported types, this method returns false.

      Parameters:
      obj - the object to check
      Returns:
      true if the object is null or empty
      See Also:
    • toObjectArray

      public static Object[] toObjectArray(@Nullable Object source)
      Convert the given array (which may be a primitive array) to an object array (if necessary of primitive wrapper objects).

      A null source value will be converted to an empty Object array.

      Parameters:
      source - the (potentially primitive) array
      Returns:
      the corresponding object array (never null)
      Throws:
      IllegalArgumentException - if the parameter is not an array
    • nullSafeEquals

      public 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.

      Compares arrays with Arrays.equals, performing an equality check based on the array elements rather than the array reference.

      Parameters:
      o1 - first Object to compare
      o2 - second Object to compare
      Returns:
      whether the given objects are equal
    • nullSafeHash

      public static int nullSafeHash(@Nullable Object... elements)
      Return a hash code for the given elements, delegating to nullSafeHashCode(Object) for each element. Contrary to Objects.hash(Object...), this method can handle an element that is an array.
      Parameters:
      elements - the elements to be hashed
      Returns:
      a hash value of the elements
    • nullSafeHashCode

      public static int nullSafeHashCode(@Nullable Object obj)
      Return a hash code for the given object; typically the value of Object#hashCode()}. If the object is an array, this method will delegate to any of the Arrays.hashCode methods. If the object is null, this method returns 0.
      See Also:
    • identityToString

      public static String identityToString(@Nullable Object obj)
      Return a String representation of an object's overall identity.
      Parameters:
      obj - the object (may be null)
      Returns:
      the object's identity as String representation, or an empty String if the object was null
    • simpleIdentityToString

      public static String simpleIdentityToString(@Nullable Object obj)
      Return a simple String representation of an object's overall identity.
      Parameters:
      obj - the object (may be null)
      Returns:
      the object's identity as simple String representation, or an empty String if the object was null
    • simpleIdentityToString

      @NonNull public static String simpleIdentityToString(@Nullable Object obj, @NonNull String name)
      Return a simple String representation of an object's overall identity, with its name.
      Parameters:
      obj - the object (may be null)
      Returns:
      the object's identity as simple String representation, or an empty String if the object was null
    • getIdentityHexString

      @NonNull public static String getIdentityHexString(Object obj)
      Return a hex String form of an object's identity hash code.
      Parameters:
      obj - the object
      Returns:
      the object's identity code in hex notation