@Override public Predicate not() { if (not == null) { not = ExpressionUtils.predicate(Ops.NOT, this); } return not; }
/** * Create a {@code left not in right} expression * * @param <D> type of expressions * @param left lhs of expression * @param right rhs of expression * @return left not in right */ public static <D> Predicate notIn(Expression<D> left, CollectionExpression<?,? extends D> right) { return predicate(Ops.NOT_IN, left, right); }
/** * Create a {@code left is not null} expression * * @param left operation argument * @return left is null */ public static Predicate isNotNull(Expression<?> left) { return predicate(Ops.IS_NOT_NULL, left); }
/** * Create a {@code left == right} expression * * @param <D> type of expressions * @param left lhs of expression * @param right rhs of expression * @return left == right */ public static <D> Predicate eq(Expression<D> left, Expression<? extends D> right) { return predicate(Ops.EQ, left, right); }
/** * Create a {@code left in right} expression * * @param <D> type of expressions * @param left lhs of expression * @param right rhs of expression * @return left in right */ public static <D> Predicate in(Expression<D> left, CollectionExpression<?,? extends D> right) { return predicate(Ops.IN, left, right); }
/** * Create a {@code left in right} expression * * @param <D> type of expressions * @param left lhs of expression * @param right rhs of expression * @return left in right */ public static <D> Predicate in(Expression<D> left, SubQueryExpression<? extends D> right) { return predicate(Ops.IN, left, right); }
/** * Create a {@code left != right} expression * * @param <D> type of expressions * @param left lhs of expression * @param right rhs of expression * @return left != right */ public static <D> Predicate ne(Expression<D> left, Expression<? super D> right) { return predicate(Ops.NE, left, right); }
/** * Create a {@code left not in right} expression * * @param <D> type of expressions * @param left lhs of expression * @param right rhs of expression * @return left not in right */ public static <D> Predicate notIn(Expression<D> left, SubQueryExpression<? extends D> right) { return predicate(Ops.NOT_IN, left, right); }
@Override public Predicate not() { if (not == null) { not = ExpressionUtils.predicate(Ops.NOT, this); } return not; }
/** * Create a {@code left is null} expression * * @param left operation argument * @return left is null */ public static Predicate isNull(Expression<?> left) { return predicate(Ops.IS_NULL, left); }
protected BooleanOperation(Operator op, ImmutableList<Expression<?>> args) { super(ExpressionUtils.predicate(op, args)); opMixin = (PredicateOperation) mixin; }
/** * Create a new Operation expression * * @param operator operator * @param args operation arguments * @return operation expression */ public static PredicateOperation predicate(Operator operator, Expression<?>... args) { return predicate(operator, ImmutableList.copyOf(args)); }
/** * Create a {@code left in right} expression * * @param <D> element type * @param left lhs of expression * @param right rhs of expression * @return left in right */ public static <D> Predicate in(Expression<D> left, Collection<? extends D> right) { if (right.size() == 1) { return eqConst(left, right.iterator().next()); } else { return predicate(Ops.IN, left, ConstantImpl.create(right)); } }
/** * Create a {@code left not in right} expression * * @param <D> type of expressions * @param left lhs of expression * @param right rhs of expression * @return left not in right */ public static <D> Predicate notIn(Expression<D> left, Collection<? extends D> right) { if (right.size() == 1) { return neConst(left, right.iterator().next()); } else { return predicate(Ops.NOT_IN, left, ConstantImpl.create(right)); } }
public Q on(Predicate... conditions) { return queryMixin.where(ExpressionUtils.predicate( MongodbOps.ELEM_MATCH, collection, ExpressionUtils.allOf(conditions))); }
/** * Add the given where conditions. * * @param conditions must not be {@literal null}. * @return the target {@link QueryMixin}. * @see QueryMixin#where(Predicate) */ public Q on(Predicate... conditions) { return queryMixin .where(ExpressionUtils.predicate(MongodbOps.ELEM_MATCH, collection, ExpressionUtils.allOf(conditions))); } }
/** * Create the intersection of the given arguments * * @param left lhs of expression * @param right rhs of expression * @return left and right */ public static Predicate and(Predicate left, Predicate right) { left = (Predicate) extract(left); right = (Predicate) extract(right); if (left == null) { return right; } else if (right == null) { return left; } else { return predicate(Ops.AND, left, right); } }
/** * Create a {@code left or right} expression * * @param left lhs of expression * @param right rhs of expression * @return left or right */ public static Predicate or(Predicate left, Predicate right) { left = (Predicate) extract(left); right = (Predicate) extract(right); if (left == null) { return right; } else if (right == null) { return left; } else { return predicate(Ops.OR, left, right); } }
@Override public Expression<?> visit(Operation<?> expr, C context) { ImmutableList<Expression<?>> args = visit(expr.getArgs(), context); if (args.equals(expr.getArgs())) { return expr; } else if (expr instanceof Predicate) { return ExpressionUtils.predicate(expr.getOperator(), args); } else { return ExpressionUtils.operation(expr.getType(), expr.getOperator(), args); } }
@SuppressWarnings("unchecked") @Test public void not() { Path<?> o1 = ExpressionUtils.path(Object.class, "o1"); Path<?> o2 = ExpressionUtils.path(Object.class, "o2"); PredicateOperation template = ExpressionUtils.predicate(Ops.EQ, o1, o2); assertEquals("!(o1 = o2)", template.not().toString()); }