Skip to content

Method: negate()

1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jopa.query.criteria;
19:
20: import cz.cvut.kbss.jopa.model.query.criteria.Expression;
21: import cz.cvut.kbss.jopa.model.query.criteria.Predicate;
22: import cz.cvut.kbss.jopa.query.criteria.expressions.AbstractExpression;
23: import cz.cvut.kbss.jopa.model.query.criteria.CriteriaBuilder;
24:
25: import java.util.List;
26:
27: public class CompoundedPredicateImpl extends AbstractPredicate {
28:
29: protected List<Expression<Boolean>> expressions;
30:
31: public CompoundedPredicateImpl(BooleanOperator booleanOperator, List<Expression<Boolean>> expressions,
32: CriteriaBuilder cb) {
33: super(booleanOperator, cb);
34: this.expressions = expressions;
35: }
36:
37: @Override
38: public List<Expression<Boolean>> getExpressions() {
39: return expressions;
40: }
41:
42: @Override
43: public BooleanOperator getOperator() {
44: return this.booleanOperator;
45: }
46:
47: @Override
48: public Predicate not() {
49: for (Expression<Boolean> expression : expressions) {
50: AbstractExpression abstractExpression = (AbstractExpression) expression;
51: abstractExpression.negate();
52: }
53: super.negate();
54: super.negateOperator();
55: return this;
56: }
57:
58: @Override
59: public void setExpressionToQuery(StringBuilder query, CriteriaParameterFiller parameterFiller) {
60: for (int i = 0; i < expressions.size(); i++) {
61: AbstractExpression expression = (AbstractExpression) expressions.get(i);
62: if (expression instanceof CompoundedPredicateImpl) {
63: query.append("(");
64: expression.setExpressionToQuery(query, parameterFiller);
65: query.append(")");
66: } else {
67: expression.setExpressionToQuery(query, parameterFiller);
68: }
69:
70: if (i < (expressions.size() - 1)) {
71: query.append(" ").append(getOperator()).append(" ");
72: }
73: }
74: }
75:
76: @Override
77: public void negate() {
78: this.not();
79: }
80: }