我需要帮助,我找不到解决此任务的方法。
我通过以下方式从ArrayList创建了此映射:
Map<RamiBean, Map<String, Map<String, List<AllertaBean>>>> complexMap = allerte.stream()
.distinct()
.collect(Collectors.groupingBy(
ab -> ab.getRamoBean(),
Collectors.groupingBy(ab -> ab.getPuntoBean().getNomePunto(),
Collectors.groupingBy(AllertaBean::getDescAllerta))));
我的问题是我需要对ab.getPuntoBean().getNomePunto()
的第二级进行分组,但是我想按另一字段/方法对这一组进行排序:ab.getPuntoBean().getKm()
答案 0 :(得分:0)
尝试
Map<RamiBean, Map<String, Map<String, List<AllertaBean>>>> complexMap = allerte.stream()
.distinct()
.collect(Collectors.groupingBy(
ab -> ab.getRamoBean(),
Collectors.groupingBy(ab -> ab.getPuntoBean().getNomePunto(),
Collectors.toMap(
AllertaBean::getDescAllerta,
ab -> new ArrayList(Arrays.asList(ab)),
(abList1, abList2) -> {
abList1.addAll(abList2);
abList1.sort(Comparator.comparing(ab -> ab.getPuntoBean().getKm()))
return abList1;
}
)
)
));
或这个
Map<RamiBean, Map<String, Map<String, List<AllertaBean>>>> complexMap = allerte.stream()
.distinct()
.collect(Collectors.groupingBy(
ab -> ab.getRamoBean(),
Collectors.groupingBy(ab -> ab.getPuntoBean().getNomePunto(),
Collectors.groupingBy(AllertaBean::getDescAllerta,
Collectors. collectingAndThen(Collectors.toList(),
abList -> abList.sort(Comparator.comparing(ab -> ab.getPuntoBean().getKm()))
))));