@Test void preconditionsShouldBeAsserted() { Expression expression = Cypher.literalOf("Arbitrary expression"); assertThatIllegalArgumentException().isThrownBy(() -> Comparison.create(null, Operator.EQUALITY, expression)) .withMessage("Left expression must not be null."); assertThatIllegalArgumentException().isThrownBy(() -> Comparison.create(expression, Operator.EQUALITY, null)) .withMessage("Right expression must not be null."); assertThatIllegalArgumentException().isThrownBy(() -> Comparison.create(expression, null, expression)) .withMessage("Operator must not be empty."); }
static Comparison create(Operator operator, Expression expression) { Assertions.isTrue(operator.isUnary(), "Operator must be unary."); Assertions.notNull(expression, "Expression must not be null."); switch (operator.getType()) { case PREFIX: return new Comparison(null, operator, expression); case POSTFIX: return new Comparison(expression, operator, null); default: throw new IllegalArgumentException("Invalid operator type " + operator.getType()); } }
Comparison implements Condition { static Comparison create(Operator operator, Expression expression) { Assertions.isTrue(operator.isUnary(), "Operator must be unary."); Assertions.notNull(expression, "Expression must not be null."); switch (operator.getType()) { case PREFIX: return new Comparison(null, operator, expression); case POSTFIX: return new Comparison(expression, operator, null); default: throw new IllegalArgumentException("Invalid operator type " + operator.getType()); } } }
Comparison implements Condition { static Comparison create(Operator operator, Expression expression) { Assertions.isTrue(operator.isUnary(), "Operator must be unary."); Assertions.notNull(expression, "Expression must not be null."); switch (operator.getType()) { case PREFIX: return new Comparison(null, operator, expression); case POSTFIX: return new Comparison(expression, operator, null); default: throw new IllegalArgumentException("Invalid operator type " + operator.getType()); } } private  Comparison(Expression left, Operator operator, Expression right); }
Comparison implements Condition { static Comparison create(Operator operator, Expression expression) { Assertions.isTrue(operator.isUnary(), "Operator must be unary."); Assertions.notNull(expression, "Expression must not be null."); switch (operator.getType()) { case PREFIX: return new Comparison(null, operator, expression); case POSTFIX: return new Comparison(expression, operator, null); default: throw new IllegalArgumentException("Invalid operator type " + operator.getType()); } } private  Comparison(Expression left, Operator operator, Expression right); @Override void accept(Visitor visitor); }
Comparison implements Condition { static Comparison create(Operator operator, Expression expression) { Assertions.isTrue(operator.isUnary(), "Operator must be unary."); Assertions.notNull(expression, "Expression must not be null."); switch (operator.getType()) { case PREFIX: return new Comparison(null, operator, expression); case POSTFIX: return new Comparison(expression, operator, null); default: throw new IllegalArgumentException("Invalid operator type " + operator.getType()); } } private  Comparison(Expression left, Operator operator, Expression right); @Override void accept(Visitor visitor);  }