【发布时间】:2012-01-02 23:14:47
【问题描述】:
假设我有一个foodGroupIds 的集合和一个food 的集合。使用 commons-collections,如何过滤掉不属于任何食物组的食物?
我可能在正确的轨道上,但无法弄清楚要使用什么谓词。也许必须创建我自己的?
Collection<Long> ids = collect(
findGoodFoodGroups(),
invokerTransformer("getId"));
Collection<Food> food = getAllFood();
filter(food, transformedPredicate(
invokerTransformer("getFoodGroupId"),
?));
在 C# 中是这样的:
var ids = FindGoodFoodGroups().Select(x => x.Id);
var goodFood = FindAllFood().Select(x => ids.Contains(x.FoodGroupId));
我想要所有属性P 类型为T 的对象等于集合C 中的任何T 类型为T 的对象。
【问题讨论】:
标签: java collections filtering apache-commons predicate