Class RuleContext<K>

java.lang.Object
com.helixframework.rules.RuleContext<K>
Type Parameters:
K - root object type
All Implemented Interfaces:
Serializable

public class RuleContext<K> extends Object implements Serializable
Context object sent to all rules for evaluation.
See Also:
  • Constructor Details

    • RuleContext

      public RuleContext(K root)
      Creates a new instance of RuleContext.
      Parameters:
      root - root object
    • RuleContext

      public RuleContext(K root, Map<String,Object> variables)
      Creates a new instance of RuleContext.
      Parameters:
      root - root object
      variables - context variables
  • Method Details

    • addVariable

      public void addVariable(String name, Object value)
      Add a variable to the context variables.
      Parameters:
      name - variable name
      value - variable value
    • getVariable

      public <T> Optional<T> getVariable(String name, Class<T> objType)
      Gets the value of a context variable.
      Type Parameters:
      T - variable value type
      Parameters:
      name - variable name
      objType - variable value type
      Returns:
      variable value
    • getVariables

      public Map<String,Object> getVariables()
      Gets the context variables.
      Returns:
      context variables
    • addError

      public void addError(String rule, RuleException exception)
    • getErrors

      public Map<String,RuleException> 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:
      true if any errors occurred; otherwise false
    • hasErrors

      public boolean hasErrors(String ruleName)
      Checks if an error occurred for a specific rule during processing of the context.
      Parameters:
      ruleName - rule name
      Returns:
      true if any errors occurred; otherwise false
    • getRoot

      public K getRoot()
      Gets the root object.
      Returns:
      root object
    • setRoot

      public void setRoot(K root)
      Sets the root object.
      Parameters:
      root - root object
    • getRoot

      public <V> V getRoot(Class<V> rootType)
      Gets the root object and casts it to the supplied type.
      Type Parameters:
      V - root object type
      Parameters:
      rootType - root object
      Returns:
      root object