You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-dev@db.apache.org by "Andy Jefferson (JIRA)" <ji...@apache.org> on 2008/06/26 09:16:45 UTC
[jira] Created: (JDO-598) Make SingleFieldIdentity classes
implement Comparable
Make SingleFieldIdentity classes implement Comparable
-----------------------------------------------------
Key: JDO-598
URL: https://issues.apache.org/jira/browse/JDO-598
Project: JDO
Issue Type: Improvement
Components: api2
Reporter: Andy Jefferson
Fix For: JDO 2 maintenance release 2
Would be preferable for javax.jdo.identity classes to implement Comparable so that we can store them in a TreeSet etc
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Closed: (JDO-598) Make SingleFieldIdentity classes implement
Comparable
Posted by "Craig Russell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/JDO-598?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Craig Russell closed JDO-598.
-----------------------------
Resolution: Fixed
Assignee: Andy Jefferson
SingleFieldIdentity classes now implement Comparable, allowing their use directly in ordered collections.
> Make SingleFieldIdentity classes implement Comparable
> -----------------------------------------------------
>
> Key: JDO-598
> URL: https://issues.apache.org/jira/browse/JDO-598
> Project: JDO
> Issue Type: Improvement
> Components: api2, api2-legacy
> Reporter: Andy Jefferson
> Assignee: Andy Jefferson
> Fix For: JDO 2 maintenance release 2
>
> Attachments: SingleFieldIdentity_Comparable.patch
>
>
> Would be preferable for javax.jdo.identity classes to implement Comparable so that we can store them in a TreeSet etc
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (JDO-598) Make SingleFieldIdentity classes
implement Comparable
Posted by "Craig Russell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/JDO-598?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12608631#action_12608631 ]
Craig Russell commented on JDO-598:
-----------------------------------
I think that an implementation of compareTo that always returns zero would effectively disallow the class from being used for keys of Map or entries of Collection. The second entry would compare equal with the first entry and be disallowed. This might be confusing to the user.
I think better would be to throw an exception if the key instance did not implement Comparable. This would allow the known good cases to work correctly and give a reasonable error message ("The key class Foo does not implement Comparable").
> Make SingleFieldIdentity classes implement Comparable
> -----------------------------------------------------
>
> Key: JDO-598
> URL: https://issues.apache.org/jira/browse/JDO-598
> Project: JDO
> Issue Type: Improvement
> Components: api2
> Reporter: Andy Jefferson
> Fix For: JDO 2 maintenance release 2
>
> Attachments: SingleFieldIdentity_Comparable.patch
>
>
> Would be preferable for javax.jdo.identity classes to implement Comparable so that we can store them in a TreeSet etc
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (JDO-598) Make SingleFieldIdentity classes
implement Comparable
Posted by "Andy Jefferson (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/JDO-598?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Andy Jefferson updated JDO-598:
-------------------------------
Attachment: SingleFieldIdentity_Comparable.patch
Patch providing Comparable for "api2" project. Want this on "api2-legacy" too ?
Patch does the following
1. IntIdentity, ShortIdentity, LongIdentity, CharIdentity, ByteIdentity, StringIdentity provide implementation of compareTo() allowing comparison with other identity *of the same type*.
2. ObjectIdentity disallows comparison
> Make SingleFieldIdentity classes implement Comparable
> -----------------------------------------------------
>
> Key: JDO-598
> URL: https://issues.apache.org/jira/browse/JDO-598
> Project: JDO
> Issue Type: Improvement
> Components: api2
> Reporter: Andy Jefferson
> Fix For: JDO 2 maintenance release 2
>
> Attachments: SingleFieldIdentity_Comparable.patch
>
>
> Would be preferable for javax.jdo.identity classes to implement Comparable so that we can store them in a TreeSet etc
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (JDO-598) Make SingleFieldIdentity classes
implement Comparable
Posted by "Craig Russell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/JDO-598?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12608529#action_12608529 ]
Craig Russell commented on JDO-598:
-----------------------------------
Thanks for providing this patch.
1. Yes, this should go into api2-legacy until we abandon Java 1.4.
2. We can add special treatment to ObjectIdentity later if needed but the basic functionality is fine.
3. Can you add test cases that verify the implementation is correct? Probably sufficient to create a few instances (of each SingleFieldIdentity type) and verify that they compare correctly. With the test cases passing, I think this is good to go. Here's an example of what I mean:
public void testCompareTo() {
ByteIdentity c1 = new ByteIdentity(Object.class, (byte)1);
ByteIdentity c2 = new ByteIdentity(Object.class, (byte)1);
ByteIdentity c3 = new ByteIdentity(Object.class, (byte)2);
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);
}
> Make SingleFieldIdentity classes implement Comparable
> -----------------------------------------------------
>
> Key: JDO-598
> URL: https://issues.apache.org/jira/browse/JDO-598
> Project: JDO
> Issue Type: Improvement
> Components: api2
> Reporter: Andy Jefferson
> Fix For: JDO 2 maintenance release 2
>
> Attachments: SingleFieldIdentity_Comparable.patch
>
>
> Would be preferable for javax.jdo.identity classes to implement Comparable so that we can store them in a TreeSet etc
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (JDO-598) Make SingleFieldIdentity classes
implement Comparable
Posted by "Andy Jefferson (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/JDO-598?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12608664#action_12608664 ]
Andy Jefferson commented on JDO-598:
------------------------------------
SVN trunk now has identity classes implementing Comparable, along with simple tests.
> Make SingleFieldIdentity classes implement Comparable
> -----------------------------------------------------
>
> Key: JDO-598
> URL: https://issues.apache.org/jira/browse/JDO-598
> Project: JDO
> Issue Type: Improvement
> Components: api2
> Reporter: Andy Jefferson
> Fix For: JDO 2 maintenance release 2
>
> Attachments: SingleFieldIdentity_Comparable.patch
>
>
> Would be preferable for javax.jdo.identity classes to implement Comparable so that we can store them in a TreeSet etc
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (JDO-598) Make SingleFieldIdentity classes
implement Comparable
Posted by "Matthew T. Adams (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/JDO-598?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12608623#action_12608623 ]
Matthew T. Adams commented on JDO-598:
--------------------------------------
Maybe we could support ObjectIdentity with a compareTo method like this:
int compareTo(Object that) {
if (that instanceof Comparable && this.getKey() instanceof Comparable) { /* cast both & return comparison */ }
else {
return 0; // just return 0 because we don't know
}
}
Thoughts?
> Make SingleFieldIdentity classes implement Comparable
> -----------------------------------------------------
>
> Key: JDO-598
> URL: https://issues.apache.org/jira/browse/JDO-598
> Project: JDO
> Issue Type: Improvement
> Components: api2
> Reporter: Andy Jefferson
> Fix For: JDO 2 maintenance release 2
>
> Attachments: SingleFieldIdentity_Comparable.patch
>
>
> Would be preferable for javax.jdo.identity classes to implement Comparable so that we can store them in a TreeSet etc
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (JDO-598) Make SingleFieldIdentity classes
implement Comparable
Posted by "Andy Jefferson (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/JDO-598?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Andy Jefferson updated JDO-598:
-------------------------------
Component/s: api2-legacy
> Make SingleFieldIdentity classes implement Comparable
> -----------------------------------------------------
>
> Key: JDO-598
> URL: https://issues.apache.org/jira/browse/JDO-598
> Project: JDO
> Issue Type: Improvement
> Components: api2, api2-legacy
> Reporter: Andy Jefferson
> Fix For: JDO 2 maintenance release 2
>
> Attachments: SingleFieldIdentity_Comparable.patch
>
>
> Would be preferable for javax.jdo.identity classes to implement Comparable so that we can store them in a TreeSet etc
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.