• 使用Lambda转换集合数据至新集合


    1. 测试
    public static void main(String[] args) {
    	// 将 pojoList 转换至 dtoList 中
    	List<Student01> dtoList = new ArrayList<>();
    	List<Student01> pojoList = new ArrayList<>();
    	Collections.addAll(pojoList, new Student01(1, "靳露"), new Student01(2, "于瑶"), new Student01(4, "王莹"));
    
    	buildDtoList(pojoList).forEach(args1 -> dtoList.add(args1));
    	dtoList.forEach(args2 -> System.out.print(JSON.toJSON(args2) + " - ".substring(0,1)));
    	// TODO: {"name":"靳露","id":1} {"name":"于瑶","id":2} {"name":"王莹","id":4} 
    }
    
    1. 方法
    static List<Student01> buildDtoList(List<Student01> stuList) {
    	return stuList.stream().map(aItem -> {
    		Student01 student01 = new Student01();
    		student01.setId(aItem.getId());
    		student01.setName(aItem.getName());
    		return student01;
    	}).collect(Collectors.toList());
    }
    

    1. 对象转对象示例
    private RcvSubmitParamBo buildRcvSubmitBoParam(BaseRequest<SubmitRcvParamDto> request) {
            RcvSubmitParamBo rcvSubmitParamBo = new RcvSubmitParamBo();
            rcvSubmitParamBo.setAsnNo(request.getData().getAsnNo());
            rcvSubmitParamBo.setWarehouseId(request.getData().getWarehouseId());
            rcvSubmitParamBo.setOperator(request.getPin());
            rcvSubmitParamBo.setTenantId(request.getTenantId());
            rcvSubmitParamBo.setSubmitRcvSkuBos(request.getData().getSubmitRcvSkuDtos().stream().map(aItem -> {
            SubmitRcvSkuBo submitRcvSkuBo = new SubmitRcvSkuBo();
            submitRcvSkuBo.setExpireDate(aItem.getExpireDate());
            submitRcvSkuBo.setLocId(aItem.getLocId());
            submitRcvSkuBo.setProduceDate(aItem.getProduceDate());
            submitRcvSkuBo.setQty(aItem.getQty());
            submitRcvSkuBo.setSkuId(aItem.getSkuId());
            submitRcvSkuBo.setSkuNature(aItem.getSkuNature());
            submitRcvSkuBo.setSkuType(aItem.getSkuType());
            return submitRcvSkuBo;
        }).collect(Collectors.toList()));
    
        return rcvSubmitParamBo;
    }
    

    1. 集合转集合示例
    private List<RcvStockInfoSo> asnDetail2RcvStockSo(List<AsnDetailDTO> asnDetailList) {
           return asnDetailList.stream().map(aItem -> {
              RcvStockInfoSo rcvStockInfoSo = new RcvStockInfoSo();
    
              rcvStockInfoSo.setAsnHeaderNo(aItem.getAsnHeaderNo());
              rcvStockInfoSo.setAsnRefNo(aItem.getAsnRefNo());
              rcvStockInfoSo.setCreateDate(aItem.getCreateDate());
              rcvStockInfoSo.setActualQty(aItem.getActualQty());
              rcvStockInfoSo.setExpectedQty(aItem.getExpectedQty());
              rcvStockInfoSo.setExtSkuId(aItem.getExtSkuId());
              rcvStockInfoSo.setLineStatus(aItem.getLineStatus());
              rcvStockInfoSo.setPurchasePrice(aItem.getPurchasePrice());
              rcvStockInfoSo.setSaleMode(aItem.getSaleMode());
              rcvStockInfoSo.setSaleUnit(aItem.getSaleUnit());
              rcvStockInfoSo.setShelfLife(aItem.getShelfLife());
              rcvStockInfoSo.setSkuId(aItem.getSkuId());
              rcvStockInfoSo.setSkuModelNo(aItem.getSkuModelNo());
              rcvStockInfoSo.setSkuName(aItem.getSkuName());
              rcvStockInfoSo.setSkuOrderNo(aItem.getSkuOrderNo());
              rcvStockInfoSo.setSkuType(aItem.getSkuType());
              rcvStockInfoSo.setTenantId(aItem.getTenantId());
              rcvStockInfoSo.setUom(aItem.getUom());
              rcvStockInfoSo.setUpcCodes(aItem.getUpcCodes());
              rcvStockInfoSo.setWarehouseId(aItem.getWarehouseId());
    
              return rcvStockInfoSo;
          }).collect(Collectors.toList());
      }
    
  • 相关阅读:
    自制操作系统Antz(11)——实现shell(下)命令响应
    自制操作系统Antz(10)——实现shell(上)
    利用Android-FingerprintManager类实现指纹识别
    C语言解析WAV音频文件
    自制病毒——控制桌面鼠标以及开关机
    Linux内核源码分析 day01——内存寻址
    后端必备的Linux知识
    Java基础面试题总结
    自制操作系统Antz(9)——实现内核 (下) 实现图形化界面
    自制操作系统Antz(8)——实现内核 (中) 扩展内核
  • 原文地址:https://www.cnblogs.com/Twittery/p/14844071.html
Copyright © 2020-2023  润新知