繁体   English   中英

在复杂地图中对列表进行排序

[英]Sorting a List inside a complex map

我需要帮助,我找不到解决此任务的方法。

我通过以下方式从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()

尝试这个

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()))
  ))));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM