/** * Evaluates the length of the given argument. * * @param evaluatedArgs List of expressions to be evaluated. * Can be a string, array or object * @return Length of the argument */ @Override public JsonNode evaluate(List<JsonNode> evaluatedArgs) throws InvalidTypeException { JsonNode arg = evaluatedArgs.get(0); if (arg.isTextual()) { return getStringLength(arg); } else if (arg.isArray() || arg.isObject()) { return new IntNode(arg.size()); } throw new InvalidTypeException("Type mismatch. Expecting a string or an array or an object."); }
/** * Retrieves the subject(lhs expression) which could be an array * or string, the search(rhs expression) which could be any JmesPath * expression. If subject is an array, this function returns true if * one of the elements in the array is equal to the provided search * value. If the provided subject is a string, this function returns * true if the string contains the provided search argument. * * @param evaluatedArgs List of input expressions * @return True subject contains search; * False otherwise */ @Override public JsonNode evaluate(List<JsonNode> evaluatedArgs) { JsonNode subject = evaluatedArgs.get(0); JsonNode search = evaluatedArgs.get(1); if (subject.isArray()) { return doesArrayContain(subject, search); } else if (subject.isTextual()) { return doesStringContain(subject, search); } throw new InvalidTypeException("Type mismatch. Expecting a string or an array."); }
private static JmesPathExpression jsonToComparator(JsonNode jsonNode) { List<JmesPathExpression> args = getChildren(jsonNode); switch(jsonNode.get("value").asText()) { case "eq": return new OpEquals(args.get(0), args.get(1)); case "ne": return new OpNotEquals(args.get(0), args.get(1)); case "gt": return new OpGreaterThan(args.get(0), args.get(1)); case "lt": return new OpLessThan(args.get(0), args.get(1)); case "gte": return new OpGreaterThanOrEqualTo(args.get(0), args.get(1)); case "lte": return new OpLessThanOrEqualTo(args.get(0), args.get(1)); default: throw new InvalidTypeException("Didn't match any of the expected comparator type"); } }
return jsonToLiteral(jsonNode); throw new InvalidTypeException("JsonNode type not found");
/** * Evaluates the length of the given argument. * * @param evaluatedArgs List of expressions to be evaluated. * Can be a string, array or object * @return Length of the argument */ @Override public JsonNode evaluate(List<JsonNode> evaluatedArgs) throws InvalidTypeException { JsonNode arg = evaluatedArgs.get(0); if (arg.isTextual()) { return getStringLength(arg); } else if (arg.isArray() || arg.isObject()) { return new IntNode(arg.size()); } throw new InvalidTypeException("Type mismatch. Expecting a string or an array or an object."); }
/** * Evaluates the length of the given argument. * * @param evaluatedArgs List of expressions to be evaluated. * Can be a string, array or object * @return Length of the argument */ @Override public JsonNode evaluate(List<JsonNode> evaluatedArgs) throws InvalidTypeException { JsonNode arg = evaluatedArgs.get(0); if (arg.isTextual()) { return getStringLength(arg); } else if (arg.isArray() || arg.isObject()) { return new IntNode(arg.size()); } throw new InvalidTypeException("Type mismatch. Expecting a string or an array or an object."); }
/** * Retrieves the subject(lhs expression) which could be an array * or string, the search(rhs expression) which could be any JmesPath * expression. If subject is an array, this function returns true if * one of the elements in the array is equal to the provided search * value. If the provided subject is a string, this function returns * true if the string contains the provided search argument. * * @param evaluatedArgs List of input expressions * @return True subject contains search; * False otherwise */ @Override public JsonNode evaluate(List<JsonNode> evaluatedArgs) { JsonNode subject = evaluatedArgs.get(0); JsonNode search = evaluatedArgs.get(1); if (subject.isArray()) { return doesArrayContain(subject, search); } else if (subject.isTextual()) { return doesStringContain(subject, search); } throw new InvalidTypeException("Type mismatch. Expecting a string or an array."); }
/** * Retrieves the subject(lhs expression) which could be an array * or string, the search(rhs expression) which could be any JmesPath * expression. If subject is an array, this function returns true if * one of the elements in the array is equal to the provided search * value. If the provided subject is a string, this function returns * true if the string contains the provided search argument. * * @param evaluatedArgs List of input expressions * @return True subject contains search; * False otherwise */ @Override public JsonNode evaluate(List<JsonNode> evaluatedArgs) { JsonNode subject = evaluatedArgs.get(0); JsonNode search = evaluatedArgs.get(1); if (subject.isArray()) { return doesArrayContain(subject, search); } else if (subject.isTextual()) { return doesStringContain(subject, search); } throw new InvalidTypeException("Type mismatch. Expecting a string or an array."); }
private static JmesPathExpression jsonToComparator(JsonNode jsonNode) { List<JmesPathExpression> args = getChildren(jsonNode); switch(jsonNode.get("value").asText()) { case "eq": return new OpEquals(args.get(0), args.get(1)); case "ne": return new OpNotEquals(args.get(0), args.get(1)); case "gt": return new OpGreaterThan(args.get(0), args.get(1)); case "lt": return new OpLessThan(args.get(0), args.get(1)); case "gte": return new OpGreaterThanOrEqualTo(args.get(0), args.get(1)); case "lte": return new OpLessThanOrEqualTo(args.get(0), args.get(1)); default: throw new InvalidTypeException("Didn't match any of the expected comparator type"); } }
return jsonToLiteral(jsonNode); throw new InvalidTypeException("JsonNode type not found");