From 35b786509dbd1152177a085780912c7722c09f47 Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Sun, 21 May 2017 16:02:41 +0200 Subject: [PATCH] update javadoc --- .../main/java/org/jeasy/rules/api/Facts.java | 22 +++++++++ .../main/java/org/jeasy/rules/api/Rules.java | 42 +++++++++++++++++ .../java/org/jeasy/rules/core/RuleProxy.java | 5 ++ .../jeasy/rules/core/RulesEngineBuilder.java | 46 +++++++++++++++++++ .../main/java/org/jeasy/rules/core/Utils.java | 5 -- 5 files changed, 115 insertions(+), 5 deletions(-) diff --git a/easy-rules-core/src/main/java/org/jeasy/rules/api/Facts.java b/easy-rules-core/src/main/java/org/jeasy/rules/api/Facts.java index 723504d..5b28a6f 100644 --- a/easy-rules-core/src/main/java/org/jeasy/rules/api/Facts.java +++ b/easy-rules-core/src/main/java/org/jeasy/rules/api/Facts.java @@ -27,18 +27,40 @@ import java.util.*; import static java.lang.String.format; +/** + * Represents a set of named facts. Facts have unique name within a Facts object. + * + * @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com) + */ public class Facts implements Iterable> { private Map facts = new HashMap<>(); + /** + * Add a fact. + * + * @param name fact name + * @param fact object + */ public void add(String name, Object fact) { facts.put(name, fact); } + /** + * Remove fact. + * + * @param name of fact to remove + */ public void remove(String name) { facts.remove(name); } + /** + * Get a fact by name. + * + * @param name of fact to get. + * @return the fact having the given name, or null if there is no fact with the given name + */ public Object get(String name) { return facts.get(name); } diff --git a/easy-rules-core/src/main/java/org/jeasy/rules/api/Rules.java b/easy-rules-core/src/main/java/org/jeasy/rules/api/Rules.java index ed4ebdb..bca7307 100644 --- a/easy-rules-core/src/main/java/org/jeasy/rules/api/Rules.java +++ b/easy-rules-core/src/main/java/org/jeasy/rules/api/Rules.java @@ -30,36 +30,75 @@ import java.util.Iterator; import java.util.Set; import java.util.TreeSet; +/** + * This class encapsulates a set of rules and represents a rules namespace. + * Rules must have a unique name within a rules namespace. + * + * @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com) + */ public class Rules implements Iterable { private Set rules = new TreeSet<>(); + /** + * Create a new {@link Rules} object. + * + * @param rules to register + */ public Rules(Set rules) { this.rules = rules; } + /** + * Create a new {@link Rules} object. + * + * @param rules to register + */ public Rules(Rule... rules ) { Collections.addAll(this.rules, rules); } + /** + * Create a new {@link Rules} object. + * + * @param rules to register + */ public Rules(Object... rules ) { for (Object rule : rules) { this.register(RuleProxy.asRule(rule)); } } + /** + * Register a new rule. + * + * @param rule to register + */ public void register(Object rule) { rules.add(RuleProxy.asRule(rule)); } + /** + * Unregister a rule. + * + * @param rule to unregister + */ public void unregister(Object rule) { rules.remove(RuleProxy.asRule(rule)); } + /** + * Check if the rule set is empty. + * + * @return true if the rule set is empty, false otherwise + */ public boolean isEmpty() { return rules.isEmpty(); } + /** + * Clear rules. + */ public void clear() { rules.clear(); } @@ -69,6 +108,9 @@ public class Rules implements Iterable { return rules.iterator(); } + /** + * Sort rules. + */ public void sort() { rules = new TreeSet<>(rules); } diff --git a/easy-rules-core/src/main/java/org/jeasy/rules/core/RuleProxy.java b/easy-rules-core/src/main/java/org/jeasy/rules/core/RuleProxy.java index a743095..d2522b9 100644 --- a/easy-rules-core/src/main/java/org/jeasy/rules/core/RuleProxy.java +++ b/easy-rules-core/src/main/java/org/jeasy/rules/core/RuleProxy.java @@ -36,6 +36,11 @@ import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.*; +/** + * Main class to create rule proxies from annotated objects. + * + * @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com) + */ public class RuleProxy implements InvocationHandler { private Object target; diff --git a/easy-rules-core/src/main/java/org/jeasy/rules/core/RulesEngineBuilder.java b/easy-rules-core/src/main/java/org/jeasy/rules/core/RulesEngineBuilder.java index a698712..413ffd8 100644 --- a/easy-rules-core/src/main/java/org/jeasy/rules/core/RulesEngineBuilder.java +++ b/easy-rules-core/src/main/java/org/jeasy/rules/core/RulesEngineBuilder.java @@ -40,6 +40,11 @@ public class RulesEngineBuilder { private List ruleListeners; + /** + * Create a new rules engine builder. + * + * @return a new rules engine builder + */ public static RulesEngineBuilder aNewRulesEngine() { return new RulesEngineBuilder(); } @@ -55,36 +60,77 @@ public class RulesEngineBuilder { return this; } + /** + * Set the setSkipOnFirstAppliedRule parameter. + * + * @param skipOnFirstAppliedRule to set + * @return the rules engine builder + */ public RulesEngineBuilder withSkipOnFirstAppliedRule(final boolean skipOnFirstAppliedRule) { parameters.setSkipOnFirstAppliedRule(skipOnFirstAppliedRule); return this; } + /** + * Set the skipOnFirstNonTriggeredRule parameter. + * + * @param skipOnFirstNonTriggeredRule to set + * @return the rules engine builder + */ public RulesEngineBuilder withSkipOnFirstNonTriggeredRule(final boolean skipOnFirstNonTriggeredRule) { parameters.setSkipOnFirstNonTriggeredRule(skipOnFirstNonTriggeredRule); return this; } + /** + * Set skipOnFirstFailedRule parameter. + * + * @param skipOnFirstFailedRule to set + * @return the rules engine builder + */ public RulesEngineBuilder withSkipOnFirstFailedRule(final boolean skipOnFirstFailedRule) { parameters.setSkipOnFirstFailedRule(skipOnFirstFailedRule); return this; } + /** + * Set rule priority threshold. + * + * @param priorityThreshold to set + * @return the rules engine builder + */ public RulesEngineBuilder withRulePriorityThreshold(final int priorityThreshold) { parameters.setPriorityThreshold(priorityThreshold); return this; } + /** + * Register a rule listener. + * + * @param ruleListener to register + * @return the rules engine builder + */ public RulesEngineBuilder withRuleListener(final RuleListener ruleListener) { this.ruleListeners.add(ruleListener); return this; } + /** + * Set silent mode to mute all loggers. + * + * @param silentMode to set + * @return the rules engine builder + */ public RulesEngineBuilder withSilentMode(final boolean silentMode) { parameters.setSilentMode(silentMode); return this; } + /** + * Build a rules engine instance. + * + * @return a rules engine instance + */ public RulesEngine build() { return new DefaultRulesEngine(parameters, ruleListeners); } diff --git a/easy-rules-core/src/main/java/org/jeasy/rules/core/Utils.java b/easy-rules-core/src/main/java/org/jeasy/rules/core/Utils.java index dbe88b3..2aa6251 100644 --- a/easy-rules-core/src/main/java/org/jeasy/rules/core/Utils.java +++ b/easy-rules-core/src/main/java/org/jeasy/rules/core/Utils.java @@ -35,11 +35,6 @@ import java.util.logging.Logger; import static java.util.Arrays.asList; -/** - * Utilities class. - * - * @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com) - */ final class Utils { private static final Logger LOGGER = Logger.getLogger(Utils.class.getName());