lambda表达式之stream filter和map的应用

public List getListEntire(U u) {

    //
        List userList=dao.selectAllEntire(u);
       List ids = userList.stream().map(u -> u.getId()).collect(Collectors.toList());
        List userRoles=dao.getUserRoleByUserIds(ids);
        Set roleIds=userRoles.stream().map(u -> u.getRoleId()).collect(Collectors.toSet());
        List roles=dao.getRoleByRoleIds(roleIds);
        List result=new ArrayList<>();
        for(User u:userList){
            //u.setRoleIds();
            List t1=userRoles.stream().filter((UserRole u1) ->u.getId().contains(u1.getUserId()) ).collect(Collectors.toList());
            Set roleIdsR=t1.stream().map(ut -> ut.getRoleId()).collect(Collectors.toSet());
            u.setRoleIds(roleIdsR);
            List t2=roles.stream().filter((Role roleIdRt) -> roleIdsR.contains(roleIdRt.getId()) ).collect(Collectors.toList());
            List roleNames=t2.stream().map(ut2 -> ut2.getName()).collect(Collectors.toList());
            u.setRoleNames(roleNames);
            result.add(u);
        }
        return result;
}

你可能感兴趣的:(编程语言)