Package org.jeasy.rules.core
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)andexecute(Facts)to provide rule conditions and actions logic.- Author:
- Mahmoud Ben Hassine ([email protected])
-
-
Field Summary
Fields Modifier and Type Field Description protected StringdescriptionRule description.protected StringnameRule name.protected intpriorityRule priority.-
Fields inherited from interface org.jeasy.rules.api.Rule
DEFAULT_DESCRIPTION, DEFAULT_NAME, DEFAULT_PRIORITY
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBasicRule()Deprecated, for removal: This API element is subject to removal in a future version.To avoid hardcoded rule name, Rule name should be uniqueprotectedBasicRule(String name)Create a newBasicRule.protectedBasicRule(String name, String description)Create a newBasicRule.protectedBasicRule(String name, String description, int priority)Create a newBasicRule.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Rule rule)booleanequals(Object o)booleanevaluate(Facts facts)This method implements the rule's condition(s).voidexecute(Facts facts)This method implements the rule's action(s).StringgetDescription()Getter for rule description.StringgetName()Getter for rule name.intgetPriority()Getter for rule priority.inthashCode()voidsetDescription(String description)voidsetPriority(int priority)StringtoString()
-
-
-
Constructor Detail
-
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 uniqueCreate a newBasicRule. Please use other constructor method as name parameter uniquely identifies a rule
-
BasicRule
protected BasicRule(String name, String description)
Create a newBasicRule.- Parameters:
name- rule namedescription- rule description
-
-
Method Detail
-
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
-
execute
public void execute(Facts facts) throws Exception
This method implements the rule's action(s).
-
getDescription
public String getDescription()
Description copied from interface:RuleGetter for rule description.- Specified by:
getDescriptionin interfaceRule- Returns:
- rule description
-
setDescription
public void setDescription(String description)
-
getPriority
public int getPriority()
Description copied from interface:RuleGetter for rule priority.- Specified by:
getPriorityin interfaceRule- Returns:
- rule priority
-
setPriority
public void setPriority(int priority)
-
compareTo
public int compareTo(Rule rule)
- Specified by:
compareToin interfaceComparable<Rule>
-
-