[
https://issues.apache.org/jira/browse/MATH-610?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13059137#comment-13059137
]
Phil Steitz commented on MATH-610:
----------------------------------
There is no reliance in the public API on the CompareTo impl in this inner
class - it is just used to sort the <int,double> pairs to construct the
ranking. If Arrays.sort stops working in this way, we will have big problems
:) That said, I am OK adding this if you are willing to add tests. I do think
there is an error in the hashcode impl, which the tests would show (unless I am
mistaken), since compareTo is based on the double components (ignoring the int
values) and your equals impl (correctly) makes instances with the same double
value equivalent. Using the int value in the hash can make equal instances
have different hashes.
> [patch] objects that use compareTo should have equals as well
> -------------------------------------------------------------
>
> Key: MATH-610
> URL: https://issues.apache.org/jira/browse/MATH-610
> Project: Commons Math
> Issue Type: Improvement
> Affects Versions: 3.0
> Reporter: Dave Brosius
> Priority: Trivial
> Fix For: 3.0
>
> Attachments: equals.diff
>
>
> NaturalRanking implements compareTo. Code that implements compareTo should
> also implement equals, and those that implement equals should implement
> hashCode. This patch does this.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira