I have a set of data and want to sort this data based on its field and their priority in a given config.
priority queue or treeMap with custom comparator based on fields priority can be used.
I have tried the comparator approach but that is not generic enough to handle insertion/removal of the object's field in the priority config.
List<Students> students
1. Student1 : "agc", "2", "12 Aug 2001"
2. Student2 : "acc", "1", "12 Aug 2001"
3. Student3 : "abc", "2", "12 Aug 2003"
{
field : "name", priority: "2",
field : "classRank", priority: "1"
}
studentsSorted = new PriorityQueue(students, new CustomComparator());
OR
studentsSorted = students.sort(Comparator.comparing(student::classRank).thenComparing(student::name))
answer : sorted order :
Student2 Student3 Student1
Expectation: generic enough to handle the insertion/removal of fields without code change in the comparator.
Please help.