Skip to content

Commit

Permalink
Corrected comparator in InvPair sorting. The current comparison was i…
Browse files Browse the repository at this point in the history
…n violation of the comparable contract which was throwing an IllegalArgumentException on JRE 7.

Change-Id: I5d3753a51afcb38585f2f17dac0c769c564ebac8
Signed-off-by: maclean <gilleain.torrance@gmail.com>
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Dec 6, 2012
1 parent 8fc7db8 commit 5937bd1
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/main/org/openscience/cdk/graph/invariant/CanonicalLabeler.java
Expand Up @@ -179,17 +179,26 @@ private void primeProduct(ArrayList v, IAtomContainer atomContainer) {
* @param v the invariance pair vector
* @cdk.todo can this be done in one loop?
*/
private void sortArrayList(ArrayList v) {
Collections.sort(v, new Comparator() {
public int compare(Object o1, Object o2) {
return (int) (((InvPair) o1).getCurr() - ((InvPair) o2).getCurr());
}
});
Collections.sort(v, new Comparator() {
public int compare(Object o1, Object o2) {
return (int) (((InvPair) o1).getLast() - ((InvPair) o2).getLast());
}
});
private void sortArrayList(List<InvPair> v) {
Collections.sort(v, new Comparator<InvPair>() {
public int compare(InvPair o1, InvPair o2) {
if (o1.getCurr() > o2.getCurr())
return +1;
if (o1.getCurr() < o2.getCurr())
return -1;
return 0;
}
});
Collections.sort(v, new Comparator<InvPair>() {
@Override
public int compare(InvPair o1, InvPair o2) {
if (o1.getLast() > o2.getLast())
return +1;
if (o1.getLast() < o2.getLast())
return -1;
return 0;
}
});
}

/**
Expand Down

0 comments on commit 5937bd1

Please sign in to comment.