在guava库中,自带了过滤器(filter)的功能,可以用来对list进行转换
/**
*@description
* 利用guava中集合filter 实现list的转换
*@date 2016年11月3日
*@author kevin
*@param entityList
*@return
* poList
*/
private List<StoryStyleDictionaryPo> entityListToPoList(List<StoryStyleDictionaryEntity> entityList){
List<StoryStyleDictionaryPo> dto_list = null;
if(entityList != null && !entityList.isEmpty()){
// 方式一
/*Function<StoryStyleDictionaryEntity, StoryStyleDictionaryPo> function = new Function<StoryStyleDictionaryEntity, StoryStyleDictionaryPo>() {
@Override
public StoryStyleDictionaryPo apply(StoryStyleDictionaryEntity input) {
StoryStyleDictionaryPo xbnAdminCompanyListDTO = new StoryStyleDictionaryPo();
//DTO内容copy制Bean对象中
BeanUtils.copyProperties(input,xbnAdminCompanyListDTO);
return xbnAdminCompanyListDTO;
}
};
Iterable<StoryStyleDictionaryPo> transform = Iterables.transform(entityList, function);
dto_list = Lists.newArrayList(transform);*/
// // 方式二
dto_list = Lists.newArrayList(Iterables.transform(entityList,new Function<StoryStyleDictionaryEntity, StoryStyleDictionaryPo>() {
@Override
public StoryStyleDictionaryPo apply(
StoryStyleDictionaryEntity input) {
//创建Bean对象
StoryStyleDictionaryPo xbnAdminCompanyListDTO = new StoryStyleDictionaryPo();
//DTO内容copy制Bean对象中
BeanUtils.copyProperties(input,xbnAdminCompanyListDTO);
return xbnAdminCompanyListDTO;
}
}));
}
return dto_list;
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。