If you have two elements when are equal a
and b
you will get compare(a, b) == -1
and compare(b, a) == -1
which doesn't make any sense.
You can simplify the code with and make it more efficient with
class TimeComparatorTipo0 implements Comparator<DataImportedTipo0> {
@Override
public int compare(DataImportedTipo0 a, DataImportedTipo0 b) {
String Time1 = a.ora, Time2 = b.ora;
int cmp = Time1.compareTo(Time2);
if (cmp == 0) {
// avoid expensive operations.
Long VolTot1 = Long.parseLong(a.volume_totale);
Long VolTot2 = Long.parseLong(b.volume_totale);
cmp = VolTot1.compareTo(VolTot2);
}
return cmp;