Package org.assertj.core.util
Class Objects
- java.lang.Object
-
- org.assertj.core.util.Objects
-
public final class Objects extends java.lang.ObjectUtility methods related to objects.
-
-
Field Summary
Fields Modifier and Type Field Description static intHASH_CODE_PRIMEPrime number used to calculate the hash code of objects.
-
Constructor Summary
Constructors Modifier Constructor Description privateObjects()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static booleanareEqual(java.lang.Object o1, java.lang.Object o2)Deprecated.UseObjects.deepEquals(Object, Object)instead.static booleanareEqualArrays(java.lang.Object o1, java.lang.Object o2)Deprecated.Use eitherObjects.deepEquals(Object, Object)orArrays.deepEquals(Object[], Object[]).static <T> TcastIfBelongsToType(java.lang.Object o, java.lang.Class<T> type)Casts the given object to the given type only if the object is of the given type.static inthashCodeFor(java.lang.Object o)Returns the hash code for the given object.static java.lang.String[]namesOf(java.lang.Class<?>... types)Returns an array containing the names of the given types.
-
-
-
Field Detail
-
HASH_CODE_PRIME
public static final int HASH_CODE_PRIME
Prime number used to calculate the hash code of objects.- See Also:
- Constant Field Values
-
-
Method Detail
-
areEqual
@Deprecated public static boolean areEqual(java.lang.Object o1, java.lang.Object o2)Deprecated.UseObjects.deepEquals(Object, Object)instead.Returnstrueif the arguments are deeply equal to each other,falseotherwise.Two
nullvalues are deeply equal. If both arguments are arrays, the algorithm inArrays.deepEquals(java.lang.Object[], java.lang.Object[])is used to determine equality. Otherwise, equality is determined by using theObject.equals(java.lang.Object)method of the first argument.- Parameters:
o1- an object.o2- an object to be compared witho1for deep equality.- Returns:
trueif the arguments are deeply equal to each other,falseotherwise.
-
areEqualArrays
@Deprecated public static boolean areEqualArrays(java.lang.Object o1, java.lang.Object o2)Deprecated.Use eitherObjects.deepEquals(Object, Object)orArrays.deepEquals(Object[], Object[]).Returnstrueif the arguments are arrays and deeply equal to each other,falseotherwise.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 witho1for deep equality.- Returns:
trueif the arguments are arrays and deeply equal to each other,falseotherwise.
-
namesOf
public static java.lang.String[] namesOf(java.lang.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(java.lang.Object o)
Returns the hash code for the given object. If the object isnull, this method returns zero. Otherwise calls the methodhashCodeof the given object.- Parameters:
o- the given object.- Returns:
- the hash code for the given object
-
castIfBelongsToType
public static <T> T castIfBelongsToType(java.lang.Object o, java.lang.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 returnsnull.- 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
nullif the given object is not to the given type.
-
-