zoukankan      html  css  js  c++  java
  • Java8 集合分组

    通过java8新特性 将一个list转换为一个list包含一个子list 子List也包含一个list的形式

    private List<RecordExcelVO> convertExcel(List<ProjectDeclaration> projectList) {
            List<RecordExcelVO> list = new ArrayList<>();
    
            if (CollectionUtils.isNotEmpty(projectList)) {
                // 按照备案日期分组
                Map<String, List<ProjectDeclaration>> firstGroup = projectList.stream().collect(Collectors.groupingBy(item -> DateFormatUtils.format(item.getRecordTime(), Constants.YEAR_MONTH)));
    
                for (Map.Entry<String, List<ProjectDeclaration>> first : firstGroup.entrySet()) {
                    RecordExcelVO recordExcelVO = new RecordExcelVO();
    
                    List<RecordExcelVO.CompanyVO> companies = new ArrayList<>();
                    recordExcelVO.setMonth(first.getKey());
                    recordExcelVO.setCompanies(companies);
    
                    if (CollectionUtils.isNotEmpty(first.getValue())) {
                        // 按照建设单位分组
                        Map<String, List<ProjectDeclaration>> secondGroup = first.getValue().stream().collect(Collectors.groupingBy(item -> item.getCompanyName()));
    
                        for (Map.Entry<String, List<ProjectDeclaration>> second : secondGroup.entrySet()) {
                            RecordExcelVO.CompanyVO company = new RecordExcelVO.CompanyVO();
                            company.setCompanyName(second.getKey());
                            company.setProjects(second.getValue());
    
                            companies.add(company);
                        }
                    }
    
    
                    list.add(recordExcelVO);
                }
            }
    
            list = list.stream().sorted(Comparator.comparing(RecordExcelVO::getMonth)).collect(Collectors.toList());
    
            return list;
        }
  • 相关阅读:
    js加密
    sharepoint更新左侧列表的名字
    HTML转换JS
    Html空格字符代码:
    docker 与host互传文件
    Ubuntu里node命令出错,找不到
    docker查看运行容器详细信息
    docker保存容器的修改
    Docker容器中安装新的程序
    运行docker容器镜像
  • 原文地址:https://www.cnblogs.com/rain-in-summer/p/9207551.html
Copyright © 2011-2022 走看看