use of com.optimizely.ab.config.audience.NullCondition in project java-sdk by optimizely.
the class ConditionJacksonDeserializer method parseConditions.
protected static <T> Condition parseConditions(Class<T> clazz, ObjectMapper objectMapper, JsonNode conditionNode) throws JsonProcessingException, InvalidAudienceCondition {
if (conditionNode.isArray() && conditionNode.size() == 0) {
return new EmptyCondition();
}
List<Condition> conditions = new ArrayList<>();
int startingParsingIndex = 0;
JsonNode opNode = conditionNode.get(0);
String operand = operand(opNode);
if (operand == null) {
operand = "or";
} else {
// the operand is valid so move to the next node.
startingParsingIndex = 1;
}
for (int i = startingParsingIndex; i < conditionNode.size(); i++) {
JsonNode subNode = conditionNode.get(i);
conditions.add(ConditionJacksonDeserializer.<T>parseCondition(clazz, objectMapper, subNode));
}
Condition condition;
switch(operand) {
case "and":
condition = new AndCondition(conditions);
break;
case "not":
condition = new NotCondition(conditions.isEmpty() ? new NullCondition() : conditions.get(0));
break;
default:
condition = new OrCondition(conditions);
break;
}
return condition;
}
Aggregations