/** * Default behavior is to recursively iterate the nested query. If nested * processing returns an object different from the original nested query, * this method creates a new unary logical expression using the new query * expression, and returns that. */ protected QueryExpression itrUnaryLogicalExpression(UnaryLogicalExpression q, Path context) { QueryExpression newq = iterate(q.getQuery(), context); if (newq != q.getQuery()) { return new UnaryLogicalExpression(q.getOp(), newq); } else { return q; } }
/** * Returns a json representation of the query */ @Override public JsonNode toJson() { return getFactory().objectNode().set(op.toString(), query.toJson()); }
@Override protected ItrState itrUnaryLogicalExpression(UnaryLogicalExpression q, Path context) { return iterate(q.getQuery(),context); }
/** * Parses a unary logical expression using the given object node */ public static UnaryLogicalExpression fromJson(ObjectNode node) { if (node.size() != 1) { throw Error.get(QueryConstants.ERR_INVALID_LOGICAL_EXPRESSION, node.toString()); } String fieldName = node.fieldNames().next(); UnaryLogicalOperator op = UnaryLogicalOperator.fromString(fieldName); if (op == null) { throw Error.get(QueryConstants.ERR_INVALID_LOGICAL_EXPRESSION, node.toString()); } QueryExpression q = QueryExpression.fromJson(node.get(fieldName)); return new UnaryLogicalExpression(op, q); } }
/** * Parses a query expression from the given json node */ public static QueryExpression fromJson(JsonNode node) { if (node instanceof ObjectNode) { ObjectNode onode = (ObjectNode) node; // If there is only one field, then that field must be a // logical operator String firstField = onode.fieldNames().next(); if (UnaryLogicalOperator.fromString(firstField) != null) { return UnaryLogicalExpression.fromJson(onode); } else if (NaryLogicalOperator.fromString(firstField) != null) { return NaryLogicalExpression.fromJson(onode); } else { return ComparisonExpression.fromJson(onode); } } else { throw Error.get(QueryConstants.ERR_INVALID_QUERY, node.toString()); } }
@Override public QueryExpression rewrite(QueryExpression q) { UnaryLogicalExpression le = dyncast(UnaryLogicalExpression.class, q); if (le != null && le.getOp() == UnaryLogicalOperator._not) { UnaryLogicalExpression oreq = dyncast(UnaryLogicalExpression.class, le.getQuery()); if (oreq != null && oreq.getOp() == UnaryLogicalOperator._not) { return oreq.getQuery(); } } return q; } }
private static boolean isFieldQueried(Path field, UnaryLogicalExpression q, Path context) { return q.getQuery().isRequired(field, context); }
/** * Parses a unary logical expression using the given object node */ public static UnaryLogicalExpression fromJson(ObjectNode node) { if (node.size() != 1) { throw Error.get(QueryConstants.ERR_INVALID_LOGICAL_EXPRESSION, node.toString()); } String fieldName = node.fieldNames().next(); UnaryLogicalOperator op = UnaryLogicalOperator.fromString(fieldName); if (op == null) { throw Error.get(QueryConstants.ERR_INVALID_LOGICAL_EXPRESSION, node.toString()); } QueryExpression q = QueryExpression.fromJson(node.get(fieldName)); return new UnaryLogicalExpression(op, q); } }
/** * Parses a query expression from the given json node */ public static QueryExpression fromJson(JsonNode node) { if (node instanceof ObjectNode) { ObjectNode onode = (ObjectNode) node; // If there is only one field, then that field must be a // logical operator String firstField = onode.fieldNames().next(); if (UnaryLogicalOperator.fromString(firstField) != null) { return UnaryLogicalExpression.fromJson(onode); } else if (NaryLogicalOperator.fromString(firstField) != null) { return NaryLogicalExpression.fromJson(onode); } else { return ComparisonExpression.fromJson(onode); } } else { throw Error.get(QueryConstants.ERR_INVALID_QUERY, node.toString()); } }
/** * Default behavior is to recursively iterate the nested query. If nested * processing returns an object different from the original nested query, * this method creates a new unary logical expression using the new query * expression, and returns that. */ protected QueryExpression itrUnaryLogicalExpression(UnaryLogicalExpression q, Path context) { QueryExpression newq = iterate(q.getQuery(), context); if (newq != q.getQuery()) { return new UnaryLogicalExpression(q.getOp(), newq); } else { return q; } }
@Override protected ItrState itrUnaryLogicalExpression(UnaryLogicalExpression q, Path context) { return iterate(q.getQuery(),context); }
/** * Returns a json representation of the query */ @Override public JsonNode toJson() { return getFactory().objectNode().set(op.toString(), query.toJson()); }
@Override public QueryExpression rewrite(QueryExpression q) { UnaryLogicalExpression le=dyncast(UnaryLogicalExpression.class,q); if(le!=null&&le.getOp()==UnaryLogicalOperator._not) { NaryLogicalExpression oreq=dyncast(NaryLogicalExpression.class,le.getQuery()); if(oreq!=null&&oreq.getOp()==NaryLogicalOperator._or) { List<QueryExpression> newList=new ArrayList<>(oreq.getQueries().size()); for(QueryExpression x:oreq.getQueries()) newList.add(new UnaryLogicalExpression(UnaryLogicalOperator._not,x)); return new NaryLogicalExpression(NaryLogicalOperator._and,newList); } } return q; } }
private static boolean isFieldQueried(Path field, UnaryLogicalExpression q, Path context) { return q.getQuery().isRequired(field, context); }
@Override public QueryExpression rewrite(QueryExpression q) { UnaryLogicalExpression le = dyncast(UnaryLogicalExpression.class, q); if (le != null && le.getOp() == UnaryLogicalOperator._not) { NaryLogicalExpression oreq = dyncast(NaryLogicalExpression.class, le.getQuery()); if (oreq != null && oreq.getOp() == NaryLogicalOperator._or) { List<QueryExpression> newList = new ArrayList<>(oreq.getQueries().size()); for (QueryExpression x : oreq.getQueries()) { newList.add(new UnaryLogicalExpression(UnaryLogicalOperator._not, x)); } return new NaryLogicalExpression(NaryLogicalOperator._and, newList); } } return q; } }
@Override public QueryExpression rewrite(QueryExpression q) { UnaryLogicalExpression le = dyncast(UnaryLogicalExpression.class, q); if (le != null && le.getOp() == UnaryLogicalOperator._not) { UnaryLogicalExpression oreq = dyncast(UnaryLogicalExpression.class, le.getQuery()); if (oreq != null && oreq.getOp() == UnaryLogicalOperator._not) { return oreq.getQuery(); } } return q; } }
/** * If the enclosed query is a placeholder (TruePH or FalsePH), it * negates the placeholder, otherwise, the query remains as is */ @Override protected QueryExpression itrUnaryLogicalExpression(UnaryLogicalExpression q, Path context) { UnaryLogicalExpression nq = (UnaryLogicalExpression) super.itrUnaryLogicalExpression(q, context); if (nq.getQuery() instanceof TruePH) { return new FalsePH(); } else if (nq.getQuery() instanceof FalsePH) { return new TruePH(); } else { return nq; } }