|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.expasy.jpl.commons.base.cond.ConditionInterpreter<T>
public final class ConditionInterpreter<T>
ConditionInterpreter translates condition type expressions into
Condition. It helps building complex ConditionImpls.
Expressions are represented as an expression tree. [conditional] Expression trees represent code in a tree-like data structure, where each node is a expression over condition.
A complex conditional expression is an expression of simple condition operands (defined internally as variable (CVAR)) and classic unary (OR) and
binary operators (AND, OR). Here is the grammar below:
EXPR := COND | NOT? EXPR
COND := CVAR BOP COND
CVAR := \w+
BOP := AND | OR
NOT := '!'
AND := '&'
OR := '|'
Condition.
ConditionInterpreter<Double> interpreter =
ConditionInterpreter.newInstance();
engine.register("c1", new ConditionImpl.Builder<Double, Double>(0.)
.operator(OperatorGreaterThan.newInstance()).build());
engine.register("c2", new ConditionImpl.Builder<Double, Double>(10.)
.operator(OperatorLowerThan.newInstance()).build());
Condition<Double> condition = interpreter.translate("c1 & c2");
Assert.assertTrue(condition.evaluate(4.));
Assert.assertFalse(condition.evaluate(14.));
ConditionImpl| Method Summary | ||
|---|---|---|
Condition<T> |
getCondition(String name)
Get the condition given its name. |
|
String |
getNextConditionName()
|
|
int |
getNumOfCondition()
|
|
static
|
newInstance()
|
|
ConditionInterpreter<T> |
register(Condition<T> condition)
Add anonymous condition instance in the condition table. |
|
ConditionInterpreter<T> |
register(String condition)
Add anonymous condition. |
|
ConditionInterpreter<T> |
register(String conditionName,
Condition<T> condition)
Add a named condition in the condition table. |
|
ConditionInterpreter<T> |
register(String conditionName,
String condition)
|
|
void |
removeAllConditions()
Remove all conditions. |
|
Condition<T> |
removeCondition(String name)
Remove the condition. |
|
void |
traceInternalConditions()
Display the internal content of defined conditions variables. |
|
Condition<T> |
translate(String expression)
Parse expression and return a tree conditional expression. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static <T> ConditionInterpreter<T> newInstance()
public ConditionInterpreter<T> register(String conditionName,
Condition<T> condition)
conditionName - the condition name.condition - the condition instance.public ConditionInterpreter<T> register(Condition<T> condition)
Do not forget to get
condition - the condition instance.
public ConditionInterpreter<T> register(String conditionName,
String condition)
throws OperatorManager.InvalidOperatorException
OperatorManager.InvalidOperatorException
public ConditionInterpreter<T> register(String condition)
throws OperatorManager.InvalidOperatorException
condition - the string format condition.
OperatorManager.InvalidOperatorExceptionpublic String getNextConditionName()
public Condition<T> removeCondition(String name)
name - the condition name.
public void removeAllConditions()
public Condition<T> getCondition(String name)
name - the condition name.
public int getNumOfCondition()
public void traceInternalConditions()
public Condition<T> translate(String expression)
throws ParseException
translate in interface Interpreter<Condition<T>>expression - the expression to evaluate.
ParseException - if invalid expression.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||