public class ChromosomeRanking implements Comparable<ChromosomeRanking>{
private double ranking;
private Chromosome chrom;
@Override
public int compareTo(ChromosomeRanking cr2) {
if(this.ranking == cr2.ranking){
return 0;
}
if(this.ranking < cr2.ranking){
return -1;
}
if(this.ranking > cr2.ranking){
return 1;
}
return 0;
}
/**
*Other methods here
*/
}
//Using above class here:
ArrayList<ChromosomeRanking> chromRankList = new ArrayList<ChromosomeRanking>();
//Lines here add members into the ArrayList
//Then calling this sort method:
Collections.sort(chromRankList);
//This code is called in numerous times while the application runs. It is running without any issue sometimes. But most of the times it is returning this exception message:
java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.ComparableTimSort.mergeLo(Unknown Source)
at java.util.ComparableTimSort.mergeAt(Unknown Source)
at java.util.ComparableTimSort.mergeCollapse(Unknown Source)
at java.util.ComparableTimSort.sort(Unknown Source)
at java.util.ComparableTimSort.sort(Unknown Source)
at java.util.Arrays.sort(Unknown Source)
at java.util.Collections.sort(Unknown Source)
I am very much in need to resolve this issue asap. Any type of help is appreciated. Thanks.