I have an arraylist of several items. An item may have a specific int field LYING equal to OFF, FLOOR, RB1, RB2, RB3 or RB4.
For example OFF is defined as:
public static final int OFF = 0;
Regarding some specific global variables I would like to order those elements in a custom way, that may be for example:
- all the RB1 items at the begin of the arraylist, all the RB2 items after any RB3 items (regardless the OFF items) and all the RB4 at the end of the arraylist.
Which is the best solution for my case?
Focusing on writing some custom:
public int compare(Object o1, Object o2) {
if(globalVariable0 > 0) {
if(o1.getLying() == o2.getLying)
return 0;
if(o1.getLying() == RB1 && o2.getLying != RB1)
return -1;
...
}else{
...
}
or..?
public int compareTo(Object other) { return this.getLying().value() - other.getLying().value(); }