db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject svn commit: r392239 - in /db/jdo: branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/ branches/2.0/tck20/src/java/org/apache/jdo/tck/util/ trunk/tck20/src/java/org/apache/jdo/tck/pc/company/ trunk/tck20/src/java/org/apache/jdo/tck/util/
Date Fri, 07 Apr 2006 10:31:49 GMT
Author: mbo
Date: Fri Apr  7 03:31:46 2006
New Revision: 392239

URL: http://svn.apache.org/viewcvs?rev=392239&view=rev
Log:
JDO-364 - Completness tests fail with generated implementation classes for interfaces

Modified:
    db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Address.java
    db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Company.java
    db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Department.java
    db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java
    db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Insurance.java
    db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Person.java
    db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Project.java
    db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/util/EqualityHelper.java
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Address.java
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Company.java
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Department.java
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Insurance.java
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Person.java
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Project.java
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/util/EqualityHelper.java

Modified: db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Address.java
URL: http://svn.apache.org/viewcvs/db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Address.java?rev=392239&r1=392238&r2=392239&view=diff
==============================================================================
--- db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Address.java (original)
+++ db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Address.java Fri Apr
 7 03:31:46 2006
@@ -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 its two IAddress 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 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.

Modified: db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Company.java
URL: http://svn.apache.org/viewcvs/db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Company.java?rev=392239&r1=392238&r2=392239&view=diff
==============================================================================
--- db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Company.java (original)
+++ db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Company.java Fri Apr
 7 03:31:46 2006
@@ -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,8 +261,20 @@
      * object. 
      */
     public int compareTo(ICompany other) {
-        long otherId = other.getCompanyid();
-        return (companyid < otherId ? -1 : (companyid == otherId ? 0 : 1));
+        return compare(this, other);
+    }
+
+    /**
+     * Compares its two ICompany 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 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());
     }
     
     /** 

Modified: db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Department.java
URL: http://svn.apache.org/viewcvs/db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Department.java?rev=392239&r1=392238&r2=392239&view=diff
==============================================================================
--- db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Department.java (original)
+++ db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Department.java Fri Apr
 7 03:31:46 2006
@@ -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,8 +308,20 @@
      * Department object. 
      */
     public int compareTo(IDepartment other) {
-        long otherId = other.getDeptid();
-        return (deptid < otherId ? -1 : (deptid == otherId ? 0 : 1));
+        return compare(this, other);
+    }
+
+    /**
+     * Compares its two IDepartment 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 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());
     }
     
     /** 

Modified: db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java
URL: http://svn.apache.org/viewcvs/db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java?rev=392239&r1=392238&r2=392239&view=diff
==============================================================================
--- db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java
(original)
+++ db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java
Fri Apr  7 03:31:46 2006
@@ -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");

Modified: db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Insurance.java
URL: http://svn.apache.org/viewcvs/db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Insurance.java?rev=392239&r1=392238&r2=392239&view=diff
==============================================================================
--- db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Insurance.java (original)
+++ db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Insurance.java Fri Apr
 7 03:31:46 2006
@@ -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,10 +181,21 @@
      * Insurance object. 
      */
     public int compareTo(IInsurance other) {
-        long otherId = other.getInsid();
-        return (insid < otherId ? -1 : (insid == otherId ? 0 : 1));
+        return compare(this, other);
+    }
+
+    /**
+     * Compares its two IInsurance 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 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.

Modified: db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Person.java
URL: http://svn.apache.org/viewcvs/db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Person.java?rev=392239&r1=392238&r2=392239&view=diff
==============================================================================
--- db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Person.java (original)
+++ db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Person.java Fri Apr 
7 03:31:46 2006
@@ -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,10 +321,21 @@
      * object. 
      */
     public int compareTo(IPerson other) {
-        long otherId = other.getPersonid();
-        return (personid < otherId ? -1 : (personid == otherId ? 0 : 1));
+        return compare(this, other);
+    }
+
+    /**
+     * Compares its two IPerson 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 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.

Modified: db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Project.java
URL: http://svn.apache.org/viewcvs/db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Project.java?rev=392239&r1=392238&r2=392239&view=diff
==============================================================================
--- db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Project.java (original)
+++ db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/pc/company/Project.java Fri Apr
 7 03:31:46 2006
@@ -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,8 +261,20 @@
      * object. 
      */
     public int compareTo(IProject other) {
-        long otherId = other.getProjid();
-        return (projid < otherId ? -1 : (projid == otherId ? 0 : 1));
+        return compare(this, other);
+    }
+
+    /**
+     * Compares its two IProject 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 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());
     }
 
     /** 

Modified: db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/util/EqualityHelper.java
URL: http://svn.apache.org/viewcvs/db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/util/EqualityHelper.java?rev=392239&r1=392238&r2=392239&view=diff
==============================================================================
--- db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/util/EqualityHelper.java (original)
+++ db/jdo/branches/2.0/tck20/src/java/org/apache/jdo/tck/util/EqualityHelper.java Fri Apr
 7 03:31:46 2006
@@ -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));
+    }
 }

Modified: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Address.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Address.java?rev=392239&r1=392238&r2=392239&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Address.java (original)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Address.java Fri Apr  7 03:31:46
2006
@@ -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 its two IAddress 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 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.

Modified: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Company.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Company.java?rev=392239&r1=392238&r2=392239&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Company.java (original)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Company.java Fri Apr  7 03:31:46
2006
@@ -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,8 +261,20 @@
      * object. 
      */
     public int compareTo(ICompany other) {
-        long otherId = other.getCompanyid();
-        return (companyid < otherId ? -1 : (companyid == otherId ? 0 : 1));
+        return compare(this, other);
+    }
+
+    /**
+     * Compares its two ICompany 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 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());
     }
     
     /** 

Modified: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Department.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Department.java?rev=392239&r1=392238&r2=392239&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Department.java (original)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Department.java Fri Apr  7 03:31:46
2006
@@ -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,8 +308,20 @@
      * Department object. 
      */
     public int compareTo(IDepartment other) {
-        long otherId = other.getDeptid();
-        return (deptid < otherId ? -1 : (deptid == otherId ? 0 : 1));
+        return compare(this, other);
+    }
+
+    /**
+     * Compares its two IDepartment 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 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());
     }
     
     /** 

Modified: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java?rev=392239&r1=392238&r2=392239&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java (original)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java Fri Apr
 7 03:31:46 2006
@@ -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");

Modified: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Insurance.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Insurance.java?rev=392239&r1=392238&r2=392239&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Insurance.java (original)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Insurance.java Fri Apr  7 03:31:46
2006
@@ -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,10 +181,21 @@
      * Insurance object. 
      */
     public int compareTo(IInsurance other) {
-        long otherId = other.getInsid();
-        return (insid < otherId ? -1 : (insid == otherId ? 0 : 1));
+        return compare(this, other);
+    }
+
+    /**
+     * Compares its two IInsurance 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 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.

Modified: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Person.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Person.java?rev=392239&r1=392238&r2=392239&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Person.java (original)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Person.java Fri Apr  7 03:31:46
2006
@@ -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,10 +321,21 @@
      * object. 
      */
     public int compareTo(IPerson other) {
-        long otherId = other.getPersonid();
-        return (personid < otherId ? -1 : (personid == otherId ? 0 : 1));
+        return compare(this, other);
+    }
+
+    /**
+     * Compares its two IPerson 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 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.

Modified: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Project.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Project.java?rev=392239&r1=392238&r2=392239&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Project.java (original)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/company/Project.java Fri Apr  7 03:31:46
2006
@@ -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,8 +261,20 @@
      * object. 
      */
     public int compareTo(IProject other) {
-        long otherId = other.getProjid();
-        return (projid < otherId ? -1 : (projid == otherId ? 0 : 1));
+        return compare(this, other);
+    }
+
+    /**
+     * Compares its two IProject 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 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());
     }
 
     /** 

Modified: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/util/EqualityHelper.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/util/EqualityHelper.java?rev=392239&r1=392238&r2=392239&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/util/EqualityHelper.java (original)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/util/EqualityHelper.java Fri Apr  7 03:31:46
2006
@@ -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));
+    }
 }



Mime
View raw message