Package com.helger.commons.equals
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 easyequalsmethod generation- Author:
- Philip Helger
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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 booleanequals(Object aObj1, Object aObj2)Check 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>
booleanequalsMap(Map<K,V> aCont1, Map<?,?> aCont2)static <T> booleanequalsSet(Set<T> aCont1, Set<?> aCont2)static <T> booleanidentityEqual(T aObj1, T aObj2)The only place where objects are compared by identity.
-
-
-
Method Detail
-
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 benull.aObj2- Second object. May benull.- Returns:
trueif both objects arenullor reference the same object.
-
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
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 valueaObj2- Second value- Returns:
trueif they are equal,falseotherwise.- See Also:
EqualsImplementationRegistry.areEqual(Object, Object)
-
equalsIgnoreCase
public static boolean equalsIgnoreCase(@Nullable String sObj1, @Nullable String sObj2)
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
public static <K,V> boolean equalsMap(@Nonnull Map<K,V> aCont1, @Nonnull Map<?,?> 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, 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
public static boolean equalsAsList(@Nullable Object aObj1, @Nullable Object aObj2)
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
-
-