Class EqualsHelper

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

@Immutable public final class EqualsHelper extends Object
A small helper class that provides helper methods for easy equals method generation
Author:
Philip Helger
  • 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

      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

      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

      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

      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

      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

      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

      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

      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

      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.
      See Also:
    • 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.
    • equalsCollectionOnly

      public static <T> boolean equalsCollectionOnly(@Nonnull Collection<T> aCont1, @Nonnull Collection<?> aCont2)
    • equalsMap

      public static <K, V> boolean equalsMap(@Nonnull Map<K,V> aCont1, @Nonnull Map<?,?> aCont2)
    • equalsSet

      public static <T> boolean equalsSet(@Nonnull Set<T> aCont1, @Nonnull Set<?> aCont2)
    • equalsIterator

      public static <T> boolean equalsIterator(@Nonnull Iterator<T> aIter1, Iterator<?> aIter2)
    • equalsEumeration

      public static <T> boolean equalsEumeration(@Nonnull Enumeration<T> aEnum1, Enumeration<?> aEnum2)
    • equalsCollection

      public static boolean equalsCollection(@Nullable Object aObj1, @Nullable Object aObj2)
      Check if the content of the passed containers is equal. If the container itself contains nested containers, this method is invoked recursively. For non-container elements, the EqualsImplementationRegistry.areEqual(Object, Object) method is invoked to test for equality!
      Parameters:
      aObj1 - The first container. May be null.
      aObj2 - The second container. May be null.
      Returns:
      true if both objects are the same, or if they have the same meta type and have the same content.
      Throws:
      IllegalArgumentException - if one of the arguments is not a container!
    • equalsAsList

      public static boolean equalsAsList(@Nullable Object aObj1, @Nullable Object aObj2)
      This is a sanity method that first calls CollectionHelper.getAsList(Object) on both objects an than calls equalsCollectionOnly(Collection, Collection) on the collections. This means that calling this method with the String array ["a", "b"] and the List<String> ("a", "b") will result in a return value of true.
      Parameters:
      aObj1 - The first object to be compared. May be null.
      aObj2 - The second object to be compared. May be null.
      Returns:
      true if the contents are equal, 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