Class BasicRule

java.lang.Object
org.jeasy.rules.core.BasicRule
All Implemented Interfaces:
Comparable<Rule>, Rule

public abstract class BasicRule extends Object implements Rule
Basic rule implementation class that provides common methods.

You can extend this class and override evaluate(Facts) and execute(Facts) to provide rule conditions and actions logic.

Author:
Mahmoud Ben Hassine ([email protected])
  • Field Details

    • name

      protected String name
      Rule name.
    • description

      protected String description
      Rule description.
    • priority

      protected int priority
      Rule priority.
  • Constructor Details

    • BasicRule

      @Deprecated(since="1.0.1", forRemoval=true) protected BasicRule()
      Deprecated, for removal: This API element is subject to removal in a future version.
      To avoid hardcoded rule name, Rule name should be unique
      Create a new BasicRule. Please use other constructor method as name parameter uniquely identifies a rule
    • BasicRule

      protected BasicRule(String name)
      Create a new BasicRule.
      Parameters:
      name - rule name
    • BasicRule

      protected BasicRule(String name, String description)
      Create a new BasicRule.
      Parameters:
      name - rule name
      description - rule description
    • BasicRule

      protected BasicRule(String name, String description, int priority)
      Create a new BasicRule.
      Parameters:
      name - rule name
      description - rule description
      priority - rule priority
  • Method Details

    • evaluate

      public boolean evaluate(Facts facts)
      This method implements the rule's condition(s). Implementations should handle any runtime exception and return true/false accordingly
      Specified by:
      evaluate in interface Rule
      Returns:
      true if the rule should be applied given the provided facts, false otherwise
    • execute

      public void execute(Facts facts) throws Exception
      This method implements the rule's action(s).
      Specified by:
      execute in interface Rule
      Throws:
      Exception - thrown if an exception occurs when performing action(s)
    • getName

      public String getName()
      Description copied from interface: Rule
      Getter for rule name.
      Specified by:
      getName in interface Rule
      Returns:
      the rule name
    • getDescription

      public String getDescription()
      Description copied from interface: Rule
      Getter for rule description.
      Specified by:
      getDescription in interface Rule
      Returns:
      rule description
    • setDescription

      public void setDescription(String description)
    • getPriority

      public int getPriority()
      Description copied from interface: Rule
      Getter for rule priority.
      Specified by:
      getPriority in interface Rule
      Returns:
      rule priority
    • setPriority

      public void setPriority(int priority)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(Rule rule)
      Specified by:
      compareTo in interface Comparable<Rule>