java8 stream流过滤数据
java8 流stream开发说明
List<Model> modelList = list.stream().filter(e -> !e.getId().equals(model.getId())).collect(Collectors.toList());
if(CollectionUtil.isNotEmpty(modelList)){
List<Model> models = modelList.stream().filter(e -> e.getKey().equals(key)).collect(Collectors.toList());
if(CollectionUtil.isNotEmpty(models)){
return R.fail("模型KEY已存在");
}
}
排序
list.stream().sorted(Comparator.comparing(HistoricTaskInstance::getEndTime, Comparator.nullsFirst(Date::compareTo))).collect(Collectors.toList());
排序
List<Comment> taskComments = taskService.getTaskComments(historicTaskInstance.getId());
if(CollectionUtil.isNotEmpty(taskComments)){
actHistoryInfoVo.setCommentId(taskComments.get(0).getId());
String message = taskComments.stream()
.map(Comment::getFullMessage).collect(Collectors.joining("。"));
if (StringUtils.isNotBlank(message)) {
actHistoryInfoVo.setComment(message);
}
}
翻译
if (CollUtil.isNotEmpty(actHistoryInfoVoList)) {
List<Long> assigneeList = actHistoryInfoVoList.stream().map(e -> Long.valueOf(e.getAssignee())).collect(Collectors.toList());
if (CollUtil.isNotEmpty(assigneeList)) {
List<SysUser> sysUsers = iUserService.selectListUserByIds(assigneeList);
actHistoryInfoVoList.forEach(e -> {
sysUsers.stream().filter(u -> u.getUserId().toString().equals(e.getAssignee())).findFirst().ifPresent(u -> {
e.setNickName(u.getNickName());
});
});
}
}