Package com.helixframework.rules
Class RuleContext<K>
java.lang.Object
com.helixframework.rules.RuleContext<K>
- Type Parameters:
K- root object type
- All Implemented Interfaces:
Serializable
Context object sent to all rules for evaluation.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionRuleContext(K root) Creates a new instance ofRuleContext.RuleContext(K root, Map<String, Object> variables) Creates a new instance ofRuleContext. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddError(String rule, RuleException exception) voidaddVariable(String name, Object value) Add a variable to the context variables.Gets any errors that occurred during rule processing.getRoot()Gets the root object.<V> VGets the root object and casts it to the supplied type.<T> Optional<T>getVariable(String name, Class<T> objType) Gets the value of a context variable.Gets the context variables.booleanChecks if any errors occurred during processing of the context.booleanChecks if an error occurred for a specific rule during processing of the context.voidSets the root object.
-
Constructor Details
-
RuleContext
Creates a new instance ofRuleContext.- Parameters:
root- root object
-
RuleContext
Creates a new instance ofRuleContext.- Parameters:
root- root objectvariables- context variables
-
-
Method Details
-
addVariable
Add a variable to the context variables.- Parameters:
name- variable namevalue- variable value
-
getVariable
Gets the value of a context variable.- Type Parameters:
T- variable value type- Parameters:
name- variable nameobjType- variable value type- Returns:
- variable value
-
getVariables
Gets the context variables.- Returns:
- context variables
-
addError
-
getErrors
Gets any errors that occurred during rule processing.- Returns:
- rule errors
-
hasErrors
public boolean hasErrors()Checks if any errors occurred during processing of the context.- Returns:
trueif any errors occurred; otherwisefalse
-
hasErrors
Checks if an error occurred for a specific rule during processing of the context.- Parameters:
ruleName- rule name- Returns:
trueif any errors occurred; otherwisefalse
-
getRoot
Gets the root object.- Returns:
- root object
-
setRoot
Sets the root object.- Parameters:
root- root object
-
getRoot
Gets the root object and casts it to the supplied type.- Type Parameters:
V- root object type- Parameters:
rootType- root object- Returns:
- root object
-