中外运-向上下递归,重写equals,正则匹配。

/**
     * 向上查询所有上级   递归
     * @param deptAll 所有集合
     * @param leafNodeDept 叶子节点
     */
    public static List<ProductClassIficationDTO> getDeptUpList(List<ProductClassIficationDTO> deptAll,ProductClassIficationDTO leafNodeDept){
        if(ObjectUtil.isNotEmpty(leafNodeDept)){
            List<ProductClassIficationDTO> set = new ArrayList<>();
            String parentId = leafNodeDept.getParentGid();
            List<ProductClassIficationDTO> parentDepts = deptAll.stream().filter(item -> item.getId().equals(parentId)).collect(Collectors.toList());
            if(CollectionUtil.isNotEmpty(parentDepts)){
                ProductClassIficationDTO parentDept = parentDepts.get(0);
                set.add(parentDept);
                List<ProductClassIficationDTO> deptUpTree = getDeptUpList(deptAll, parentDept);
                if(deptUpTree!=null){
                    set.addAll(deptUpTree);
                }
                return set;
            }
        }
        return null;
    }
    /**
     * 向下查询所有下级  递归
     * @param treeList 所有集合
     * @param id 父节点
     */
    public static List<ProductClassIficationDTO> buildTreeUseList(List<ProductClassIficationDTO> treeList,String id) {
        //收集传递的集合中父id相同的TreeNode
        List<ProductClassIficationDTO> children = new ArrayList<>();
        for (ProductClassIficationDTO treeNode : treeList) {
            //判断该节点的父id,是否与传入的父id相同,相同则递归设置其孩子节点,并将该节点放入children集合中
            if (treeNode.getParentGid().equals(id)) {
                //递归设置其孩子节点
                treeNode.setChildren(buildTreeUseList(treeList, treeNode.getId()));
                //放入children集合
                children.add(treeNode);
            }
        }
        return children;
    }

重写equals

 @Override
    public boolean equals(Object obj) {
        if(this == obj){
            return true;
        }
        if(obj == null && getClass() != obj.getClass()){
            return false;
        }
        ProductClassIficationDTO productClassIficationDTO = (ProductClassIficationDTO) obj;
        //当type、color 内容都相等的时候,才返回true
        return Objects.equals(classificationCode,productClassIficationDTO.getClassificationCode()) && Objects.equals(description,productClassIficationDTO.getDescription());
    }

正则匹配

 String regExp = "(\\w+)";
            Pattern pattern=Pattern.compile(regExp);
            Matcher matcher=pattern.matcher(productClassIficationParam.getKeyword());
            while(matcher.find()) {
                fenci.add(matcher.group(0));
                productClassIficationParam.setKeyword(matcher.group(0).toUpperCase());
                //  false:组装树数据
                List<ProductClassIficationDTO> productClassIficationDTOS = getProductClassIficationDTOS(productClassIficationParam,false);
                list.addAll(productClassIficationDTOS);
            }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值