Class ConditionalRuleGroup

  • All Implemented Interfaces:
    java.lang.Comparable<Rule>, Rule

    public class ConditionalRuleGroup
    extends CompositeRule
    A conditional rule group is a composite rule where the rule with the highest priority acts as a condition: if the rule with the highest priority evaluates to true, then we try to evaluate the rest of the rules and execute the ones that evaluate to true. This class is not thread-safe.
    • Constructor Detail

      • ConditionalRuleGroup

        public ConditionalRuleGroup()
        Create a conditional rule group.
      • ConditionalRuleGroup

        public ConditionalRuleGroup​(java.lang.String name)
        Create a conditional rule group.
        Parameters:
        name - of the conditional rule
      • ConditionalRuleGroup

        public ConditionalRuleGroup​(java.lang.String name,
                                    java.lang.String description)
        Create a conditional rule group.
        Parameters:
        name - of the conditional rule
        description - of the conditional rule
      • ConditionalRuleGroup

        public ConditionalRuleGroup​(java.lang.String name,
                                    java.lang.String description,
                                    int priority)
        Create a conditional rule group.
        Parameters:
        name - of the conditional rule
        description - of the conditional rule
        priority - of the composite rule
    • Method Detail

      • evaluate

        public boolean evaluate​(Facts facts)
        A conditional rule group will trigger all its composing rules if the condition of the rule with highest priority evaluates to true.
        Specified by:
        evaluate in interface Rule
        Specified by:
        evaluate in class CompositeRule
        Parameters:
        facts - The facts.
        Returns:
        true if the conditions of all composing rules evaluate to true
      • execute

        public void execute​(Facts facts)
                     throws java.lang.Exception
        When a conditional rule group is executed, all rules that evaluated to true are performed in their natural order, but with the conditional rule (the one with the highest priority) first.
        Specified by:
        execute in interface Rule
        Specified by:
        execute in class CompositeRule
        Parameters:
        facts - The facts.
        Throws:
        java.lang.Exception - thrown if an exception occurs during actions performing