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 String
description
Rule description.protected String
name
Rule name.protected int
priority
Rule priority.-
Fields inherited from interface org.jeasy.rules.api.Rule
DEFAULT_DESCRIPTION, DEFAULT_NAME, DEFAULT_PRIORITY
-
-
Constructor Summary
Constructors Modifier Constructor Description 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 uniqueprotected
BasicRule(String name)
Create a newBasicRule
.protected
BasicRule(String name, String description)
Create a newBasicRule
.protected
BasicRule(String name, String description, int priority)
Create a newBasicRule
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(Rule rule)
boolean
equals(Object o)
boolean
evaluate(Facts facts)
This method implements the rule's condition(s).void
execute(Facts facts)
This method implements the rule's action(s).String
getDescription()
Getter for rule description.String
getName()
Getter for rule name.int
getPriority()
Getter for rule priority.int
hashCode()
void
setDescription(String description)
void
setPriority(int priority)
String
toString()
-
-
-
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:Rule
Getter for rule description.- Specified by:
getDescription
in interfaceRule
- 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 interfaceRule
- Returns:
- rule priority
-
setPriority
public void setPriority(int priority)
-
compareTo
public int compareTo(Rule rule)
- Specified by:
compareTo
in interfaceComparable<Rule>
-
-