Abstraction for a rule that can be fired by a rules engine. Rules are registered in a namespace of rule of type Rules in which they must have a unique name. @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
| 32 | * @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com) |
| 33 | */ |
| 34 | public interface Rule extends Comparable<Rule> { |
| 35 | |
| 36 | /** |
| 37 | * Default rule name. |
| 38 | */ |
| 39 | String DEFAULT_NAME = "rule"; |
| 40 | |
| 41 | /** |
| 42 | * Default rule description. |
| 43 | */ |
| 44 | String DEFAULT_DESCRIPTION = "description"; |
| 45 | |
| 46 | /** |
| 47 | * Default rule priority. |
| 48 | */ |
| 49 | int DEFAULT_PRIORITY = Integer.MAX_VALUE - 1; |
| 50 | |
| 51 | /** |
| 52 | * Getter for rule name. |
| 53 | * @return the rule name |
| 54 | */ |
| 55 | default String getName() { |
| 56 | return DEFAULT_NAME; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Getter for rule description. |
| 61 | * @return rule description |
| 62 | */ |
| 63 | default String getDescription() { |
| 64 | return DEFAULT_DESCRIPTION; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Getter for rule priority. |
| 69 | * @return rule priority |
| 70 | */ |
| 71 | default int getPriority() { |
| 72 | return DEFAULT_PRIORITY; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * This method implements the rule's condition(s). |
| 77 | * <strong>Implementations should handle any runtime exception and return true/false accordingly</strong> |
| 78 | * |
| 79 | * @return true if the rule should be applied given the provided facts, false otherwise |
| 80 | */ |
| 81 | boolean evaluate(Facts facts); |
| 82 | |
| 83 | /** |
| 84 | * This method implements the rule's action(s). |
| 85 | * @throws Exception thrown if an exception occurs when performing action(s) |
| 86 | */ |
| 87 | void execute(Facts facts) throws Exception; |
| 88 | |
| 89 | } |
no outgoing calls
no test coverage detected