Parent是一个被Child继承的类,Child又被GrandChild继承。每个类都包含子类的列表(即Parent包含Child的列表,Child包含GrandChild的列表)。每个类都包含50个属性(attrib1-atrib50)。 getChildList()返回类型为Child对象的arrayList,getGrandChildList()返回类型为GrandChild对象的arrayList。
让resultSet成为Parent的列表。
List<Parent> resultSet
现在我想根据一些属性对列表进行排序。例如,如果我想根据两个父属性(比如 Attribute 1 和 attribute 2)对 resultSet 进行排序,我使用以下代码。
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());
现在我想根据Child类的属性1和GrandChild类的属性1对parentlist进行排序。我该如何排序。