I suspect this is at least one immediate problem:
if (p1.getBPos().isDeparture() && p2.getBPos().isVacation()) {
return SWAP_BPOS;
} else if (p1.getBPos().isVacation() && p2.getBPos().isDeparture()) {
return SWAP_BPOS;
}
If you call compare(p1, p2)
and then compare(p2, p1)
you'll get the same non-zero result... which breaks the comparison rules.
Basically, your comparison needs to obey the documented rules. The above is one problem - it's entirely possible there are more. You should read the rules very carefully and think about how your comparison needs to work.
You can start off by negating SWAP_BPOS
for the reverse situation:
if (p1.getBPos().isDeparture() && p2.getBPos().isVacation()) {
return SWAP_BPOS;
} else if (p1.getBPos().isVacation() && p2.getBPos().isDeparture()) {
return -SWAP_BPOS;
}
That may not be everything required, but it's a start.