Recipe 0.7. Creating a conditional expression
Problem
You want to create a conditional expression from other conditions.
Solution
Here is an example of code to define conditional expression:
// an engine handles expression building ConditionInterpreter<Double> engine = ConditionInterpreter.newInstance(); // the engine has an internal symbol table that map a symbol name with // a condition // creation and registering of the condition "c1" engine.addCondition("c1", new ConditionImpl.Builder<Double, Double>(0.).operator(OperatorGreaterThan.newInstance()).build()); // creation and registering of the condition "c2" engine.addCondition("c2", new ConditionImpl.Builder<Double, Double>(10.).operator(OperatorLowerThan.newInstance()).build()); // creation of a complex condition over "c1" and "c2" Condition<Double> condition = engine.compile("c1 & c2"); // test the new conditional expression Assert.assertTrue(condition.isTrue(4.)); Assert.assertFalse(condition.isTrue(14.));
Discussion
See Also
See also this link to conditions.