java - Is there a data structure for storing boolean expressions? -
i need store boolean expressions this:
x1 , x2 , x3 or (x4 , x5) , (not x6)
each x
variable boolean expression ==
or !=
values. problem store nested and
, or
clauses (inside and/or inside each other) , wrap them not
. wrapping depth can deep.
does java sdk have data structure these expressions?
in java 8 functional interface predicate<t>
way go.
here java docs.
and here various examples.
so in use case follows:
public static predicate<integer> equals(integer compare) { return -> i.equals(compare); } public static predicate<integer> complex() { return equals(1).and(equals(2)).and(equals(3)).or(equals(4).and(equals(5))).and(equals(6).negate()); }
remember — java 8 onwards!
Comments
Post a Comment