Source:
private boolean executeSelectorTree(QueryNode node, DocumentRevision rev) { if (node instanceof AndQueryNode) { boolean passed = true; AndQueryNode andNode = (AndQueryNode) node; for (QueryNode child: andNode.children) { passed = passed && executeSelectorTree(child, rev); } return passed; } if (node instanceof OrQueryNode) { boolean passed = false; OrQueryNode orNode = (OrQueryNode) node; for (QueryNode child: orNode.children) { passed = passed || executeSelectorTree(child, rev); } return passed; } else if (node instanceof OperatorExpressionNode) { Map<String, Object> expression = ((OperatorExpressionNode) node).expression; String fieldName = (String) expression.keySet().toArray()[0]; Map<String, Object> operatorExpression; operatorExpression = (Map<String, Object>) expression.get(fieldName); String operator = (String) operatorExpression.keySet().toArray()[0]; boolean invertResult = operator.equals(NOT); if (invertResult) { operatorExpression = (Map<String, Object>) operatorExpression.get(NOT); operator = (String) operatorExpression.keySet().toArray()[0]; } Object expected = operatorExpression.get(operator); Object actual = ValueExtractor.extractValueForFieldName(fieldName, rev); boolean passed = false; if (actual instanceof List) { boolean currentItemPassed = false; for (Object item: (List<Object>) actual) { currentItemPassed = valueCompare(item, operator, expected); passed = passed || (invertResult ? !currentItemPassed : currentItemPassed); } } else { passed = valueCompare(actual, operator, expected); passed = invertResult ? !passed : passed; } return passed; } else { String msg = String.format("Found unexpected selector execution tree: %s", node); logger.log(Level.SEVERE, msg); return false; } }

Target:
private boolean executeSelectorTree(QueryNode node, DocumentRevision rev) { if (node instanceof AndQueryNode) { boolean passed = true; AndQueryNode andNode = (AndQueryNode) node; for (QueryNode child: andNode.children) { passed = passed && executeSelectorTree(child, rev); } return passed; } if (node instanceof OrQueryNode) { boolean passed = false; OrQueryNode orNode = (OrQueryNode) node; for (QueryNode child: orNode.children) { passed = passed || executeSelectorTree(child, rev); } return passed; } else if (node instanceof OperatorExpressionNode) { Map<String, Object> expression = ((OperatorExpressionNode) node).expression; String fieldName = (String) expression.keySet().toArray()[0]; Map<String, Object> operatorExpression; operatorExpression = (Map<String, Object>) expression.get(fieldName); String operator = (String) operatorExpression.keySet().toArray()[0]; boolean invertResult = operator.equals(NOT); if (invertResult) { operatorExpression = (Map<String, Object>) operatorExpression.get(NOT); operator = (String) operatorExpression.keySet().toArray()[0]; } Object expected = operatorExpression.get(operator); Object actual = ValueExtractor.extractValueForFieldName(fieldName, rev); boolean passed = false; if (actual instanceof List) { for (Object item: (List<Object>) actual) { boolean currentItemPassed = valueCompare(item, operator, expected); passed = passed || (invertResult ? !currentItemPassed : currentItemPassed); } } else { passed = valueCompare(actual, operator, expected); passed = invertResult ? !passed : passed; } return passed; } else { String msg = String.format("Found unexpected selector execution tree: %s", node); logger.log(Level.SEVERE, msg); return false; } }