I have a list of conditions which contains
pair<And, a>, <Or, b>, <And, c>, <Or, d>, <And, e>, <And,f>.
I would like to create one condition from it where all are just next to each other on same level without any parentheses.
So:
a OR b AND c OR d AND e AND f.
The list can contain any number of conditions with mixed operators(And, Or).
Currently if I chain it together in Jooq it generates (a OR b) and c.. etc which is not what I want.
This is a fun algorithm. Your list is like a sequence of tokens, similar to what a parser would encounter. You could implement something like a recursive descent parser, similar to jOOQ's own parser. This would make sense if you add more operands to your stream, e.g.
Notor arithmetic operators, as well as the possibility of nesting operations, etc.With only two types of operators, it's probably simpler to just loop over your list like this. Assuming these auxiliary types:
Write this:
This then prints: