Commit 5e281761 authored by Nico Mack's avatar Nico Mack

Added honnorOrder method to Rules

placed operations performed in duplicate method inside synchronized
block
parent 87eb61d2
......@@ -88,8 +88,10 @@ public class VectorVariable<B> extends Variable<List<B>> implements List<B> {
/** {@inheritDoc} */
@Override
public void setValue(List<B> values) {
this.value.clear();
this.value.addAll(values);
synchronized (this.value) {
this.value.clear();
this.value.addAll(values);
}
if (!this.notificationSuspended()) {
this.notifyInputChangeListeners(new InputEvent(this));
}
......
......@@ -20,6 +20,7 @@ import lu.list.itis.dkd.tui.cps.variable.Variable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -41,12 +42,16 @@ public abstract class Rule {
private Map<String, Boolean> conditions;
private List<String> sequence;
private Operator operator;
private boolean isStateful;
private boolean firedOnce;
private boolean ordered;
private boolean singleShot;
private boolean enabled;
......@@ -71,13 +76,16 @@ public abstract class Rule {
this.application = application;
this.conditions = new HashMap<>();
this.sequence = new ArrayList<>();
for (String condition : conditions) {
this.conditions.put(condition, Boolean.FALSE);
this.sequence.add(condition);
}
this.name = (name != null) ? name : getClass().getSimpleName();
this.operator = Operator.OR;
this.singleShot = false;
this.firedOnce = false;
this.ordered = false;
this.enabled = true;
}
......@@ -110,8 +118,20 @@ public abstract class Rule {
case AND:
matches = true;
for (Variable<?> source : sources) {
if (this.conditions.containsKey(source.getName())) {
this.conditions.replace(source.getName(), Boolean.TRUE);
String identifier = source.getName();
if (this.conditions.containsKey(identifier)) {
if (this.ordered) {
Integer sequenceNumber = this.sequence.indexOf(identifier);
boolean orderRespected = true;
for (int index = 0; index < sequenceNumber; index++) {
orderRespected &= this.conditions.get(this.sequence.get(index));
}
if (orderRespected) {
this.conditions.replace(source.getName(), Boolean.TRUE);
}
} else {
this.conditions.replace(source.getName(), Boolean.TRUE);
}
}
}
......@@ -169,6 +189,13 @@ public abstract class Rule {
// ---------------------------------------------------------------------------
public Rule honnorOrder(boolean ordered) {
this.ordered = ordered;
return this;
}
// ---------------------------------------------------------------------------
public String getName() {
return this.name;
}
......@@ -220,7 +247,12 @@ public abstract class Rule {
}
String operatorToPrepend = "";
for (String condition : this.conditions.keySet()) {
if (this.ordered) {
builder.append(" <SEQ> ");
}
for (String condition : this.sequence) {
builder.append(operatorToPrepend).append(condition);
operatorToPrepend = operatorAsString;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment