转list
List<FunctionVO> functions = input.getFunctionInfos().stream().map(parse2FunctionGuideVO::apply).collect(Collectors.toList());
转map
Map<Integer, OrderPartnerVO> res = partnerProductMapping
.stream()
.collect(Collectors.toMap(
PartnerProductMapping::getPartnerCarTypeId,
t -> PartnerConvert.getOrderPartnerVO(t),
((oldValue, newValue) -> oldValue)
));
filter (使用Predicate)
List<PartnerCarType> carTypeList = cityPartnerInfo.getPartnerCarTypes()
.stream()
.filter(partnerCarTypeSupportForChannel())
.collect(Collectors.toList());
public Predicate<PartnerCarType> partnerCarTypeSupportForChannel() {
int channel = getChannelType();
return obj -> {
if (CollectionUtils.isEmpty(obj.getChannelTypes())) {
return true;
}
return obj.getChannelTypes().stream().anyMatch(s -> s.getChannelId() == channel);
completableFuture
public CompletableFuture<Boolean> appendFranchiseeInfo() {
return CompletableFuture.supplyAsync(() -> franchiseeRpcService.queryCompany(franchiseeId)).thenApply((franchiseeInfoDTO -> {
if (franchiseeInfoDTO == null) {
orderDriver.setFranchiseDriver(false);
return true;
}
orderDriver.setFranchiseDriver(true);
orderDriver.setFranchiseeInfo(new FranchiseeInfoVO(franchiseeInfoDTO.getLogoUrl(), franchiseeInfoDTO.getShortCompanyName()));
return true;
})).exceptionally(throwable -> {
if (throwable != null) {
UserVisitLogHelper.sendLog(LogTypeEnum.RPC_ERROR, "queryCompany", "xxxx");
}
return false;
});
}