默认自用
取一列
List<String> rList = rResults.stream().map(RResult::getRs).collect(Collectors.toList());
取多列组map,注意summingLong(是个Collector)
Map<Long, Long> taskQty = lockResults.stream()
.filter(l -> l.getOwner() == LockOwnerEnum.SPECIFIED_OUTBOUND)
.collect(groupingBy(InvLockResult::getValue, summingLong(InvLockResult::getCount)));
分组
Map<Integer, List<AData>> groupByTransferFlag = aDataList.stream()
.collect(Collectors.groupingBy(AData::getTransferFlag));
统计个数
aDataList.stream().map(AData::getCode).distinct().count()
List<HashMap<String, Object>> collect = list.stream().map(e -> {
HashMap<String, Object> info = Maps.newHashMap();
info.put("index", e.getIndex());
info.put("code", e.getCode());
info.put("qty", e.getMaxBoxQty() - e.getSurplusBoxQty());
return info;
}).collect(Collectors.toList());
list.addAll(manualPlans.stream()
.map(manualPlan -> {
CombineInfo combineInfo = new CombineInfo();
combineInfo.setCombinedType(1);
combineInfo.setTrayNum(manualPlan.getMaxPalletQty()+":"+manualPlan.getRecommendPalletQty());
combineInfo.setTimes(String.format("%s/%s", manualPlan.getStartTime().format(FMT_YMDHMS),
manualPlan.getEndTime().format(FMT_YMDHMS)));
return combineInfo;
}).collect(Collectors.toList()));
Map<String, String> switches = sendSwitches
.stream()
.map(paramKey -> Pair.of(paramKey, configManager.queryByParamKey(paramKey)))
.collect(Collectors.toMap(Pair::getKey, paramValue ->
"0".equals(paramValue.getValue()) ? "开启" : "关闭")
);
max
tasks.stream().max(Comparator.comparing(Task::getCreateTime)).orElse(null);
map
Set<String> sList = initBO.getSpecs().stream().map(Spec::getCode).collect(Collectors.toSet());
allMatch
boolean noTask = cesults.stream().allMatch(c -> TypeEnum.isVirtual(c.getCode()));
Optional
Optional.ofNullable(caskBOList).orElse(List.of()).stream()
.filter(task -> Objects.nonNull(task.getNo()))
.findFirst().orElse(null);
flatmap
List<String> pList = cList.stream()
.flatMap(c -> c.getSList().stream().map(CSResult::getSCode))
.distinct()
.collect(toList());
组装新对象
cancelAssignedResults.stream() .filter(r -> r.getTaskNo() != 0) .collect(groupingBy(PsBoxCancelAssignedResult::getTaskNo)) .forEach((key, value) -> psDepalletizeTaskService.decreaseTaskActualQty(key, value.size()));
计算
info.values().stream().mapToInt(Integer::intValue).sum();