Package com.helger.commons.equals
Class EqualsHelper
java.lang.Object
com.helger.commons.equals.EqualsHelper
A small helper class that provides helper methods for easy
equals method generation- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanequals(boolean aObj1, boolean aObj2) Check if two values are equal.static booleanequals(byte aObj1, byte aObj2) Check if two values are equal.static booleanequals(char aObj1, char aObj2) Check if two values are equal.static booleanequals(double aObj1, double aObj2) Check if two double values are equal.static booleanequals(float aObj1, float aObj2) Check if two float values are equal.static booleanequals(int aObj1, int aObj2) Check if two values are equal.static booleanequals(long aObj1, long aObj2) Check if two values are equal.static booleanequals(short aObj1, short aObj2) Check if two values are equal.static booleanCheck if two values are equal.static booleanequalsAsList(Object aObj1, Object aObj2) This is a sanity method that first callsCollectionHelper.getAsList(Object)on both objects an than callsequalsCollectionOnly(Collection, Collection)on the collections.static booleanequalsCollection(Object aObj1, Object aObj2) Check if the content of the passed containers is equal.static <T> booleanequalsCollectionOnly(Collection<T> aCont1, Collection<?> aCont2) static <T> booleanequalsCustom(T aObj1, T aObj2, BiPredicate<T, T> aPredicate) Perform an equals check with a custom predicate that is only invoked, if both objects are non-null.static <T> booleanequalsEumeration(Enumeration<T> aEnum1, Enumeration<?> aEnum2) static booleanequalsIgnoreCase(String sObj1, String sObj2) Check if the passed strings are equals case insensitive handlingnullappropriately.static <T> booleanequalsIterator(Iterator<T> aIter1, Iterator<?> aIter2) static <K,V> boolean static <T> booleanstatic <T> booleanidentityDifferent(T aObj1, T aObj2) The only place where objects are compared by identity.static <T> booleanidentityEqual(T aObj1, T aObj2) The only place where objects are compared by identity.
-
Method Details
-
identityEqual
The only place where objects are compared by identity.- Type Parameters:
T- Type to check.- Parameters:
aObj1- First object. May benull.aObj2- Second object. May benull.- Returns:
trueif both objects arenullor reference the same object.
-
identityDifferent
The only place where objects are compared by identity.- Type Parameters:
T- Type to check.- Parameters:
aObj1- First object. May benull.aObj2- Second object. May benull.- Returns:
trueif one object isnullor 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 valueaObj2- Second value- Returns:
trueif they are equal,falseotherwise.
-
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 valueaObj2- Second value- Returns:
trueif they are equal,falseotherwise.
-
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 valueaObj2- Second value- Returns:
trueif they are equal,falseotherwise.
-
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 doubleaObj2- Second double- Returns:
trueif they are equal,falseotherwise.
-
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 floataObj2- Second float- Returns:
trueif they are equal,falseotherwise.
-
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 valueaObj2- Second value- Returns:
trueif they are equal,falseotherwise.
-
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 valueaObj2- Second value- Returns:
trueif they are equal,falseotherwise.
-
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 valueaObj2- Second value- Returns:
trueif they are equal,falseotherwise.
-
equals
Check if two values are equal. This method only exists, so that no type differentiation is needed.- Parameters:
aObj1- First valueaObj2- Second value- Returns:
trueif they are equal,falseotherwise.- See Also:
-
equalsIgnoreCase
Check if the passed strings are equals case insensitive handlingnullappropriately.- Parameters:
sObj1- First object to comparesObj2- Second object to compare- Returns:
trueif they are equal case insensitive,falseotherwise.
-
equalsCollectionOnly
public static <T> boolean equalsCollectionOnly(@Nonnull Collection<T> aCont1, @Nonnull Collection<?> aCont2) -
equalsMap
-
equalsSet
-
equalsIterator
-
equalsEumeration
-
equalsCollection
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, theEqualsImplementationRegistry.areEqual(Object, Object)method is invoked to test for equality!- Parameters:
aObj1- The first container. May benull.aObj2- The second container. May benull.- Returns:
trueif 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
This is a sanity method that first callsCollectionHelper.getAsList(Object)on both objects an than callsequalsCollectionOnly(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 benull.aObj2- The second object to be compared. May benull.- Returns:
trueif the contents are equal,falseotherwise
-
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 benull.aObj2- The second object to be compared. May benull.aPredicate- The predicate to be invoked, if both objects are non-null. May not benull.- Returns:
trueif the contents are equal,falseotherwise- Since:
- 9.4.5
-