I need to sort my array list in custom order (not alphabetical order) by its own String property.
List<WeekSales> saleList = new ArrayList<>();
...
WeekSales:
public class WeekSales{
private String day;
private int amount;
// getters setters
...
}
Property day
is always a day of the week. ("Sunday","Monday", etc...) So I need to order the elements of the list according to the order of the week.("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
So I tried with google.common.collect.Ordering.
But it gives me an error
Cannot compare value: com.certus.controllers.WeekSales
Comparator<WeekSales> com = Ordering.explicit(new WeekSales("Monday",0), new WeekSales("Tuesday",0), new WeekSales("Wednesday",0), new WeekSales("Thursday",0), new WeekSales("Friday",0), new WeekSales("Saturday",0),new WeekSales("Sunday",0));
saleList.sort(com);
Any help would be appreciable. Thank you.
UPDATE :
This question has no any solution for my problem. I have got a custom order in my case.
("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")