Index: src/java/org/apache/jdo/tck/pc/company/Department.java =================================================================== --- src/java/org/apache/jdo/tck/pc/company/Department.java (Revision 391652) +++ src/java/org/apache/jdo/tck/pc/company/Department.java (Arbeitskopie) @@ -246,7 +246,7 @@ */ public boolean deepCompareFields(Object other, EqualityHelper helper) { - Department otherDept = (Department)other; + IDepartment otherDept = (IDepartment)other; String where = "Department<" + deptid + ">"; return helper.equals(deptid, otherDept.getDeptid(), where + ".deptid") & @@ -294,7 +294,7 @@ * Compare two instances. This is a method in Comparator. */ public int compare(Object o1, Object o2) { - return ((Department)o1).compareTo(o2); + return compare((IDepartment)o1, (IDepartment)o2); } /** @@ -308,9 +308,21 @@ * Department object. */ public int compareTo(IDepartment other) { - long otherId = other.getDeptid(); - return (deptid < otherId ? -1 : (deptid == otherId ? 0 : 1)); + return compare(this, other); } + + /** + * Compares two instance of IDepartment for order. Returns a negative + * integer, zero, or a positive integer as this object is less than, equal + * to, or greater than the specified object. + * @param o1 The first IDepartment object to be compared. + * @param o2 The second IDepartment object to be compared. + * @return a negative integer, zero, or a positive integer as the first + * object is less than, equal to, or greater than the second object. + */ + public static int compare(IDepartment o1, IDepartment o2) { + return EqualityHelper.compare(o1.getDeptid(), o2.getDeptid()); + } /** * Indicates whether some other object is "equal to" this one. Index: src/java/org/apache/jdo/tck/pc/company/Company.java =================================================================== --- src/java/org/apache/jdo/tck/pc/company/Company.java (Revision 391652) +++ src/java/org/apache/jdo/tck/pc/company/Company.java (Arbeitskopie) @@ -230,13 +230,6 @@ } /** - * Compare two instances. This is a method in Comparator. - */ - public int compare(Object o1, Object o2) { - return ((Company)o1).compareTo(o2); - } - - /** * Compares this object with the specified object for order. Returns a * negative integer, zero, or a positive integer as this object is less * than, equal to, or greater than the specified object. @@ -251,6 +244,13 @@ } /** + * Compare two instances. This is a method in Comparator. + */ + public int compare(Object o1, Object o2) { + return compare((ICompany)o1, (ICompany)o2); + } + + /** * Compares this object with the specified Company object for * order. Returns a negative integer, zero, or a positive integer as * this object is less than, equal to, or greater than the specified @@ -261,9 +261,21 @@ * object. */ public int compareTo(ICompany other) { - long otherId = other.getCompanyid(); - return (companyid < otherId ? -1 : (companyid == otherId ? 0 : 1)); + return compare(this, other); } + + /** + * Compares two instance of ICompany for order. Returns a negative + * integer, zero, or a positive integer as this object is less than, equal + * to, or greater than the specified object. + * @param o1 The first ICompany object to be compared. + * @param o2 The second ICompany object to be compared. + * @return a negative integer, zero, or a positive integer as the first + * object is less than, equal to, or greater than the second object. + */ + public static int compare(ICompany o1, ICompany o2) { + return EqualityHelper.compare(o1.getCompanyid(), o2.getCompanyid()); + } /** * Indicates whether some other object is "equal to" this one. Index: src/java/org/apache/jdo/tck/pc/company/Person.java =================================================================== --- src/java/org/apache/jdo/tck/pc/company/Person.java (Revision 391652) +++ src/java/org/apache/jdo/tck/pc/company/Person.java (Arbeitskopie) @@ -289,14 +289,7 @@ helper.deepEquals(phoneNumbers, otherPerson.getPhoneNumbers(), where + ".phoneNumbers"); } - /** - * Compare two instances. This is a method in Comparator. - */ - public int compare(Object o1, Object o2) { - return ((Person)o1).compareTo(o2); - } - - /** + /** * Compares this object with the specified object for order. Returns a * negative integer, zero, or a positive integer as this object is less * than, equal to, or greater than the specified object. @@ -311,6 +304,13 @@ } /** + * Compare two instances. This is a method in Comparator. + */ + public int compare(Object o1, Object o2) { + return compare((IPerson)o1, (IPerson)o2); + } + + /** * Compares this object with the specified Person object for * order. Returns a negative integer, zero, or a positive integer as * this object is less than, equal to, or greater than the specified @@ -321,11 +321,22 @@ * object. */ public int compareTo(IPerson other) { - long otherId = other.getPersonid(); - return (personid < otherId ? -1 : (personid == otherId ? 0 : 1)); + return compare(this, other); } + + /** + * Compares two instance of IPerson for order. Returns a negative + * integer, zero, or a positive integer as this object is less than, equal + * to, or greater than the specified object. + * @param o1 The first IPerson object to be compared. + * @param o2 The second IPerson object to be compared. + * @return a negative integer, zero, or a positive integer as the first + * object is less than, equal to, or greater than the second object. + */ + public static int compare(IPerson o1, IPerson o2) { + return EqualityHelper.compare(o1.getPersonid(), o2.getPersonid()); + } - /** * Indicates whether some other object is "equal to" this one. * @param obj the object with which to compare. Index: src/java/org/apache/jdo/tck/pc/company/Project.java =================================================================== --- src/java/org/apache/jdo/tck/pc/company/Project.java (Revision 391652) +++ src/java/org/apache/jdo/tck/pc/company/Project.java (Arbeitskopie) @@ -230,13 +230,6 @@ } /** - * Compare two instances. This is a method in Comparator. - */ - public int compare(Object o1, Object o2) { - return ((Project)o1).compareTo(o2); - } - - /** * Compares this object with the specified object for order. Returns a * negative integer, zero, or a positive integer as this object is less * than, equal to, or greater than the specified object. @@ -251,6 +244,13 @@ } /** + * Compare two instances. This is a method in Comparator. + */ + public int compare(Object o1, Object o2) { + return compare((IProject)o1, (IProject)o2); + } + + /** * Compares this object with the specified Project object for * order. Returns a negative integer, zero, or a positive integer as * this object is less than, equal to, or greater than the specified @@ -261,10 +261,22 @@ * object. */ public int compareTo(IProject other) { - long otherId = other.getProjid(); - return (projid < otherId ? -1 : (projid == otherId ? 0 : 1)); + return compare(this, other); } + /** + * Compares two instance of IProject for order. Returns a negative + * integer, zero, or a positive integer as this object is less than, equal + * to, or greater than the specified object. + * @param o1 The first IProject object to be compared. + * @param o2 The second IProject object to be compared. + * @return a negative integer, zero, or a positive integer as the first + * object is less than, equal to, or greater than the second object. + */ + public static int compare(IProject o1, IProject o2) { + return EqualityHelper.compare(o1.getProjid(), o2.getProjid()); + } + /** * Indicates whether some other object is "equal to" this one. * @param obj the object with which to compare. Index: src/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java =================================================================== --- src/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java (Revision 391652) +++ src/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java (Arbeitskopie) @@ -117,7 +117,7 @@ */ public boolean deepCompareFields(Object other, EqualityHelper helper) { - FullTimeEmployee otherEmp = (FullTimeEmployee)other; + IFullTimeEmployee otherEmp = (IFullTimeEmployee)other; String where = "FullTimeEmployee<" + getPersonid() + ">"; return super.deepCompareFields(otherEmp, helper) & helper.closeEnough(salary, otherEmp.getSalary(), where + ".salary"); Index: src/java/org/apache/jdo/tck/pc/company/Address.java =================================================================== --- src/java/org/apache/jdo/tck/pc/company/Address.java (Revision 391652) +++ src/java/org/apache/jdo/tck/pc/company/Address.java (Arbeitskopie) @@ -206,13 +206,6 @@ } /** - * Compare two instances. This is a method in Comparator. - */ - public int compare(Object o1, Object o2) { - return ((Address)o1).compareTo(o2); - } - - /** * Compares this object with the specified object for order. Returns a * negative integer, zero, or a positive integer as this object is less * than, equal to, or greater than the specified object. @@ -227,6 +220,13 @@ } /** + * Compare two instances. This is a method in Comparator. + */ + public int compare(Object o1, Object o2) { + return compare((IAddress)o1, (IAddress)o2); + } + + /** * Compares this object with the specified Address object for * order. Returns a negative integer, zero, or a positive integer as * this object is less than, equal to, or greater than the specified @@ -237,10 +237,22 @@ * object. */ public int compareTo(IAddress other) { - long otherId = other.getAddrid(); - return (addrid < otherId ? -1 : (addrid == otherId ? 0 : 1)); + return compare(this, other); } + /** + * Compares two instance of IAddress for order. Returns a negative + * integer, zero, or a positive integer as this object is less than, equal + * to, or greater than the specified object. + * @param o1 The first IAddress object to be compared. + * @param o2 The second IAddress object to be compared. + * @return a negative integer, zero, or a positive integer as the first + * object is less than, equal to, or greater than the second object. + */ + public static int compare(IAddress o1, IAddress o2) { + return EqualityHelper.compare(o1.getAddrid(), o2.getAddrid()); + } + /** * Indicates whether some other object is "equal to" this one. * @param obj the object with which to compare. Index: src/java/org/apache/jdo/tck/pc/company/Insurance.java =================================================================== --- src/java/org/apache/jdo/tck/pc/company/Insurance.java (Revision 391652) +++ src/java/org/apache/jdo/tck/pc/company/Insurance.java (Arbeitskopie) @@ -150,13 +150,6 @@ } /** - * Compare two instances. This is a method in Comparator. - */ - public int compare(Object o1, Object o2) { - return ((Insurance)o1).compareTo(o2); - } - - /** * Compares this object with the specified object for order. Returns a * negative integer, zero, or a positive integer as this object is less * than, equal to, or greater than the specified object. @@ -171,6 +164,13 @@ } /** + * Compare two instances. This is a method in Comparator. + */ + public int compare(Object o1, Object o2) { + return compare((IInsurance)o1, (IInsurance)o2); + } + + /** * Compares this object with the specified Insurance object for * order. Returns a negative integer, zero, or a positive integer as * this object is less than, equal to, or greater than the specified @@ -181,11 +181,22 @@ * Insurance object. */ public int compareTo(IInsurance other) { - long otherId = other.getInsid(); - return (insid < otherId ? -1 : (insid == otherId ? 0 : 1)); + return compare(this, other); } + + /** + * Compares two instance of IInsurance for order. Returns a negative + * integer, zero, or a positive integer as this object is less than, equal + * to, or greater than the specified object. + * @param o1 The first IInsurance object to be compared. + * @param o2 The second IInsurance object to be compared. + * @return a negative integer, zero, or a positive integer as the first + * object is less than, equal to, or greater than the second object. + */ + public static int compare(IInsurance o1, IInsurance o2) { + return EqualityHelper.compare(o1.getInsid(), o2.getInsid()); + } - /** * Indicates whether some other object is "equal to" this one. * @param obj the object with which to compare. Index: src/java/org/apache/jdo/tck/util/EqualityHelper.java =================================================================== --- src/java/org/apache/jdo/tck/util/EqualityHelper.java (Revision 391652) +++ src/java/org/apache/jdo/tck/util/EqualityHelper.java (Arbeitskopie) @@ -177,8 +177,6 @@ return true; if ((me == null) || (other == null)) return false; - if (!me.getClass().isAssignableFrom(other.getClass())) - return false; if (isProcessed(me)) return true; markProcessed(me); @@ -229,11 +227,19 @@ // Return false, if the size differs if (mine.size() != other.size()) return false; + + if (mine.size() == 0) + return true; + // Now check the elements List myList = new ArrayList(mine); Collections.sort(myList); List otherList = new ArrayList(other); - Collections.sort(otherList); + /* Any collection of elements to be compared must implement Comparator + * to avoid the other side having to implement Comparable. */ + Comparator comparator = + (Comparator)myList.get(0); + Collections.sort(otherList, comparator); for (int i = 0; i < myList.size(); i++) { if (!deepEquals(myList.get(i), otherList.get(i))) return false; @@ -269,6 +275,8 @@ List myList = new ArrayList(mine.entrySet()); Collections.sort(myList, entryKeyComparator); List otherList = new ArrayList(other.entrySet()); + /* Any collection of elements to be compared must implement Comparator + * to avoid the other side having to implement Comparable. */ Comparator comparator = (Comparator)((Map.Entry)myList.get(0)).getKey(); Collections.sort(otherList, @@ -306,11 +314,19 @@ // Return false, if the size differs if (mine.size() != other.size()) return false; + + if (mine.size() == 0) + return true; + // Now check the elements List myList = new ArrayList(mine); Collections.sort(myList); List otherList = new ArrayList(other); - Collections.sort(otherList); + /* Any collection of elements to be compared must implement Comparator + * to avoid the other side having to implement Comparable. */ + Comparator comparator = + (Comparator)myList.get(0); + Collections.sort(otherList, comparator); return myList.equals(otherList); } @@ -375,10 +391,6 @@ logUnequal(me, other, where + msgOtherNull); return false; } - if (!me.getClass().isAssignableFrom(other.getClass())) { - logUnequal(me, other, where + msgIncompatibleTypes); - return false; - } if (isProcessed(me)) return true; markProcessed(me); @@ -599,11 +611,19 @@ ", counted size= " + count); return false; } + + if (me.size() == 0) + return true; + // Now check the elements List myList = new ArrayList(me); Collections.sort(myList); List otherList = new ArrayList(other); - Collections.sort(otherList); + /* Any collection of elements to be compared must implement Comparator + * to avoid the other side having to implement Comparable. */ + Comparator comparator = + (Comparator)myList.get(0); + Collections.sort(otherList, comparator); boolean result = myList.equals(otherList); if (!result) logUnequal(me, other, @@ -847,4 +867,18 @@ return result; } + // Methods to support compare methods as specified in Comparator + + /** + * Compares its two arguments for order. Returns a negative integer, zero, + * or a positive integer as the first argument is less than, equal to, or + * greater than the second. + * @param l1 the first long to be compared + * @param l2 the second long to be compared + * @return a negative integer, zero, or a positive integer as the first + * argument is less than, equal to, or greater than the second. + */ + public static int compare (long l1, long l2) { + return (l1 < l2 ? -1 : (l1 == l2 ? 0 : 1)); + } }