guava集合类的使用

1.  List<PromotionXaAttrDto> packXaList = promotionService.promXaAttrQuery(promtionDto.getId());
        if(CollectionUtils.isNotEmpty(packXaList)) {

            //如果没符合添加,Collections2.filter返回的集合的是空集合([]),而不是null

            promSpecialXaList.addAll(Collections2.filter(packXaList, new Predicate<PromotionXaAttrDto>(){
                @Override
                public boolean apply(PromotionXaAttrDto promXaAttrDto) {
                    return !PromAttr.contains(promXaAttrDto.getxAttribName());
                }
            }));
        }

2.过滤+转换集合

    public List<Map<String, String>> getDismantalPackageList(final String partNum, final EmployeeDto employeeDto){
        List<DictionaryDo> dicDoList = dictionaryService.getDictionaryByType(DISMANTLE_PACKAGES_SEL_TYPE);
        Predicate<DictionaryDo> predicate = new Predicate<DictionaryDo>() {  
            @Override  
            public boolean apply(DictionaryDo dicDo) {
                PromotionEltsDto promotionEltsDto= searchPromotionService.queryPackageByRowId(dicDo.getValue(), employeeDto);
                if(promotionEltsDto == null) return false;
                String partNums = dicDo.getValueType();
                return StringUtils.isBlank(partNums) || partNums.indexOf(partNum)!=-1;  
            }  
        };  
        Function<DictionaryDo, Map<String,String>> func = new Function<DictionaryDo,Map<String,String>>(){  
            @Override  
            public Map<String,String> apply(DictionaryDo dicDo) {  
                Map<String,String> map = Maps.newHashMap();
                map.put("name", dicDo.getValueName());
                map.put("promId", dicDo.getValue());
                return map;  
            }  
        };
        return  FluentIterable.from(dicDoList)  
                .filter(predicate)  
                .transform(func)  
                .toList();  
    }

你可能感兴趣的:(guava集合类的使用)