2.17.2: 2011-06-17

net.sf.basedb.util
Class EqualsHelper

java.lang.Object
  extended by net.sf.basedb.util.EqualsHelper

public class EqualsHelper
extends Object

Helper class for implementing equals and hash code calculations in classes.

Since:
2.15
Author:
nicklas

Constructor Summary
EqualsHelper()
           
 
Method Summary
static boolean equals(Object o1, Object o2)
          Check if two objects are equal according to their equals implementation.
static int hashCode(Object o)
          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
<T> boolean
invariantEquals(T[] a1, T[] a2)
          Checks if two arrays contains equal elements disregarding their positions in the array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EqualsHelper

public EqualsHelper()
Method Detail

equals

public static boolean equals(Object o1,
                             Object o2)
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 object
o2 - The second object
Returns:
TRUE if the objects are equal

hashCode

public static int hashCode(Object o)
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

public static <T> int hashCode(T... objects)
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(Object[], Object[])

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 array
a2 - The second array
Returns:
TRUE if both arrays contains the same elements

2.17.2: 2011-06-17