Class Equals


  • public class Equals
    extends java.lang.Object
    A set of helper methods which return true if the two parameters are equal to each other.
    Author:
    ayates
    See Also:
    For how to use this class
    • Constructor Summary

      Constructors 
      Constructor Description
      Equals()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean classEqual​(java.lang.Object one, java.lang.Object two)
      This method should be called before beginning any equals methods.
      static boolean equal​(boolean one, boolean two)  
      static boolean equal​(int one, int two)  
      static boolean equal​(long one, long two)  
      static boolean equal​(java.lang.Object one, java.lang.Object two)
      Does not compare class types.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Equals

        public Equals()
    • Method Detail

      • equal

        public static boolean equal​(int one,
                                    int two)
      • equal

        public static boolean equal​(long one,
                                    long two)
      • equal

        public static boolean equal​(boolean one,
                                    boolean two)
      • equal

        public static boolean equal​(java.lang.Object one,
                                    java.lang.Object two)
        Does not compare class types.
        See Also:
        classEqual(Object, Object)
      • classEqual

        public static boolean classEqual​(java.lang.Object one,
                                         java.lang.Object two)
        This method should be called before beginning any equals methods. In order to return true the method:
        1. The two given objects are the same instance using ==. This also means if both Objects are null then this method will return true (well technically they are equal)
        2. Tests that neither object is null
        3. The the two classes from the objects are equal using ==
        The boilerplate using this method then becomes:
         boolean equals = false;
         if (EqualsHelper.classEqual(this, obj)) {
           TargetClass casted = (TargetClass) obj;
           equals = (EqualsHelper.equal(this.getId(), casted.getId()) && EqualsHelper
               .equal(this.getName(), casted.getName()));
         }
         return equals;
         
        Parameters:
        one - The first object to test
        two - The second object to test
        Returns:
        A boolean indicating if the logic agrees that these two objects are equal at the class level