I have this case where I am filtering list into multiple lists based on criteria.
for(SomeObj someObj : someObjs) {
if(StringUtils.equalsIgnoreCase(someObj.getIndicator(), "Y")) {
beansWithY.add(someObj);
} else if(StringUtils.equalsIgnoreCase(someObj.getIndicator(), "N")) {
beansWithN.add(someObj);
} else {
beansWithIndNotValid.add(someObj);
}
}
This looks simple enough, but, I am wondering if this is possible using Lambdaj.
I came across grouping and it can be used like the following, but, it doesn't seem to cover the default scenario.
Group<SomeObj> group = group(listOfSomeObjs, by(on(SomeObj.class).getIndicator()));
After this the result will be the following:
Y group
N group
null group
a group for each and every invalid indicator ( like A, B, C...)
I am wondering if this can be made to work like the for loop mentioned above, if it is Y - go to a list/group, N - go to another list/group, everything else to one group.