首页 > 其他 > 详细

guava集合类的使用

时间:2015-03-25 06:44:18      阅读:130      评论:0      收藏:0      [点我收藏+]

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集合类的使用

原文:http://my.oschina.net/u/2303045/blog/391081

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!