[英]Sorting a List inside a complex map
I need help, i could not find a way to resolve this task.. 我需要帮助,我找不到解决此任务的方法。
I created this map from an ArrayList in following way: 我通过以下方式从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))));
My problem is that i need to group the second level for ab.getPuntoBean().getNomePunto()
but i I would like to have this group ordered by another field/method: ab.getPuntoBean().getKm()
我的问题是我需要将第二层的
ab.getPuntoBean().getNomePunto()
但是我想按另一个字段/方法对这个组进行排序: ab.getPuntoBean().getKm()
try this 尝试这个
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;
}
)
)
));
or this one 或这个
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()))
))));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.