Chromosome contains a number of scores generated in different ways. The compareTo method actually tests the agreement of the methods and accordingly returns a result.
return 1: comp = -5..-1
return 0: comp = 0 (can happen in different scenarios one of which is that all scores are equal.
return -1: comp = 1..5
public int compareTo(Chromosome o) {
if(o == null)
return(1);
int comp = 0;
comp += Double.compare(getScore(1),o.getScore(1));
comp += Double.compare(getScore(2),o.getScore(2));
comp += Double.compare(getScore(3),o.getScore(3));
comp += Double.compare(getScore(5),o.getScore(5));
comp += Double.compare(getScore(7),o.getScore(7));
if(comp == 0)
return(0);
if(comp > 0)
return(1);
else
return(-1);
}
My question is, how to make this scenario adhere to the rules imposed by the contract for the comparator. Apparently it doesn't and I keep getting: java.lang.IllegalArgumentException: Comparison method violates its general contract!