|
|
|
@ -27,9 +27,13 @@ package org.easyrules.core;
|
|
|
|
|
import org.easyrules.api.Rule;
|
|
|
|
|
import org.easyrules.util.Utils;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.TreeSet;
|
|
|
|
|
|
|
|
|
|
import static org.easyrules.core.RuleProxy.asRule;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class representing a composite rule composed of a set of rules.
|
|
|
|
|
*
|
|
|
|
@ -45,6 +49,8 @@ public class CompositeRule extends BasicRule {
|
|
|
|
|
*/
|
|
|
|
|
protected Set<Rule> rules;
|
|
|
|
|
|
|
|
|
|
protected Map<Object, Rule> proxyRules;
|
|
|
|
|
|
|
|
|
|
public CompositeRule() {
|
|
|
|
|
this(Utils.DEFAULT_RULE_NAME, Utils.DEFAULT_RULE_DESCRIPTION, Utils.DEFAULT_RULE_PRIORITY);
|
|
|
|
|
}
|
|
|
|
@ -60,6 +66,7 @@ public class CompositeRule extends BasicRule {
|
|
|
|
|
public CompositeRule(final String name, final String description, final int priority) {
|
|
|
|
|
super(name, description, priority);
|
|
|
|
|
rules = new TreeSet<>();
|
|
|
|
|
proxyRules = new HashMap<>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -96,16 +103,21 @@ public class CompositeRule extends BasicRule {
|
|
|
|
|
* Add a rule to the composite rule.
|
|
|
|
|
* @param rule the rule to add
|
|
|
|
|
*/
|
|
|
|
|
public void addRule(final Rule rule) {
|
|
|
|
|
rules.add(rule);
|
|
|
|
|
public void addRule(final Object rule) {
|
|
|
|
|
Rule proxy = asRule(rule);
|
|
|
|
|
rules.add(proxy);
|
|
|
|
|
proxyRules.put(rule, proxy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove a rule from the composite rule.
|
|
|
|
|
* @param rule the rule to remove
|
|
|
|
|
*/
|
|
|
|
|
public void removeRule(final Rule rule) {
|
|
|
|
|
rules.remove(rule);
|
|
|
|
|
public void removeRule(final Object rule) {
|
|
|
|
|
Rule proxy = proxyRules.get(rule);
|
|
|
|
|
if (proxy != null) {
|
|
|
|
|
rules.remove(proxy);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|