I have needed in several occasions some classes to represent and manipulate conditions (typically in a UI so the user builds a query by combining different condition types and then the code can transform that depending on the underlying system to be queried, for example lucene and a db). I searched all over for a reusable set of classes, I am sure this has to be used in many existing places (all the expression languages for starters) but could not find anything easily usable. I ended up coding both times myself, but felt bad about not reusing something I am sure exists.
Typical needs are: - several operators: and or etc - variable number of operands - combining conditions to build expressions - serializing of expressions - parsing/formatting of expressions from/to strings
has somebody found something like that?
It does sound like you might be looking for Functors (aka function objects). If so, this SO question would be relevant, wrt. choices: Commons functor (mentioned already) is one alternative but there are others too.
All functor libs come with the framework (which is quite simple; unary, binary predicates, mapping functionality for those, combining by chaining) and basic set of functions most commonly needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With