use of com.optimizely.ab.config.audience.EmptyCondition in project java-sdk by optimizely.
the class ConditionUtils method parseConditions.
/**
* parse conditions using List and Map
*
* @param clazz the class of parsed condition
* @param rawObjectList list of conditions
* @param <T> This is the type parameter
* @return audienceCondition
*/
public static <T> Condition parseConditions(Class<T> clazz, List<Object> rawObjectList) throws InvalidAudienceCondition {
if (rawObjectList.size() == 0) {
return new EmptyCondition();
}
List<Condition> conditions = new ArrayList<Condition>();
int startingParseIndex = 0;
String operand = operand(rawObjectList.get(startingParseIndex));
if (operand != null) {
startingParseIndex = 1;
} else {
operand = "or";
}
for (int i = startingParseIndex; i < rawObjectList.size(); i++) {
Object obj = rawObjectList.get(i);
conditions.add(parseConditions(clazz, obj));
}
return buildCondition(operand, conditions);
}
use of com.optimizely.ab.config.audience.EmptyCondition in project java-sdk by optimizely.
the class ConditionUtils method parseConditions.
/**
* Parse conditions from org.json.JsonArray
*
* @param clazz the class of parsed condition
* @param conditionJson jsonArray to parse
* @param <T> This is the type parameter
* @return condition parsed from conditionJson.
*/
public static <T> Condition parseConditions(Class<T> clazz, org.json.JSONArray conditionJson) throws InvalidAudienceCondition {
if (conditionJson.length() == 0) {
return new EmptyCondition();
}
List<Condition> conditions = new ArrayList<Condition>();
int startingParseIndex = 0;
String operand = operand(conditionJson.get(startingParseIndex));
if (operand != null) {
startingParseIndex = 1;
} else {
operand = "or";
}
for (int i = startingParseIndex; i < conditionJson.length(); i++) {
Object obj = conditionJson.get(i);
conditions.add(parseConditions(clazz, obj));
}
return buildCondition(operand, conditions);
}
use of com.optimizely.ab.config.audience.EmptyCondition 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