use of org.knime.base.node.rules.engine.Rule.GenericRule in project knime-core by knime.
the class SimpleRuleParser method parse.
/**
* Parses a whole {@link Rule}.
*
* @param rule A line representing a rule (possibly comment).
* @param booleanOutcome Should the rule include only a boolean outcome ({@code true}), or it cannot ({@code false}
* ), or it can be either boolean or non-boolean ({@code null})?
* @return The parsed {@link Rule}.
* @throws ParseException Problem during parsing.
*/
public Rule parse(final String rule, final Boolean booleanOutcome) throws ParseException {
if (RuleSupport.isComment(rule)) {
return new GenericRule(rule, new Condition.Comment(rule), NoOutcome.getInstance());
}
final ParseState state = new ParseState(rule);
final Condition condition = parseCondition(state);
if (!state.isEnd()) {
final Outcome outcome = parseOutcome(state, booleanOutcome);
return new GenericRule(rule, condition, outcome);
}
throw new ParseException("No outcome specified.", state.getPosition());
}
use of org.knime.base.node.rules.engine.Rule.GenericRule in project knime-core by knime.
the class StreamingUtil method checkExpressions.
private static boolean checkExpressions(final Rule rule, final Predicate<Expression> check) {
if (!rule.getCondition().isEnabled()) {
// comment
return true;
}
if (rule instanceof GenericRule) {
final GenericRule gr = (GenericRule) rule;
final Condition condition = gr.getCondition();
if (condition instanceof GenericCondition) {
final GenericCondition gc = (GenericCondition) condition;
final Expression ce = gc.getExpression();
final Outcome outcome = gr.getOutcome();
if (outcome instanceof GenericOutcome) {
final GenericOutcome go = (GenericOutcome) outcome;
final Expression oe = go.getExpression();
return check.test(oe) && check.test(ce);
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
Aggregations