Package net.sf.basedb.util
Class EqualsHelper
java.lang.Object
net.sf.basedb.util.EqualsHelper
Helper class for implementing equals and hash code calculations in
classes.
- Since:
- 2.15
- Author:
- nicklas
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Check if two objects are equal according to their equals implementation.static int
Get the hashcode for an object.static <T> int
hashCode
(T... objects) Hashcode calculation for an array of objects that doesn't depend on the position in the array.static boolean
invariantEquals
(List<?> l1, List<?> l2) Checks if two lists contains equal elements disregarding their positions in the array.static <T> boolean
invariantEquals
(T[] a1, T[] a2) Checks if two arrays contains equal elements disregarding their positions in the array.
-
Constructor Details
-
EqualsHelper
public EqualsHelper()
-
-
Method Details
-
equals
Check if two objects are equal according to their equals implementation. This method is safe to use with null values and returns true if both objects are null. Otherwise, it calls o1.equals(o2).- Parameters:
o1
- The first objecto2
- The second object- Returns:
- TRUE if the objects are equal
-
hashCode
Get the hashcode for an object. This method is safe to use with null and returns 0.- Parameters:
o
- The object to get the hash code for- Returns:
- The hash code
-
hashCode
Hashcode calculation for an array of objects that doesn't depend on the position in the array. Null objects are ignored.- Parameters:
objects
- An array of objects- Returns:
- The combined hash code for objects in the array
- See Also:
-
invariantEquals
public static <T> boolean invariantEquals(T[] a1, T[] a2) Checks if two arrays contains equal elements disregarding their positions in the array. Eg. [1, 2] is equal to [2, 1]- Parameters:
a1
- The first arraya2
- The second array- Returns:
- TRUE if both arrays contains the same elements
-
invariantEquals
Checks if two lists contains equal elements disregarding their positions in the array. Eg. [1, 2] is equal to [2, 1]- Parameters:
l1
- The first listl2
- The second list- Returns:
- TRUE if both list contains the same elements
- Since:
- 3.8
-