Class EqualsHelper

java.lang.Object
com.helger.base.equals.EqualsHelper

public class EqualsHelper extends Object
Helper class providing various methods for comparing objects by identity, by value, and for arrays of all primitive types.
Author:
Philip Helger
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    equals(boolean aObj1, boolean aObj2)
    Check if two values are equal.
    static boolean
    equals(byte aObj1, byte aObj2)
    Check if two values are equal.
    static boolean
    equals(char aObj1, char aObj2)
    Check if two values are equal.
    static boolean
    equals(double aObj1, double aObj2)
    Check if two double values are equal.
    static boolean
    equals(float aObj1, float aObj2)
    Check if two float values are equal.
    static boolean
    equals(int aObj1, int aObj2)
    Check if two values are equal.
    static boolean
    equals(long aObj1, long aObj2)
    Check if two values are equal.
    static boolean
    equals(short aObj1, short aObj2)
    Check if two values are equal.
    static boolean
    equals(@Nullable Object aObj1, @Nullable Object aObj2)
    Check if two values are equal.
    static <T> boolean
    equalsCustom(@Nullable T aObj1, @Nullable T aObj2, @NonNull BiPredicate<T,T> aPredicate)
    Perform an equals check with a custom predicate that is only invoked, if both objects are non-null.
    static boolean
    equalsIgnoreCase(@Nullable String sObj1, @Nullable String sObj2)
    Check if the passed strings are equals case insensitive handling null appropriately.
    static <T> boolean
    identityDifferent(@Nullable T aObj1, @Nullable T aObj2)
    The only place where objects are compared by identity.
    static <T> boolean
    identityEqual(@Nullable T aObj1, @Nullable T aObj2)
    The only place where objects are compared by identity.

    Methods inherited from class java.lang.Object

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

    • EqualsHelper

      protected EqualsHelper()
  • Method Details

    • identityEqual

      public static <T> boolean identityEqual(@Nullable T aObj1, @Nullable T aObj2)
      The only place where objects are compared by identity.
      Type Parameters:
      T - Type to check.
      Parameters:
      aObj1 - First object. May be null.
      aObj2 - Second object. May be null.
      Returns:
      true if both objects are null or reference the same object.
    • identityDifferent

      public static <T> boolean identityDifferent(@Nullable T aObj1, @Nullable T aObj2)
      The only place where objects are compared by identity.
      Type Parameters:
      T - Type to check.
      Parameters:
      aObj1 - First object. May be null.
      aObj2 - Second object. May be null.
      Returns:
      true if one object is null or if they reference a different object.
      Since:
      11.1.7
    • equals

      @UsedInGeneratedCode public static boolean equals(boolean aObj1, boolean aObj2)
      Check if two values are equal. This method only exists, so that no type differentiation is needed.
      Parameters:
      aObj1 - First value
      aObj2 - Second value
      Returns:
      true if they are equal, false otherwise.
    • equals

      @UsedInGeneratedCode public static boolean equals(byte aObj1, byte aObj2)
      Check if two values are equal. This method only exists, so that no type differentiation is needed.
      Parameters:
      aObj1 - First value
      aObj2 - Second value
      Returns:
      true if they are equal, false otherwise.
    • equals

      @UsedInGeneratedCode public static boolean equals(char aObj1, char aObj2)
      Check if two values are equal. This method only exists, so that no type differentiation is needed.
      Parameters:
      aObj1 - First value
      aObj2 - Second value
      Returns:
      true if they are equal, false otherwise.
    • equals

      @UsedInGeneratedCode public static boolean equals(double aObj1, double aObj2)
      Check if two double values are equal. This is necessary, because in some cases, the "==" operator returns wrong results.
      Parameters:
      aObj1 - First double
      aObj2 - Second double
      Returns:
      true if they are equal, false otherwise.
    • equals

      @UsedInGeneratedCode public static boolean equals(float aObj1, float aObj2)
      Check if two float values are equal. This is necessary, because in some cases, the "==" operator returns wrong results.
      Parameters:
      aObj1 - First float
      aObj2 - Second float
      Returns:
      true if they are equal, false otherwise.
    • equals

      @UsedInGeneratedCode public static boolean equals(int aObj1, int aObj2)
      Check if two values are equal. This method only exists, so that no type differentiation is needed.
      Parameters:
      aObj1 - First value
      aObj2 - Second value
      Returns:
      true if they are equal, false otherwise.
    • equals

      @UsedInGeneratedCode public static boolean equals(long aObj1, long aObj2)
      Check if two values are equal. This method only exists, so that no type differentiation is needed.
      Parameters:
      aObj1 - First value
      aObj2 - Second value
      Returns:
      true if they are equal, false otherwise.
    • equals

      @UsedInGeneratedCode public static boolean equals(short aObj1, short aObj2)
      Check if two values are equal. This method only exists, so that no type differentiation is needed.
      Parameters:
      aObj1 - First value
      aObj2 - Second value
      Returns:
      true if they are equal, false otherwise.
    • equals

      @UsedInGeneratedCode public static boolean equals(@Nullable Object aObj1, @Nullable Object aObj2)
      Check if two values are equal. This method only exists, so that no type differentiation is needed.
      Parameters:
      aObj1 - First value
      aObj2 - Second value
      Returns:
      true if they are equal, false otherwise.
    • equalsIgnoreCase

      public static boolean equalsIgnoreCase(@Nullable String sObj1, @Nullable String sObj2)
      Check if the passed strings are equals case insensitive handling null appropriately.
      Parameters:
      sObj1 - First object to compare
      sObj2 - Second object to compare
      Returns:
      true if they are equal case insensitive, false otherwise.
    • equalsCustom

      public static <T> boolean equalsCustom(@Nullable T aObj1, @Nullable T aObj2, @NonNull BiPredicate<T,T> aPredicate)
      Perform an equals check with a custom predicate that is only invoked, if both objects are non-null.
      Type Parameters:
      T - parameter type
      Parameters:
      aObj1 - The first object to be compared. May be null.
      aObj2 - The second object to be compared. May be null.
      aPredicate - The predicate to be invoked, if both objects are non-null. May not be null.
      Returns:
      true if the contents are equal, false otherwise
      Since:
      9.4.5