Create sortPrescriptionList method

This commit is contained in:
jacques 2022-06-29 04:56:26 +02:00
parent 76639d0d82
commit 5110e6b9b8

View file

@ -3,7 +3,9 @@ package net.foucry.pilldroid;
import net.foucry.pilldroid.models.Medicine;
import net.foucry.pilldroid.models.Prescription;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Random;
@ -45,4 +47,16 @@ public class Utils {
return aPrescription;
}
public static void sortPrescriptionList(List<Prescription> prescriptionList) {
prescriptionList.sort(new Comparator<>() {
@Override
public int compare(Prescription lhs, Prescription rhs) {
if (lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()) != 0)
return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock());
else
return (int) (lhs.getStock() - rhs.getStock());
}
});
}
}