@Test public void contains_any_returns_true_when_any_expression_value_in_array() throws Exception { QueryExpression expr = EvalTestContext.queryExpressionFromJson("{'array':'field6.nf5', 'contains':'$any', 'values':[1,2,3,4,5]}"); QueryEvaluator eval = QueryEvaluator.getInstance(expr, md); QueryEvaluationContext context = eval.evaluate(jsonDoc); Assert.assertTrue(context.getResult()); }
@Override public boolean evaluate(QueryEvaluationContext ctx) { boolean ret = false; JsonNode node = ctx.getNode(expr.getArray()); if (node instanceof ArrayNode) { ArrayNode array = (ArrayNode) node; List<Value> values = expr.getValues(); ContainsOperator op = expr.getOp(); Type t = elem.getType(); int numElementsContained = 0; for (Iterator<JsonNode> itr = array.elements(); itr.hasNext();) { JsonNode valueNode = itr.next(); for (Value value : values) { Object v = value.getValue(); if (isValueInNode(valueNode, v, t)) { numElementsContained++; break; } } } ret = evaluateContainsOperator(op, numElementsContained, values); } ctx.setResult(ret); return ret; }
ArrayContainsEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { boolean ret = false; JsonNode node = ctx.getNode(expr.getArray()); if (node instanceof ArrayNode) { ArrayNode array = (ArrayNode) node; List<Value> values = expr.getValues(); ContainsOperator op = expr.getOp(); Type t = elem.getType(); int numElementsContained = 0; for (Iterator<JsonNode> itr = array.elements(); itr.hasNext();) { JsonNode valueNode = itr.next(); for (Value value : values) { Object v = value.getValue(); if (isValueInNode(valueNode, v, t)) { numElementsContained++; break; } } } ret = evaluateContainsOperator(op, numElementsContained, values); } ctx.setResult(ret); return ret; } }
ArrayContainsEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { boolean ret = false; JsonNode node = ctx.getNode(expr.getArray()); if (node instanceof ArrayNode) { ArrayNode array = (ArrayNode) node; List<Value> values = expr.getValues(); ContainsOperator op = expr.getOp(); Type t = elem.getType(); int numElementsContained = 0; for (Iterator<JsonNode> itr = array.elements(); itr.hasNext();) { JsonNode valueNode = itr.next(); for (Value value : values) { Object v = value.getValue(); if (isValueInNode(valueNode, v, t)) { numElementsContained++; break; } } } ret = evaluateContainsOperator(op, numElementsContained, values); } ctx.setResult(ret); return ret; } ArrayContainsEvaluator(ArrayContainsExpression expr, FieldTreeNode context); }
ArrayContainsEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { boolean ret = false; JsonNode node = ctx.getNode(expr.getArray()); if (node instanceof ArrayNode) { ArrayNode array = (ArrayNode) node; List<Value> values = expr.getValues(); ContainsOperator op = expr.getOp(); Type t = elem.getType(); int numElementsContained = 0; for (Iterator<JsonNode> itr = array.elements(); itr.hasNext();) { JsonNode valueNode = itr.next(); for (Value value : values) { Object v = value.getValue(); if (isValueInNode(valueNode, v, t)) { numElementsContained++; break; } } } ret = evaluateContainsOperator(op, numElementsContained, values); } ctx.setResult(ret); return ret; } ArrayContainsEvaluator(ArrayContainsExpression expr, FieldTreeNode context); @Override boolean evaluate(QueryEvaluationContext ctx); }
ArrayContainsEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { boolean ret = false; JsonNode node = ctx.getNode(expr.getArray()); if (node instanceof ArrayNode) { ArrayNode array = (ArrayNode) node; List<Value> values = expr.getValues(); ContainsOperator op = expr.getOp(); Type t = elem.getType(); int numElementsContained = 0; for (Iterator<JsonNode> itr = array.elements(); itr.hasNext();) { JsonNode valueNode = itr.next(); for (Value value : values) { Object v = value.getValue(); if (isValueInNode(valueNode, v, t)) { numElementsContained++; break; } } } ret = evaluateContainsOperator(op, numElementsContained, values); } ctx.setResult(ret); return ret; } ArrayContainsEvaluator(ArrayContainsExpression expr, FieldTreeNode context); @Override boolean evaluate(QueryEvaluationContext ctx);  }