db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@apache.org
Subject svn commit: r672600 - in /db/jdo/trunk: api2-legacy/src/java/javax/jdo/identity/ api2-legacy/test/java/javax/jdo/identity/ api2/src/java/javax/jdo/identity/ api2/test/java/javax/jdo/identity/
Date Sun, 29 Jun 2008 02:47:55 GMT
Author: clr
Date: Sat Jun 28 19:47:54 2008
New Revision: 672600

URL: http://svn.apache.org/viewvc?rev=672600&view=rev
Log:
JDO-598 Add comparison of class name to compareTo

Modified:
    db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/ByteIdentity.java
    db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/CharIdentity.java
    db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/IntIdentity.java
    db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/LongIdentity.java
    db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/ShortIdentity.java
    db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/SingleFieldIdentity.java
    db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/StringIdentity.java
    db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/ByteIdentityTest.java
    db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/CharIdentityTest.java
    db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/IntIdentityTest.java
    db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/LongIdentityTest.java
    db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/ShortIdentityTest.java
    db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/StringIdentityTest.java
    db/jdo/trunk/api2/src/java/javax/jdo/identity/ByteIdentity.java
    db/jdo/trunk/api2/src/java/javax/jdo/identity/CharIdentity.java
    db/jdo/trunk/api2/src/java/javax/jdo/identity/IntIdentity.java
    db/jdo/trunk/api2/src/java/javax/jdo/identity/LongIdentity.java
    db/jdo/trunk/api2/src/java/javax/jdo/identity/ShortIdentity.java
    db/jdo/trunk/api2/src/java/javax/jdo/identity/SingleFieldIdentity.java
    db/jdo/trunk/api2/src/java/javax/jdo/identity/StringIdentity.java
    db/jdo/trunk/api2/test/java/javax/jdo/identity/ByteIdentityTest.java
    db/jdo/trunk/api2/test/java/javax/jdo/identity/CharIdentityTest.java
    db/jdo/trunk/api2/test/java/javax/jdo/identity/IntIdentityTest.java
    db/jdo/trunk/api2/test/java/javax/jdo/identity/LongIdentityTest.java
    db/jdo/trunk/api2/test/java/javax/jdo/identity/ShortIdentityTest.java
    db/jdo/trunk/api2/test/java/javax/jdo/identity/StringIdentityTest.java

Modified: db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/ByteIdentity.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/ByteIdentity.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/ByteIdentity.java (original)
+++ db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/ByteIdentity.java Sat Jun 28 19:47:54
2008
@@ -113,7 +113,12 @@
     public int compareTo(Object o) {
         if (o instanceof ByteIdentity) {
         	ByteIdentity other = (ByteIdentity)o;
-            return (int)(key - other.key);
+            int result = super.compare(other);
+            if (result == 0) {
+                return (key - other.key);
+            } else {
+                return result;
+            }
         }
         else if (o == null) {
             throw new ClassCastException("object is null");

Modified: db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/CharIdentity.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/CharIdentity.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/CharIdentity.java (original)
+++ db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/CharIdentity.java Sat Jun 28 19:47:54
2008
@@ -121,7 +121,12 @@
     public int compareTo(Object o) {
         if (o instanceof CharIdentity) {
         	CharIdentity other = (CharIdentity)o;
-            return (int)(key - other.key);
+            int result = super.compare(other);
+            if (result == 0) {
+                return (key - other.key);
+            } else {
+                return result;
+            }
         }
         else if (o == null) {
             throw new ClassCastException("object is null");

Modified: db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/IntIdentity.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/IntIdentity.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/IntIdentity.java (original)
+++ db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/IntIdentity.java Sat Jun 28 19:47:54
2008
@@ -110,9 +110,14 @@
     public int compareTo(Object o) {
         if (o instanceof IntIdentity) {
         	IntIdentity other = (IntIdentity)o;
-            return key - other.key;
+            int result = super.compare(other);
+            if (result == 0) {
+                return (key - other.key);
+            } else {
+                return result;
+            }
         }
-        else if (o == null) {
+       else if (o == null) {
             throw new ClassCastException("object is null");
         }
         throw new ClassCastException(this.getClass().getName() + " != " + o.getClass().getName());

Modified: db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/LongIdentity.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/LongIdentity.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/LongIdentity.java (original)
+++ db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/LongIdentity.java Sat Jun 28 19:47:54
2008
@@ -111,7 +111,21 @@
     public int compareTo(Object o) {
         if (o instanceof LongIdentity) {
         	LongIdentity other = (LongIdentity)o;
-            return (int)(key - other.key);
+            int result = super.compare(other);
+            if (result == 0) {
+                long diff = key - other.key;
+                if (diff == 0) {
+                    return 0;
+                } else {
+                    if (diff < 0) {
+                        return -1;
+                    } else {
+                        return 1;
+                    }
+                }
+            } else {
+                return result;
+            }
         }
         else if (o == null) {
             throw new ClassCastException("object is null");

Modified: db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/ShortIdentity.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/ShortIdentity.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/ShortIdentity.java (original)
+++ db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/ShortIdentity.java Sat Jun 28 19:47:54
2008
@@ -110,7 +110,12 @@
     public int compareTo(Object o) {
         if (o instanceof ShortIdentity) {
         	ShortIdentity other = (ShortIdentity)o;
-            return key - other.key;
+            int result = super.compare(other);
+            if (result == 0) {
+                return (key - other.key);
+            } else {
+                return result;
+            }
         }
         else if (o == null) {
             throw new ClassCastException("object is null");

Modified: db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/SingleFieldIdentity.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/SingleFieldIdentity.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/SingleFieldIdentity.java (original)
+++ db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/SingleFieldIdentity.java Sat Jun
28 19:47:54 2008
@@ -186,4 +186,15 @@
         targetClassName = (String)in.readObject();
         hashCode = in.readInt();
     }
+
+    /** Determine the ordering of identity objects. Only the class name
+     *  is compared. This method is only used by subclasses.
+     * @param o Other identity
+     * @return The relative ordering between the objects
+     * @since 2.2
+     */
+    protected int compare(SingleFieldIdentity o) {
+            return targetClassName.compareTo(o.targetClassName);
+        }
+ 
 }

Modified: db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/StringIdentity.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/StringIdentity.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/StringIdentity.java (original)
+++ db/jdo/trunk/api2-legacy/src/java/javax/jdo/identity/StringIdentity.java Sat Jun 28 19:47:54
2008
@@ -86,7 +86,12 @@
     public int compareTo(Object o) {
         if (o instanceof StringIdentity) {
             StringIdentity other = (StringIdentity)o;
-            return ((String)this.keyAsObject).compareTo((String)other.keyAsObject);
+            int result = super.compare(other);
+            if (result == 0) {
+                return ((String)keyAsObject).compareTo((String)other.keyAsObject);
+            } else {
+                return result;
+            }
         }
         else if (o == null) {
             throw new ClassCastException("object is null");

Modified: db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/ByteIdentityTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/ByteIdentityTest.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/ByteIdentityTest.java (original)
+++ db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/ByteIdentityTest.java Sat Jun 28
19:47:54 2008
@@ -131,9 +131,10 @@
     	ByteIdentity c1 = new ByteIdentity(Object.class, (byte)1);
         ByteIdentity c2 = new ByteIdentity(Object.class, (byte)1);
         ByteIdentity c3 = new ByteIdentity(Object.class, (byte)2);
+        ByteIdentity c4 = new ByteIdentity(Class.class, (byte)1);
         assertEquals("Equal ByteIdentity instances compare not equal.", 0, c1.compareTo(c2));
         assertTrue("Not equal ByteIdentity instances have wrong compareTo result", c1.compareTo(c3)
< 0);
         assertTrue("Not equal ByteIdentity instances have wrong compareTo result", c3.compareTo(c1)
> 0); 
+        assertTrue("Not equal ByteIdentity instances have wrong compareTo result", c1.compareTo(c4)
> 0);
     }
-
 }

Modified: db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/CharIdentityTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/CharIdentityTest.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/CharIdentityTest.java (original)
+++ db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/CharIdentityTest.java Sat Jun 28
19:47:54 2008
@@ -140,9 +140,10 @@
     	CharIdentity c1 = new CharIdentity(Object.class, '1');
     	CharIdentity c2 = new CharIdentity(Object.class, '1');
     	CharIdentity c3 = new CharIdentity(Object.class, '2');
+        CharIdentity c4 = new CharIdentity(Class.class, '1');
         assertEquals("Equal CharIdentity instances compare not equal.", 0, c1.compareTo(c2));
         assertTrue("Not equal CharIdentity instances have wrong compareTo result", c1.compareTo(c3)
< 0);
         assertTrue("Not equal CharIdentity instances have wrong compareTo result", c3.compareTo(c1)
> 0); 
+        assertTrue("Not equal CharIdentity instances have wrong compareTo result", c1.compareTo(c4)
> 0);
     }
-
 }

Modified: db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/IntIdentityTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/IntIdentityTest.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/IntIdentityTest.java (original)
+++ db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/IntIdentityTest.java Sat Jun 28
19:47:54 2008
@@ -130,9 +130,10 @@
     	IntIdentity c1 = new IntIdentity(Object.class, 1);
     	IntIdentity c2 = new IntIdentity(Object.class, 1);
     	IntIdentity c3 = new IntIdentity(Object.class, 2);
+        IntIdentity c4 = new IntIdentity(Class.class, 1);
         assertEquals("Equal IntIdentity instances compare not equal.", 0, c1.compareTo(c2));
         assertTrue("Not equal IntIdentity instances have wrong compareTo result", c1.compareTo(c3)
< 0);
         assertTrue("Not equal IntIdentity instances have wrong compareTo result", c3.compareTo(c1)
> 0); 
+        assertTrue("Not equal IntIdentity instances have wrong compareTo result", c1.compareTo(c4)
> 0);
     }
-
 }

Modified: db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/LongIdentityTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/LongIdentityTest.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/LongIdentityTest.java (original)
+++ db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/LongIdentityTest.java Sat Jun 28
19:47:54 2008
@@ -46,8 +46,10 @@
         LongIdentity c1 = new LongIdentity(Object.class, 1);
         LongIdentity c2 = new LongIdentity(Object.class, 1);
         LongIdentity c3 = new LongIdentity(Object.class, 2);
+        LongIdentity c4 = new LongIdentity(Object.class, 0x100000001L);
         assertEquals("Equal LongIdentity instances compare not equal.", c1, c2);
         assertFalse ("Not equal LongIdentity instances compare equal", c1.equals(c3));
+        assertFalse ("Not equal LongIdentity instances compare equal", c4.equals(c1));
     }
 
     public void testLongConstructor() {
@@ -131,9 +133,12 @@
     	LongIdentity c1 = new LongIdentity(Object.class, 1);
     	LongIdentity c2 = new LongIdentity(Object.class, 1);
     	LongIdentity c3 = new LongIdentity(Object.class, 2);
+        LongIdentity c4 = new LongIdentity(Class.class, 1);
+    	LongIdentity c5 = new LongIdentity(Object.class, 0x100000001L);
         assertEquals("Equal LongIdentity instances compare not equal.", 0, c1.compareTo(c2));
         assertTrue("Not equal LongIdentity instances have wrong compareTo result", c1.compareTo(c3)
< 0);
         assertTrue("Not equal LongIdentity instances have wrong compareTo result", c3.compareTo(c1)
> 0); 
+        assertTrue("Not equal LongIdentity instances have wrong compareTo result", c1.compareTo(c4)
> 0);
+        assertTrue("Not equal LongIdentity instances have wrong compareTo result", c5.compareTo(c1)
> 0);
     }
-
 }

Modified: db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/ShortIdentityTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/ShortIdentityTest.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/ShortIdentityTest.java (original)
+++ db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/ShortIdentityTest.java Sat Jun 28
19:47:54 2008
@@ -130,9 +130,10 @@
     	ShortIdentity c1 = new ShortIdentity(Object.class, (short)1);
     	ShortIdentity c2 = new ShortIdentity(Object.class, (short)1);
     	ShortIdentity c3 = new ShortIdentity(Object.class, (short)2);
-        assertEquals("Equal IntIdentity instances compare not equal.", 0, c1.compareTo(c2));
-        assertTrue("Not equal IntIdentity instances have wrong compareTo result", c1.compareTo(c3)
< 0);
-        assertTrue("Not equal IntIdentity instances have wrong compareTo result", c3.compareTo(c1)
> 0); 
+        ShortIdentity c4 = new ShortIdentity(Class.class, (short)1);
+        assertEquals("Equal ShortIdentity instances compare not equal.", 0, c1.compareTo(c2));
+        assertTrue("Not equal ShortIdentity instances have wrong compareTo result", c1.compareTo(c3)
< 0);
+        assertTrue("Not equal ShortIdentity instances have wrong compareTo result", c3.compareTo(c1)
> 0); 
+        assertTrue("Not equal ShortIdentity instances have wrong compareTo result", c1.compareTo(c4)
> 0);
     }
-
 }

Modified: db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/StringIdentityTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/StringIdentityTest.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/StringIdentityTest.java (original)
+++ db/jdo/trunk/api2-legacy/test/java/javax/jdo/identity/StringIdentityTest.java Sat Jun
28 19:47:54 2008
@@ -93,9 +93,10 @@
     	StringIdentity c1 = new StringIdentity(Object.class, "1");
     	StringIdentity c2 = new StringIdentity(Object.class, "1");
     	StringIdentity c3 = new StringIdentity(Object.class, "2");
+        StringIdentity c4 = new StringIdentity(Class.class, "1");
         assertEquals("Equal StringIdentity instances compare not equal.", 0, c1.compareTo(c2));
         assertTrue("Not equal StringIdentity instances have wrong compareTo result", c1.compareTo(c3)
< 0);
         assertTrue("Not equal StringIdentity instances have wrong compareTo result", c3.compareTo(c1)
> 0); 
+        assertTrue("Not equal StringIdentity instances have wrong compareTo result", c1.compareTo(c4)
> 0);
     }
-
 }

Modified: db/jdo/trunk/api2/src/java/javax/jdo/identity/ByteIdentity.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/src/java/javax/jdo/identity/ByteIdentity.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2/src/java/javax/jdo/identity/ByteIdentity.java (original)
+++ db/jdo/trunk/api2/src/java/javax/jdo/identity/ByteIdentity.java Sat Jun 28 19:47:54 2008
@@ -113,7 +113,12 @@
     public int compareTo(Object o) {
         if (o instanceof ByteIdentity) {
         	ByteIdentity other = (ByteIdentity)o;
-            return (int)(key - other.key);
+            int result = super.compare(other);
+            if (result == 0) {
+                return (key - other.key);
+            } else {
+                return result;
+            }
         }
         else if (o == null) {
             throw new ClassCastException("object is null");

Modified: db/jdo/trunk/api2/src/java/javax/jdo/identity/CharIdentity.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/src/java/javax/jdo/identity/CharIdentity.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2/src/java/javax/jdo/identity/CharIdentity.java (original)
+++ db/jdo/trunk/api2/src/java/javax/jdo/identity/CharIdentity.java Sat Jun 28 19:47:54 2008
@@ -121,7 +121,12 @@
     public int compareTo(Object o) {
         if (o instanceof CharIdentity) {
         	CharIdentity other = (CharIdentity)o;
-            return (int)(key - other.key);
+            int result = super.compare(other);
+            if (result == 0) {
+                return (key - other.key);
+            } else {
+                return result;
+            }
         }
         else if (o == null) {
             throw new ClassCastException("object is null");

Modified: db/jdo/trunk/api2/src/java/javax/jdo/identity/IntIdentity.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/src/java/javax/jdo/identity/IntIdentity.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2/src/java/javax/jdo/identity/IntIdentity.java (original)
+++ db/jdo/trunk/api2/src/java/javax/jdo/identity/IntIdentity.java Sat Jun 28 19:47:54 2008
@@ -110,9 +110,14 @@
     public int compareTo(Object o) {
         if (o instanceof IntIdentity) {
         	IntIdentity other = (IntIdentity)o;
-            return key - other.key;
+            int result = super.compare(other);
+            if (result == 0) {
+                return (key - other.key);
+            } else {
+                return result;
+            }
         }
-        else if (o == null) {
+       else if (o == null) {
             throw new ClassCastException("object is null");
         }
         throw new ClassCastException(this.getClass().getName() + " != " + o.getClass().getName());

Modified: db/jdo/trunk/api2/src/java/javax/jdo/identity/LongIdentity.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/src/java/javax/jdo/identity/LongIdentity.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2/src/java/javax/jdo/identity/LongIdentity.java (original)
+++ db/jdo/trunk/api2/src/java/javax/jdo/identity/LongIdentity.java Sat Jun 28 19:47:54 2008
@@ -111,7 +111,21 @@
     public int compareTo(Object o) {
         if (o instanceof LongIdentity) {
         	LongIdentity other = (LongIdentity)o;
-            return (int)(key - other.key);
+            int result = super.compare(other);
+            if (result == 0) {
+                long diff = key - other.key;
+                if (diff == 0) {
+                    return 0;
+                } else {
+                    if (diff < 0) {
+                        return -1;
+                    } else {
+                        return 1;
+                    }
+                }
+            } else {
+                return result;
+            }
         }
         else if (o == null) {
             throw new ClassCastException("object is null");

Modified: db/jdo/trunk/api2/src/java/javax/jdo/identity/ShortIdentity.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/src/java/javax/jdo/identity/ShortIdentity.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2/src/java/javax/jdo/identity/ShortIdentity.java (original)
+++ db/jdo/trunk/api2/src/java/javax/jdo/identity/ShortIdentity.java Sat Jun 28 19:47:54 2008
@@ -110,7 +110,12 @@
     public int compareTo(Object o) {
         if (o instanceof ShortIdentity) {
         	ShortIdentity other = (ShortIdentity)o;
-            return key - other.key;
+            int result = super.compare(other);
+            if (result == 0) {
+                return (key - other.key);
+            } else {
+                return result;
+            }
         }
         else if (o == null) {
             throw new ClassCastException("object is null");

Modified: db/jdo/trunk/api2/src/java/javax/jdo/identity/SingleFieldIdentity.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/src/java/javax/jdo/identity/SingleFieldIdentity.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2/src/java/javax/jdo/identity/SingleFieldIdentity.java (original)
+++ db/jdo/trunk/api2/src/java/javax/jdo/identity/SingleFieldIdentity.java Sat Jun 28 19:47:54
2008
@@ -186,4 +186,15 @@
         targetClassName = (String)in.readObject();
         hashCode = in.readInt();
     }
+
+    /** Determine the ordering of identity objects. Only the class name
+     *  is compared. This method is only used by subclasses.
+     * @param o Other identity
+     * @return The relative ordering between the objects
+     * @since 2.2
+     */
+    protected int compare(SingleFieldIdentity o) {
+            return targetClassName.compareTo(o.targetClassName);
+        }
+ 
 }

Modified: db/jdo/trunk/api2/src/java/javax/jdo/identity/StringIdentity.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/src/java/javax/jdo/identity/StringIdentity.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2/src/java/javax/jdo/identity/StringIdentity.java (original)
+++ db/jdo/trunk/api2/src/java/javax/jdo/identity/StringIdentity.java Sat Jun 28 19:47:54
2008
@@ -86,7 +86,12 @@
     public int compareTo(Object o) {
         if (o instanceof StringIdentity) {
             StringIdentity other = (StringIdentity)o;
-            return ((String)this.keyAsObject).compareTo((String)other.keyAsObject);
+            int result = super.compare(other);
+            if (result == 0) {
+                return ((String)keyAsObject).compareTo((String)other.keyAsObject);
+            } else {
+                return result;
+            }
         }
         else if (o == null) {
             throw new ClassCastException("object is null");

Modified: db/jdo/trunk/api2/test/java/javax/jdo/identity/ByteIdentityTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/test/java/javax/jdo/identity/ByteIdentityTest.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2/test/java/javax/jdo/identity/ByteIdentityTest.java (original)
+++ db/jdo/trunk/api2/test/java/javax/jdo/identity/ByteIdentityTest.java Sat Jun 28 19:47:54
2008
@@ -131,8 +131,10 @@
     	ByteIdentity c1 = new ByteIdentity(Object.class, (byte)1);
         ByteIdentity c2 = new ByteIdentity(Object.class, (byte)1);
         ByteIdentity c3 = new ByteIdentity(Object.class, (byte)2);
+        ByteIdentity c4 = new ByteIdentity(Class.class, (byte)1);
         assertEquals("Equal ByteIdentity instances compare not equal.", 0, c1.compareTo(c2));
         assertTrue("Not equal ByteIdentity instances have wrong compareTo result", c1.compareTo(c3)
< 0);
         assertTrue("Not equal ByteIdentity instances have wrong compareTo result", c3.compareTo(c1)
> 0); 
+        assertTrue("Not equal ByteIdentity instances have wrong compareTo result", c1.compareTo(c4)
> 0);
     }
 }

Modified: db/jdo/trunk/api2/test/java/javax/jdo/identity/CharIdentityTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/test/java/javax/jdo/identity/CharIdentityTest.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2/test/java/javax/jdo/identity/CharIdentityTest.java (original)
+++ db/jdo/trunk/api2/test/java/javax/jdo/identity/CharIdentityTest.java Sat Jun 28 19:47:54
2008
@@ -140,8 +140,10 @@
     	CharIdentity c1 = new CharIdentity(Object.class, '1');
     	CharIdentity c2 = new CharIdentity(Object.class, '1');
     	CharIdentity c3 = new CharIdentity(Object.class, '2');
+        CharIdentity c4 = new CharIdentity(Class.class, '1');
         assertEquals("Equal CharIdentity instances compare not equal.", 0, c1.compareTo(c2));
         assertTrue("Not equal CharIdentity instances have wrong compareTo result", c1.compareTo(c3)
< 0);
         assertTrue("Not equal CharIdentity instances have wrong compareTo result", c3.compareTo(c1)
> 0); 
+        assertTrue("Not equal CharIdentity instances have wrong compareTo result", c1.compareTo(c4)
> 0);
     }
 }

Modified: db/jdo/trunk/api2/test/java/javax/jdo/identity/IntIdentityTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/test/java/javax/jdo/identity/IntIdentityTest.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2/test/java/javax/jdo/identity/IntIdentityTest.java (original)
+++ db/jdo/trunk/api2/test/java/javax/jdo/identity/IntIdentityTest.java Sat Jun 28 19:47:54
2008
@@ -130,8 +130,10 @@
     	IntIdentity c1 = new IntIdentity(Object.class, 1);
     	IntIdentity c2 = new IntIdentity(Object.class, 1);
     	IntIdentity c3 = new IntIdentity(Object.class, 2);
+        IntIdentity c4 = new IntIdentity(Class.class, 1);
         assertEquals("Equal IntIdentity instances compare not equal.", 0, c1.compareTo(c2));
         assertTrue("Not equal IntIdentity instances have wrong compareTo result", c1.compareTo(c3)
< 0);
         assertTrue("Not equal IntIdentity instances have wrong compareTo result", c3.compareTo(c1)
> 0); 
+        assertTrue("Not equal IntIdentity instances have wrong compareTo result", c1.compareTo(c4)
> 0);
     }
 }

Modified: db/jdo/trunk/api2/test/java/javax/jdo/identity/LongIdentityTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/test/java/javax/jdo/identity/LongIdentityTest.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2/test/java/javax/jdo/identity/LongIdentityTest.java (original)
+++ db/jdo/trunk/api2/test/java/javax/jdo/identity/LongIdentityTest.java Sat Jun 28 19:47:54
2008
@@ -46,8 +46,10 @@
         LongIdentity c1 = new LongIdentity(Object.class, 1);
         LongIdentity c2 = new LongIdentity(Object.class, 1);
         LongIdentity c3 = new LongIdentity(Object.class, 2);
+        LongIdentity c4 = new LongIdentity(Object.class, 0x100000001L);
         assertEquals("Equal LongIdentity instances compare not equal.", c1, c2);
         assertFalse ("Not equal LongIdentity instances compare equal", c1.equals(c3));
+        assertFalse ("Not equal LongIdentity instances compare equal", c4.equals(c1));
     }
 
     public void testLongConstructor() {
@@ -131,8 +133,12 @@
     	LongIdentity c1 = new LongIdentity(Object.class, 1);
     	LongIdentity c2 = new LongIdentity(Object.class, 1);
     	LongIdentity c3 = new LongIdentity(Object.class, 2);
+        LongIdentity c4 = new LongIdentity(Class.class, 1);
+    	LongIdentity c5 = new LongIdentity(Object.class, 0x100000001L);
         assertEquals("Equal LongIdentity instances compare not equal.", 0, c1.compareTo(c2));
         assertTrue("Not equal LongIdentity instances have wrong compareTo result", c1.compareTo(c3)
< 0);
         assertTrue("Not equal LongIdentity instances have wrong compareTo result", c3.compareTo(c1)
> 0); 
+        assertTrue("Not equal LongIdentity instances have wrong compareTo result", c1.compareTo(c4)
> 0);
+        assertTrue("Not equal LongIdentity instances have wrong compareTo result", c5.compareTo(c1)
> 0);
     }
 }

Modified: db/jdo/trunk/api2/test/java/javax/jdo/identity/ShortIdentityTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/test/java/javax/jdo/identity/ShortIdentityTest.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2/test/java/javax/jdo/identity/ShortIdentityTest.java (original)
+++ db/jdo/trunk/api2/test/java/javax/jdo/identity/ShortIdentityTest.java Sat Jun 28 19:47:54
2008
@@ -130,8 +130,10 @@
     	ShortIdentity c1 = new ShortIdentity(Object.class, (short)1);
     	ShortIdentity c2 = new ShortIdentity(Object.class, (short)1);
     	ShortIdentity c3 = new ShortIdentity(Object.class, (short)2);
-        assertEquals("Equal IntIdentity instances compare not equal.", 0, c1.compareTo(c2));
-        assertTrue("Not equal IntIdentity instances have wrong compareTo result", c1.compareTo(c3)
< 0);
-        assertTrue("Not equal IntIdentity instances have wrong compareTo result", c3.compareTo(c1)
> 0); 
+        ShortIdentity c4 = new ShortIdentity(Class.class, (short)1);
+        assertEquals("Equal ShortIdentity instances compare not equal.", 0, c1.compareTo(c2));
+        assertTrue("Not equal ShortIdentity instances have wrong compareTo result", c1.compareTo(c3)
< 0);
+        assertTrue("Not equal ShortIdentity instances have wrong compareTo result", c3.compareTo(c1)
> 0); 
+        assertTrue("Not equal ShortIdentity instances have wrong compareTo result", c1.compareTo(c4)
> 0);
     }
 }

Modified: db/jdo/trunk/api2/test/java/javax/jdo/identity/StringIdentityTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/test/java/javax/jdo/identity/StringIdentityTest.java?rev=672600&r1=672599&r2=672600&view=diff
==============================================================================
--- db/jdo/trunk/api2/test/java/javax/jdo/identity/StringIdentityTest.java (original)
+++ db/jdo/trunk/api2/test/java/javax/jdo/identity/StringIdentityTest.java Sat Jun 28 19:47:54
2008
@@ -93,8 +93,10 @@
     	StringIdentity c1 = new StringIdentity(Object.class, "1");
     	StringIdentity c2 = new StringIdentity(Object.class, "1");
     	StringIdentity c3 = new StringIdentity(Object.class, "2");
+        StringIdentity c4 = new StringIdentity(Class.class, "1");
         assertEquals("Equal StringIdentity instances compare not equal.", 0, c1.compareTo(c2));
         assertTrue("Not equal StringIdentity instances have wrong compareTo result", c1.compareTo(c3)
< 0);
         assertTrue("Not equal StringIdentity instances have wrong compareTo result", c3.compareTo(c1)
> 0); 
+        assertTrue("Not equal StringIdentity instances have wrong compareTo result", c1.compareTo(c4)
> 0);
     }
 }



Mime
View raw message