Package org.fest.util

Class Objects


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

      Fields 
      Modifier and Type Field Description
      static int HASH_CODE_PRIME
      Prime number used to calculate the hash code of objects.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean areEqual​(java.lang.Object o1, java.lang.Object o2)
      Returns true if the given objects are equal or if both objects are null.
      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.
      static int hashCodeFor​(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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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

        public static boolean areEqual​(java.lang.Object o1,
                                       java.lang.Object o2)
        Returns true if the given objects are equal or if both objects are null.
        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 are null.
      • 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 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​(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 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.