Sorry for this duplicate question that has been already answered on other posts. Unfortunately i did not know how to implement it on my code :
public int compare(Group gp1, Group gp2){
if (gp1.isPredOf(gp2))
return 1;
if (gp2.isPredOf(gp1))
return -1;
return 0;
}
Note that if gp1
is a predecessor of gp2
, gp2.isPredOf(gp1)
will return false
and vice versa.
Could you please show me the appropriate code to avoid this exception ?
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Comparison method violates its general contract!
Thank you for your help.
PS : the code of the function "isPredOf" :
public boolean isPredOf(Group gp2){
for (Operation op1 : this.operations){
for (int i=0;i<=op1.job.operations.indexOf(op1);i++){
if (gp2.operations.contains(op1.job.operations.get(i)))
return true;
}
}
return false;
}