update javadoc

pull/94/head
Mahmoud Ben Hassine 8 years ago
parent ba72b7fd41
commit 35b786509d

@ -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 <code>Facts</code> object.
*
* @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
*/
public class Facts implements Iterable<Map.Entry<String, Object>> {
private Map<String, Object> 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);
}

@ -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<Rule> {
private Set<Rule> rules = new TreeSet<>();
/**
* Create a new {@link Rules} object.
*
* @param rules to register
*/
public Rules(Set<Rule> 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<Rule> {
return rules.iterator();
}
/**
* Sort rules.
*/
public void sort() {
rules = new TreeSet<>(rules);
}

@ -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;

@ -40,6 +40,11 @@ public class RulesEngineBuilder {
private List<RuleListener> 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 <code>setSkipOnFirstAppliedRule</code> parameter.
*
* @param skipOnFirstAppliedRule to set
* @return the rules engine builder
*/
public RulesEngineBuilder withSkipOnFirstAppliedRule(final boolean skipOnFirstAppliedRule) {
parameters.setSkipOnFirstAppliedRule(skipOnFirstAppliedRule);
return this;
}
/**
* Set the <code>skipOnFirstNonTriggeredRule</code> parameter.
*
* @param skipOnFirstNonTriggeredRule to set
* @return the rules engine builder
*/
public RulesEngineBuilder withSkipOnFirstNonTriggeredRule(final boolean skipOnFirstNonTriggeredRule) {
parameters.setSkipOnFirstNonTriggeredRule(skipOnFirstNonTriggeredRule);
return this;
}
/**
* Set <code>skipOnFirstFailedRule</code> 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);
}

@ -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());

Loading…
Cancel
Save