Class Objects

java.lang.Object
org.assertj.core.util.Objects

public final class Objects extends Object
Utility methods related to objects.
Author:
Alex Ruiz, Joel Costigliola
  • Field Details

    • HASH_CODE_PRIME

      public static final int HASH_CODE_PRIME
      Prime number used to calculate the hash code of objects.
      See Also:
  • Method Details

    • areEqual

      @Deprecated public static boolean areEqual(Object o1, Object o2)
      Deprecated.
      Returns true if the arguments are deeply equal to each other, false otherwise.

      Two null values are deeply equal. If both arguments are arrays, the algorithm in Arrays.deepEquals(java.lang.Object[], java.lang.Object[]) is used to determine equality. Otherwise, equality is determined by using the Object.equals(java.lang.Object) method of the first argument.

      Parameters:
      o1 - an object.
      o2 - an object to be compared with o1 for deep equality.
      Returns:
      true if the arguments are deeply equal to each other, false otherwise.
    • areEqualArrays

      @Deprecated public static boolean areEqualArrays(Object o1, Object o2)
      Returns true if the arguments are arrays and deeply equal to each other, false otherwise.

      Once verified that the arguments are arrays, the algorithm in Arrays.deepEquals(java.lang.Object[], java.lang.Object[]) is used to determine equality.

      Parameters:
      o1 - an object.
      o2 - an object to be compared with o1 for deep equality.
      Returns:
      true if the arguments are arrays and deeply equal to each other, false otherwise.
    • namesOf

      public static String[] namesOf(Class<?>... types)
      Returns an array containing the names of the given types.
      Parameters:
      types - the given types.
      Returns:
      the names of the given types stored in an array.
    • hashCodeFor

      public static int hashCodeFor(Object o)
      Returns the hash code for the given object. If the object is null, this method returns zero. Otherwise calls the method hashCode of the given object.
      Parameters:
      o - the given object.
      Returns:
      the hash code for the given object
    • castIfBelongsToType

      public static <T> T castIfBelongsToType(Object o, Class<T> type)
      Casts the given object to the given type only if the object is of the given type. If the object is not of the given type, this method returns null.
      Type Parameters:
      T - the generic type to cast the given object to.
      Parameters:
      o - the object to cast.
      type - the given type.
      Returns:
      the casted object, or null if the given object is not to the given type.