db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@apache.org
Subject [db-jdo] 13/43: JDO-364 - Completness tests fail with generated implementation classes for interfaces
Date Fri, 07 May 2021 23:11:55 GMT
This is an automated email from the ASF dual-hosted git repository.

clr pushed a commit to branch origin/2.0.1
in repository https://gitbox.apache.org/repos/asf/db-jdo.git

commit 45a6ae134a2b7dc1697cfdf6cf5982f15064148f
Author: Michael Bouschen <mbo@apache.org>
AuthorDate: Fri Apr 7 10:31:46 2006 +0000

    JDO-364 - Completness tests fail with generated implementation classes for interfaces
---
 .../org/apache/jdo/tck/pc/company/Address.java     | 30 +++++++++----
 .../org/apache/jdo/tck/pc/company/Company.java     | 30 +++++++++----
 .../org/apache/jdo/tck/pc/company/Department.java  | 20 +++++++--
 .../jdo/tck/pc/company/FullTimeEmployee.java       |  2 +-
 .../org/apache/jdo/tck/pc/company/Insurance.java   | 31 ++++++++-----
 .../java/org/apache/jdo/tck/pc/company/Person.java | 33 +++++++++-----
 .../org/apache/jdo/tck/pc/company/Project.java     | 30 +++++++++----
 .../org/apache/jdo/tck/util/EqualityHelper.java    | 52 ++++++++++++++++++----
 8 files changed, 166 insertions(+), 62 deletions(-)

diff --git a/tck20/src/java/org/apache/jdo/tck/pc/company/Address.java b/tck20/src/java/org/apache/jdo/tck/pc/company/Address.java
index 49e4985..08f6406 100644
--- a/tck20/src/java/org/apache/jdo/tck/pc/company/Address.java
+++ b/tck20/src/java/org/apache/jdo/tck/pc/company/Address.java
@@ -206,13 +206,6 @@ public class Address
     }
     
     /** 
-     * 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 @@ public class Address
     }
 
     /** 
+     * 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 @@ public class Address
      * 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.
diff --git a/tck20/src/java/org/apache/jdo/tck/pc/company/Company.java b/tck20/src/java/org/apache/jdo/tck/pc/company/Company.java
index 44af95c..c240187 100644
--- a/tck20/src/java/org/apache/jdo/tck/pc/company/Company.java
+++ b/tck20/src/java/org/apache/jdo/tck/pc/company/Company.java
@@ -230,13 +230,6 @@ public class Company
     }
     
     /** 
-     * 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 @@ public class Company
     }
 
     /** 
+     * 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 @@ public class Company
      * 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());
     }
     
     /** 
diff --git a/tck20/src/java/org/apache/jdo/tck/pc/company/Department.java b/tck20/src/java/org/apache/jdo/tck/pc/company/Department.java
index 6a98477..1c9e9bc 100644
--- a/tck20/src/java/org/apache/jdo/tck/pc/company/Department.java
+++ b/tck20/src/java/org/apache/jdo/tck/pc/company/Department.java
@@ -246,7 +246,7 @@ public class Department
      */
     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 @@ public class Department
      * 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 @@ public class Department
      * 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());
     }
     
     /** 
diff --git a/tck20/src/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java b/tck20/src/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java
index d3d1e41..2af011e 100644
--- a/tck20/src/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java
+++ b/tck20/src/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java
@@ -117,7 +117,7 @@ public class FullTimeEmployee extends Employee implements IFullTimeEmployee
{
      */
     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");
diff --git a/tck20/src/java/org/apache/jdo/tck/pc/company/Insurance.java b/tck20/src/java/org/apache/jdo/tck/pc/company/Insurance.java
index 2791165..a095f3a 100644
--- a/tck20/src/java/org/apache/jdo/tck/pc/company/Insurance.java
+++ b/tck20/src/java/org/apache/jdo/tck/pc/company/Insurance.java
@@ -150,13 +150,6 @@ public abstract class Insurance
     }
     
     /** 
-     * 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 @@ public abstract class Insurance
     }
 
     /** 
+     * 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 @@ public abstract class Insurance
      * 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.
diff --git a/tck20/src/java/org/apache/jdo/tck/pc/company/Person.java b/tck20/src/java/org/apache/jdo/tck/pc/company/Person.java
index 830cd5a..e5e2020 100644
--- a/tck20/src/java/org/apache/jdo/tck/pc/company/Person.java
+++ b/tck20/src/java/org/apache/jdo/tck/pc/company/Person.java
@@ -289,14 +289,7 @@ public class Person
             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 @@ public class Person
     }
 
     /** 
+     * 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 @@ public class Person
      * 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.
diff --git a/tck20/src/java/org/apache/jdo/tck/pc/company/Project.java b/tck20/src/java/org/apache/jdo/tck/pc/company/Project.java
index 8aa66b5..39158a0 100644
--- a/tck20/src/java/org/apache/jdo/tck/pc/company/Project.java
+++ b/tck20/src/java/org/apache/jdo/tck/pc/company/Project.java
@@ -230,13 +230,6 @@ public class Project
     }
     
     /** 
-     * 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 @@ public class Project
     }
 
     /** 
+     * 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 @@ public class Project
      * 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());
     }
 
     /** 
diff --git a/tck20/src/java/org/apache/jdo/tck/util/EqualityHelper.java b/tck20/src/java/org/apache/jdo/tck/util/EqualityHelper.java
index 3d19a82..2c63e5b 100644
--- a/tck20/src/java/org/apache/jdo/tck/util/EqualityHelper.java
+++ b/tck20/src/java/org/apache/jdo/tck/util/EqualityHelper.java
@@ -177,8 +177,6 @@ public class EqualityHelper {
             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 @@ public class EqualityHelper {
         // 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 @@ public class EqualityHelper {
         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 @@ public class EqualityHelper {
         // 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 @@ public class EqualityHelper {
             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 @@ public class EqualityHelper {
                     ", 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 @@ public class EqualityHelper {
         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