Collectors.groupingBy应用

@Override
public Map<String, Map<String, List<ServiceGitEntity>>> uiCasePolicyDropList(long jiraBrand) {
Example example = new Example(ServiceEntity.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("jiraBrand", jiraBrand);
List<ServiceEntity> serviceEntities = serviceMapper.selectByExample(example);
List<GitEntity> gitEntities = gitMapper.getByType(GitType.UT.getCode());
List<ServiceGitEntity> serviceGitEntities = new ArrayList<>();
ServiceGitEntity serviceGit = null;
for (ServiceEntity serviceEntity : serviceEntities) {
for (GitEntity gitEntity : gitEntities) {
if (serviceEntity.getId().equals(gitEntity.getServiceId())) {
serviceGit = new ServiceGitEntity();
serviceGit.setProject(serviceEntity.getProject());
serviceGit.setBranch(gitEntity.getBranch());
serviceGit.setName(serviceEntity.getName());
serviceGit.setId(serviceEntity.getId());
serviceGit.setUrl(gitEntity.getUrl());
if (!serviceGitEntities.contains(serviceGit)) {
serviceGitEntities.add(serviceGit);
}
}
}
}
Map<String, Map<String, List<ServiceGitEntity>>> map = serviceGitEntities.stream().collect(Collectors.groupingBy(ServiceGitEntity::getProject,Collectors.groupingBy(ServiceGitEntity::getName)));
return map;
}
原文地址:https://www.cnblogs.com/cristin/p/14277698.html