0

Whats the best practice for defining filters to apply to a collection of objects within a spring context file?


Say I have a Collection of Persons (Collection<Person> people). Each person has age/name/sex/occupation/email properties.

I need to create subgroups of these people, based on some standard & simple predicates. Example groupings may be:

  1. sex=Male
  2. sex=Female && age>30 && occupation=IT
  3. sex=Male && occupation=IT && email endsWith "aol.com"

I can see a relatively straight forward route to doing this with Guava Predicates & Collections2.filter() by defining Predicate(s) in code, pulling them into collections in context file end injecting appropriate collection of Predicates where needed.

JFilter is a possible contender too, as you can define filters as Strings. LambdaJ seems to be the other popular option for filtering Collections in Java, but not obvious how to allow filtering logic to be driven from a Spring Context.


Is there a better way to go about this?

Note, I want to a avoid call to database each time, as I already have the collection of objects I care about in memory.

MdSalih
  • 1,978
  • 10
  • 16
  • Do you mean these are currently being stored in the database tables? Or you want to use some other storage for this stuff to avoid databases. – Swapnil Jan 12 '13 at 16:44
  • So the objects I want to filter are held in a Collection of objects, not in a database. – MdSalih Jan 12 '13 at 17:03
  • Ok, but what do you mean by "better" here (as you already know about a couple of ways to do it) – Swapnil Jan 12 '13 at 17:09
  • Question I had was if there's a better/standard way of doing this that I've missed in my google-ing - I've edited the title to better reflect this. – MdSalih Jan 12 '13 at 17:15

0 Answers0