/** * Creates a logical atom expression for the specified. */ public Expr(Type op, Expr left, Expr right) { setLogical(op, left, right); }
break; default: setLogical(Type.NOT, new Expr(this), null); break;
/** * Utility, combine this expression with another, using conjunction. * The expression will only match if both conditions are met. * * @param expr the other expression * @return self for chaining */ public Expr and(Expr expr) { if (type == Type.TRUE) { set(expr); } else if (expr.type != Type.TRUE) { if (type.isLogical() && !expr.type.isLogical()) { if (type == AND) right.and(expr); else setLogical(Type.AND, expr, new Expr(this)); } else { setLogical(Type.AND, new Expr(this), expr); } } return this; }
/** * Utility, combine this expression with another, using disjunction. * The expression will match if either conditions is met. * @param expr the other expression * @return self for chaining */ public Expr or(Expr expr) { if (type == Type.TRUE || type == Type.FALSE || type == NONE) { set(expr); } else if (expr.type != Type.TRUE && expr.type != Type.FALSE && expr.type != Type.NONE) { if (type.isLogical() && !expr.type.isLogical()) { if (type == OR) right.or(expr); else setLogical(Type.OR, expr, new Expr(this)); } else setLogical(Type.OR, new Expr(this), expr); } return this; }
Expr right = strip(expr.right(), type); if (left != null && right != null) expr.setLogical(expr.type(), left, right); else if (left != null) return left; Expr sub = strip(expr.left(), type); if (sub != null) { expr.setLogical(expr.type(), sub, null); return expr; } else {