org.kuali.rice.core.api.util
Class EqualsAndHashCodeUtils

java.lang.Object
  extended by org.kuali.rice.core.api.util.EqualsAndHashCodeUtils

public final class EqualsAndHashCodeUtils
extends Object

Class of static utility methods used to aid in the generation of hashcode values and equals comparisons of objects for corner cases that EqualsBuilder and HashCodeBuilder of commons-lang cannot cover.


Method Summary
static
<T> boolean
equalsUsingCompareToOnFields(T o1, T o2, String... fieldNames)
          This method provides an equals comparison of two objects by evaluating the results of compareTo across specified internal fields of the class of the two objects being compared.
static int hashCodeForCalendars(Calendar... calendars)
          Generates an int hashcode from all calendars passed in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

equalsUsingCompareToOnFields

public static <T> boolean equalsUsingCompareToOnFields(T o1,
                                                       T o2,
                                                       String... fieldNames)
This method provides an equals comparison of two objects by evaluating the results of compareTo across specified internal fields of the class of the two objects being compared.

This method should be used where evaluating equality on fields of two instances of type T using .equals() yields false, but for the purposes of determining equality of the two instances of type T, should be true. An example is where a class has internal fields of type Calendar that need equality determined using only its time value and not other internal fields of Calendar.

Type Parameters:
T - Type of both o1 and o2 parameters. Guarantees both o1 and o2 are the same reference type.
Parameters:
o1 - The first object used in an equality operation using compareTo
o2 - The second object used in an equality operation using compareTo
fieldNames - All field names within type T that should be determined equal or not using compareTo
Returns:
true if (o1.field.compareTo(o2.field) == 0) is true for all passed in fieldNames. Otherwise false is returned. False is also returned if any fields specified in fieldNames are not of type Comparable or if one (but not both) of the passed in objects are null references.

hashCodeForCalendars

public static int hashCodeForCalendars(Calendar... calendars)
Generates an int hashcode from all calendars passed in. This is a convenience method for hashcode methods to call if they have to generate hashcodes from fields of type Calendar when those Calendar fields have equality evaluated using compareTo and not equals within the equals method of the container class.

Parameters:
calendars -
Returns:
int hashcode value generated by using the long value returned from each Calendar.getTimeInMillis()


Copyright © 2005-2013 The Kuali Foundation. All Rights Reserved.