在guava库中,自带了过滤器(filter)的功能,可以用来对list进行转换
/**
*@description
* 利用guava中集合filter 实现list的转换
*@date 2016年11月3日
*@author kevin
*@param entityList
*@return
* poList
*/
private List entityListToPoList(List entityList){
List dto_list = null;
if(entityList != null && !entityList.isEmpty()){
// 方式一
/*Function function = new Function() {
@Override
public StoryStyleDictionaryPo apply(StoryStyleDictionaryEntity input) {
StoryStyleDictionaryPo xbnAdminCompanyListDTO = new StoryStyleDictionaryPo();
//DTO内容copy制Bean对象中
BeanUtils.copyProperties(input,xbnAdminCompanyListDTO);
return xbnAdminCompanyListDTO;
}
};
Iterable transform = Iterables.transform(entityList, function);
dto_list = Lists.newArrayList(transform);*/
// // 方式二
dto_list = Lists.newArrayList(Iterables.transform(entityList,new Function() {
@Override
public StoryStyleDictionaryPo apply(
StoryStyleDictionaryEntity input) {
//创建Bean对象
StoryStyleDictionaryPo xbnAdminCompanyListDTO = new StoryStyleDictionaryPo();
//DTO内容copy制Bean对象中
BeanUtils.copyProperties(input,xbnAdminCompanyListDTO);
return xbnAdminCompanyListDTO;
}
}));
}
return dto_list;
}