Parent is a class which is inherited by Child. which is inherited by GrandChild. Each class contains List of the child class(i.e Parent contains List of Child and Child contains List of GrandChild). Each class contains 50 attributes(attrib1-atrib50). getChildList() returns the arrayList of objects of type Child getGrandChildList() returns the arrayList of objects of type GrandChild
Let resultSet be List of Parent
List<Parent> resultSet
Now I want to sort the list based on some attributes. For example if I want to sort resultSet based on two parent attributes(say Attribute 1 and attribute 2, I use this code.
Comparator<Parent> byFirst = (e1, e2) -> e2.getAttrib1().compareTo(e1.getAttrib1());
Comparator<Parent> bySecond = (e1, e2) -> e1.getAttrib2().compareTo(e2.getAttrib2());
Comparator<Parent> byThird = byFirst.thenComparing(bySecond);
List<Parent> sortedList = resultSet.stream().sorted(byThird).collect(Collectors.toList());
Now I want to sort the parentlist based on attribute 1 of Child class and attribute 1 of GrandChild class. How should I sort this.