I'm searching how to order my elements of a list and then get a value by getType.. if getType == 0 set y that element first at the list (But not replace the item in 0 positions.)the others don't need to order them by Type.
I've done two comparables in my code. First i've order'em by getDate .. second, I've order'em by getType. But of course, the last list that my method returns is a list ordered by Type. I don't want that.
public List<PromotionList> returnSortedList(List<PromotionList> inputList) {
Collections.sort(inputList, (o1, o2) -> {
if (o1.getDate() != null) {
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss a", Locale.ENGLISH);
try {
return format.parse(o2.getDate()).compareTo(format.parse(o1.getDate()));
} catch (ParseException e) {
e.printStackTrace();
// Log.e("ErrorGetDate", e.getMessage());
return 0;
}
}
return 0;
});
Collections.sort(inputList, (o1, o2) -> {
if (o1.getType() != null && o2.getType() != null) {
if (o1.getPrioridad() == 0) {
int prior1 = o1.getType();
int prior2 = o2.getType();
return Integer.compare(prior1, prior2);
}
}
return 0;
return inputList;
}
Thanks.