commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne" <scolebou...@btopenworld.com>
Subject Re: [collections] ComparableComparator executes all comparisons twice!?
Date Wed, 08 Jan 2003 23:45:33 GMT
From: "Rodney Waldhoff" <rwaldhoff@apache.org>
Subject: [collections] ComparableComparator executes all comparisons twice!?

> I recently noticed something that I found rather surprising.  Given two
> Comparables compA and compB, ComparableComparator always executes both
> compA.compareTo(compB) *and* compB.compareTo(compA)  (and throws
> ClassCastException if the two results are inconsistent).
Crazy!

> I suggest that we replace the block above with simply:
>
>   return ((Comparable)o1).compareTo(o2);
+1

>  Unfortunately ComparableComparator does in fact state in its
> JavaDocs that it "throws ClassCastException if the compareTo of both
> objects do not provide an inverse result of each other as per the
> Comparable javadoc.", which does make this a small change in the
> ComparableComparator contract.  This change in contract would of course
> imply a new major version number, per the commons versioning guidelines.
I suppose so, although personally I wouldn't be hung up on this particular
change.

> (The addition of collections.primitives probably justifies a new major
> version number anyway.)
Agreed.

If we do go to 3.0, then could we delete the deprecated iterators and
comparators in the main package?

Stephen



--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message