Can you please explain why my Filtering is not working? (the filter is not done and the message is not printed out).
@Override
protected void fetchValueObjectsListPostSpecificAction() {
logger.info("~~~size:" + this.valueObjectsList.size());
// show only scenarios which have applications related defined
Collections2.filter(this.valueObjectsList, new Predicate<PlanScenarioVo>() {
@Override
public boolean apply(final PlanScenarioVo arg0) {
System.out.println("!!!!!!!!!!---FILTER");
return (StringUtils.isNotEmpty(arg0.getApplication().getInternalId()));
}
});
logger.info("~~~size POST:" + this.valueObjectsList.size());
}
At least I want to make sure that it gets into the apply method, but I do not see anything on output, only the size(6) and size POST(6).
~~~size:6
~~~size POST:6
Do you see something wrong with this method?
Thanks,
Collections2.filterreturns a filtered Collection, it does not modify the passed collections.EDIT
As JB Nizmet explains below,
Collections2.filteris a view over the original collection, you will see thePredicateevaluated only when you actually iterate over the result or access it.It will be useful for you to assign the result to a variable, print its size, and look at the stack trace in the predicate method inside a debugger.