Package org.fest.util
Class Objects
java.lang.Object
org.fest.util.Objects
Understands utility methods related to objects.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Prime number used to calculate the hash code of objects. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Returnstrue
if the given objects are equal or if both objects arenull
.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.static int
Returns the hash code for the given object.static String[]
Returns an array containing the names of the given types.
-
Field Details
-
HASH_CODE_PRIME
public static final int HASH_CODE_PRIMEPrime number used to calculate the hash code of objects.- See Also:
-
-
Constructor Details
-
Objects
private Objects()
-
-
Method Details
-
areEqual
Returnstrue
if the given objects are equal or if both objects arenull
.- Parameters:
o1
- one of the objects to compare.o2
- one of the objects to compare.- Returns:
true
if the given objects are equal or if both objects arenull
.
-
namesOf
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
Returns the hash code for the given object. If the object isnull
, this method returns zero. Otherwise calls the methodhashCode
of the given object.- Parameters:
o
- the given object.- Returns:
- the hash code for the given object
-
castIfBelongsToType
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
null
if the given object is not to the given type.
-