I’m looking for a solution to represent boolean algebra.
Let’s say I have a lot of String objects that I’m displaying to the user. He can now multi-select them (make an && AND connection between them), and also make || OR connections. The final expression should also be shown to the user.
So, eg if he selects String1, String2, String3 I want to present String1 && String2 && String3. And maybe lateron the user should be able to build expressions like (String1 || String 2) && String 3.
My question is: how could I track reference on these boolean selections between the string objects?
Of course I could just create a String expression; and always append what he selected. But what if he deselects an object? Then I would have to parse the whole string an revaluate it.
I’m searching for something to keep a AND/OR reference between the objects and then having a method to build the String final expression based on these.
Any ideas are welcome!
It sounds like you just need a tree structure. Every inner node represents an operator (
&&,||, etc.), and every leaf node represents a term.See also: abstract syntax tree