public class Rule<T> extends AbstractRule<T>
Operator) for numeric and boolean values. rules can reference other rules
through using '§' + name.
every rule defines parameters and an operation. the parameters will be checked against the arguments given on
#execute(Map). additionally, there may be constraints for value ranges. Example:
rule = new Rule<BigDecimal>("test", "A ? (x1 + 1) : (x2 * 2)", MapUtil.asMap("A",
ParType.BOOLEAN,
"x1",
ParType.NUMBER,
"x2",
ParType.NUMBER));
rule.addConstraint("x1", new Constraint(BigDecimal.class, new BigDecimal(0), new BigDecimal(1)));
BigDecimal r2 = rule.execute(MapUtil.asMap("A", false, "x1", new BigDecimal(1), "x2", new BigDecimal(2)));
or
Rule ruleWithImport = new Rule("test-import", "A ? 1 + §test : (x2 * 3)", MapUtil.asMap("A",
Boolean.class,
"x1",
BigDecimal.class,
"x2",
BigDecimal.class));
| Modifier and Type | Field and Description |
|---|---|
static String |
KEY_RESULT |
initialized, PREFIXconstraints, name, operation, operationContent, parameter, specifications| Constructor and Description |
|---|
Rule()
constructor only to be used by deserializing
|
Rule(String name,
String operation,
LinkedHashMap<String,ParType> parameter)
constructor
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
initDeserializing() |
T |
run(Map<String,Object> arguments,
Object... extArgs)
executes the given rule, checking the given arguments.
|
importSubRules, prefixaddConstraint, addSpecification, addSpecification, asSequence, checkConstraint, checkedArguments, checkSpecification, createConstraints, createParameters, createSimpleParameters, getName, getOperation, getParameter, getParameterList, markArgumentsAsSequence, parameters, setOperation, toStringpublic static final String KEY_RESULT
public Rule()
public Rule(String name, String operation, LinkedHashMap<String,ParType> parameter)
operation - parameter - public T run(Map<String,Object> arguments, Object... extArgs)
arguments - rule inputprotected void initDeserializing()
initDeserializing in class AbstractRunnable<T>Copyright © 2012–2018. All rights reserved.