use of ambit2.rules.conditions.ICondition in project ambit-mirror by ideaconsult.
the class GenericReaction method getReactionFromJsonNode.
public static GenericReaction getReactionFromJsonNode(JsonNode node) throws Exception {
GenericReaction reaction = new GenericReaction();
Boolean use = JSONParsingUtils.extractBooleanKeyword(node, "USE", false);
if (use != null)
reaction.setFlagUse(use);
reaction.name = JSONParsingUtils.extractStringKeyword(node, "NAME", true);
reaction.smirks = JSONParsingUtils.extractStringKeyword(node, "SMIRKS", true);
reaction.reactionClass = JSONParsingUtils.extractStringKeyword(node, "CLASS", false);
Object[] obj = JSONParsingUtils.extractArrayKeyword(node, "USE_CONDITIONS", false, true);
if (obj != null) {
List<ICondition> conditions = new ArrayList<ICondition>();
for (int i = 0; i < obj.length; i++) {
if (obj[i] == null)
continue;
if (obj[i] instanceof String) {
ICondition condition = ReactionParser.getConditionFromString((String) obj[i]);
conditions.add(condition);
} else {
if (obj[i] instanceof JsonNode) {
IDescriptorValueCondition dvc = ConditionJsonParser.getDescriptorValueCondition((JsonNode) obj[i]);
conditions.add(dvc);
} else
throw new Exception("Incorrect USE_CONDITIONS[" + (i + 1) + "]. It is not a string! " + obj[i]);
}
}
reaction.setConditions(conditions);
}
return reaction;
}
use of ambit2.rules.conditions.ICondition in project ambit-mirror by ideaconsult.
the class GenericReactionInstance method calculateConditionsStatus.
public void calculateConditionsStatus() {
if (reaction == null)
return;
if (reaction.conditions != null) {
int n = reaction.conditions.size();
conditionsStatus = new boolean[n];
for (int i = 0; i < n; i++) {
ICondition cond = reaction.conditions.get(i);
conditionsStatus[i] = cond.isTrue(this);
}
}
if (reaction.applicationConditions != null) {
int n = reaction.applicationConditions.size();
applicationConditionsStatus = new boolean[n];
for (int i = 0; i < n; i++) {
ICondition cond = reaction.applicationConditions.get(i);
applicationConditionsStatus[i] = cond.isTrue(this);
}
}
}
Aggregations