We want to sort objects by three different criteria, the criteria with higher priority overrides the next one):
- status field
- time field
- sort field
- status are enums and have a custom sorting, which we implemented by a comparator. (unknown, open, closed,)
- sortBy Field is an Integer and can be sorted accordingly
- time field can be null, we only want to sort the ones with null to the top and leave the remaining sorting as it is
example:
- Object1(status: open, time: 1, sort: 4)
- Object2(status: closed, time: null, sort: 1)
- Object3(status: unknown, time: 2, sort: 3)
- Object4(status: unknown, time: null, sort: 2)
- Object5(status: open, time: 1, sort: 5)
sorted:
- Object 3 (status: unknown)
- Object 4 (status: unknown, next item in the original list)
- Object 2 (status != unknown, time: null)
- Object 1 (status != unknown, time != null, sort: 4)
- Object 5 (status != unknown, time != null, sort: 5)
we return the list the following way:
list.sortedWith(statusComparator.thenBy { it.sort }
What is missing is the sorting of items with time = null. How do I sort the items with time = null to the top and leave the remaining sorting untouched?