lambda用法示例

//情形1

Set<String> pickBillNos = zonePickBills.stream().map(ZonePickBill::getPickBillNo).collect(Collectors.toSet());

 

//情形2

String msg = areaNotSetLogicList.stream().map(SimpleWarehouseAreaDto::getAreaCode).limit(3).collect(Collectors.joining(","));

 

//情形3

Map<String, DeliveryPickInfo> deliveryPickInfoMap = 

deliveryPickInfos.stream().collect(Collectors.toMap(DeliveryPickInfo::getPickBillNo, deliveryPickInfo -> deliveryPickInfo));

Map<String, DeliveryPickInfo> deliveryPickInfoMap = 

deliveryPickInfos.stream().collect(Collectors.toMap(DeliveryPickInfo::getPickBillNo, Function.identity()));

Map<Long, Integer> regionIdPriorityLevelMap =

        deliveryRegions.stream().collect(Collectors.toMap(DeliveryRegionResultDto::getRegionId,

                n -> Optional.ofNullable(n.getPriorityLevel()).orElse(0), (key1, key2) -> key1));

 

//情形4

List<WarehouseGrayRecordResDto> recordResDtos;

Map<Long,List<WarehouseGrayRecordResDto>> map =

recordResDtos.stream().collect(Collectors.groupingBy(WarehouseGrayRecordResDto::getWarehouseId));

 

//情形5-1

Map<String, List<String>> map = deliveryInfoForPrintDtos.stream().collect(Collectors.groupingBy(DeliveryInfoForPrintDto::getRouteNo,

        Collectors.mapping(dto -> {

            String billno = dto.getOutBoundBillNo();

            // 将出库单号添加到集合中

            outboundNoList.add(billno); //返回map时同时提取所有的单号(其他地方需要)

            return billno;

        }, Collectors.toCollection(ArrayList::new))));

//情形5-2

Map<Integer, Set<String>> skuAreaCodeMap = pickBillDetailDtoList.stream()

        .collect(Collectors.groupingBy(PickBillDetailDto::getOriginSkuCode,

                Collectors.mapping(PickBillDetail::getAreaCode, Collectors.toSet())));

 

//情形6

List<String> areaCodeNotSetPickPolicyList = areaCodeList.stream().filter(e -> !areaCodeHavePolicySet.contains(e)).collect(Collectors.toList());

 

//情形7

List<HainaOutboundBillDto> sortOutboundDetailList = Lists.newArrayList();

List<HainaOutboundBillDetailDto> list = sortOutboundDetailList.stream().map(HainaOutboundBillDto::getDetailList)

        .flatMap(Collection::stream).collect(Collectors.toList());

 

//情形8

List<PickBill> billList;

Map<OutboundTypeEnum, List<PickBill>> = billList.stream().collect(Collectors.groupingBy(bill -> {

    if (isOrder(bill.getPickBillNo())) {

        return OutboundTypeEnum.ORDER_OUTBOUND;

    } else if (isSupplyReturn(bill.getPickBillNo())) {

        return OutboundTypeEnum.RETURN_OUTBOUND;

    } else {

        return OutboundTypeEnum.ALLOT_OUTBOUND;

    }

}));

 

//情形8

List<PickBillDetail> detailList;

Map<String, Set<String>> pickOutboundMap =

        detailList.stream().collect(Collectors.groupingBy(PickBillDetail::getPickBillNo,

                Collectors.mapping(PickBillDetail::getOutboundBillNo, Collectors.toSet())));

 

//情形9

int orderSkuTotalQty = pickBillDetailList.stream().map(PickBillDetailDto::getOriginSkuCode).distinct().count();

int orderUnitTotalQty = pickBillDetailList.stream().mapToInt(PickBillDetailDto::getOriginSkuQty).sum();

List<DeliveryRouteDetailInfoVo> deliveries = new ArrayList<>(orderNoList.size());

BigDecimal sumWeight = deliveries.stream().map(DeliveryRouteDetailInfoVo::getWeight).reduce(BigDecimal.ZERO, BigDecimal::add);

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值