DFS method
Implementation
Operator DFS({String? key, required Map<String, dynamic> json}) {
for (MapEntry<String, dynamic> entry in json.entries) {
final operator = getOperator(entry.key);
if (operator is CombinationOperator) {
List<Operator> subList = [];
entry.value.forEach((e) {
subList.add(DFS(key: key, json: e));
});
operator.operators = subList;
return operator;
} else if (operator == null) {
List<Operator> subList = [];
entry.value.forEach((operatorStr, arg) {
final subOperator =
getOperator(operatorStr, key: entry.key, expected: arg);
if (subOperator is ConditionOperator) {
subList.add(subOperator);
} else if (subOperator is CombinationOperator) {
subList.add(DFS(key: entry.key, json: {operatorStr: arg}));
} else if (subOperator == null) {
if (arg is Map<String, dynamic>) {
subList.add(_nestedOperator(
"${key != null ? "$key." : ""}${entry.key}.${operatorStr}",
arg));
} else {
throw AdapterException(error: 'Invalid Selector Format');
}
}
});
if (subList.length > 1) {
return AndOperator(operators: subList);
} else {
return subList.first;
}
} else {
throw AdapterException(error: "Invalid Format of Selector");
}
}
return this.value;
}