I'm implementing and using the Comparable interface in my class "History". This way I want to sort an ArrayList of History objects.
The class constructor looks like this:
public History(long id, String res, double deposit, double odds, String sport, double ret, String user_name, Date date) {
this.id = id;
this.res = res;
this.deposit = deposit;
this.odds = odds;
this.sport = sport;
this.ret = ret;
this.user_name = user_name;
this.date = date;
}
@Override
public int compareTo(History o) {
return this.getDepInt().compareTo(o.getDepInt());
}
Also, I have respective methods to return the variables e.g. "getDepInt()", getOddsInt() etc.
This works fine, and im able to sort the list by the deposit variable:
[172 Loss | 1000.0 | 1.1 | 1100.0 | F
, 170 Loss | 900.0 | 2.75 | 2475.0 | F
, 168 Won | 300.0 | 2.75 | 825.0 | F
, 169 Won | 200.0 | 2.75 | 550.0 | F
, 105 Loss | 175.0 | 2.75 | 481.25 | F
, 167 Won | 100.0 | 2.5 | 250.0 | F
, 166 Loss | 100.0 | 2.5 | 250.0 | F
, 165 Won | 100.0 | 2.5 | 250.0 | F
, 164 Won | 100.0 | 2.5 | 250.0 | F
, 171 Loss | 20.0 | 1.5 | 30.0 | F
]
However, I want to be able to sort the list on all varibles, so the user can select which way the they want to sort the list e.g. sort the list by "Won/Loss".
My problem is that the compareTo(History o) method overwrites, and im not actually calling the method in my code. Is there a way of solving this?