I want to sort objects based on Boolean values and I want to sort true values before false values.
Which of these implementations of compareTo is more readable?
Using -1 to change default behavior
public class Example implements Comparable<Example>{
Boolean isOk;
public int compareTo(Example o) {
return -1 * this.isOk.compareTo(o.isOk);
}
}
or swap sides of Boolean#compareTo method?
public class ExampleTwo implements Comparable<ExampleTwo>{
Boolean isOk;
public int compareTo(ExampleTwo o) {
return o.isOk.compareTo(this.isOk);
}
}