Package com.helger.base.equals
Class EqualsHelper
java.lang.Object
com.helger.base.equals.EqualsHelper
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 -
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 <T> booleanequalsCustom(@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 booleanequalsIgnoreCase(@Nullable String sObj1, @Nullable String sObj2) Check if the passed strings are equals case insensitive handlingnullappropriately.static <T> booleanidentityDifferent(@Nullable T aObj1, @Nullable T aObj2) The only place where objects are compared by identity.static <T> booleanidentityEqual(@Nullable T aObj1, @Nullable T aObj2) The only place where objects are compared by identity.
-
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 benull.aObj2- Second object. May benull.- Returns:
trueif both objects arenullor 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 benull.aObj2- Second object. May benull.- Returns:
trueif one object isnullor 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 valueaObj2- Second value- Returns:
trueif they are equal,falseotherwise.
-
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 valueaObj2- Second value- Returns:
trueif they are equal,falseotherwise.
-
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 valueaObj2- Second value- Returns:
trueif they are equal,falseotherwise.
-
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 doubleaObj2- Second double- Returns:
trueif they are equal,falseotherwise.
-
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 floataObj2- Second float- Returns:
trueif they are equal,falseotherwise.
-
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 valueaObj2- Second value- Returns:
trueif they are equal,falseotherwise.
-
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 valueaObj2- Second value- Returns:
trueif they are equal,falseotherwise.
-
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 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.
-
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.
-
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
-