|
38 | 38 | * @author Michael Nitschinger |
39 | 39 | * @author Michael Reiche |
40 | 40 | * @author Mauro Monti |
| 41 | + * @author Shubham Mishra |
41 | 42 | */ |
42 | 43 | public class QueryCriteria implements QueryCriteriaDefinition { |
43 | 44 |
|
@@ -148,13 +149,7 @@ public QueryCriteria and(N1QLExpression key) { |
148 | 149 | } |
149 | 150 |
|
150 | 151 | public QueryCriteria and(QueryCriteria criteria) { |
151 | | - if (this.criteriaChain != null && !this.criteriaChain.contains(this)) { |
152 | | - throw new RuntimeException("criteria chain does not include this"); |
153 | | - } |
154 | | - if (this.criteriaChain == null) { |
155 | | - this.criteriaChain = new LinkedList<>(); |
156 | | - this.criteriaChain.add(this); |
157 | | - } |
| 152 | + checkAndAddToCriteriaChain(); |
158 | 153 | QueryCriteria newThis = wrap(this); |
159 | 154 | QueryCriteria qc = wrap(criteria); |
160 | 155 | newThis.criteriaChain.add(qc); |
@@ -189,13 +184,7 @@ public QueryCriteria or(N1QLExpression key) { |
189 | 184 | } |
190 | 185 |
|
191 | 186 | public QueryCriteria or(QueryCriteria criteria) { |
192 | | - if (this.criteriaChain != null && !this.criteriaChain.contains(this)) { |
193 | | - throw new RuntimeException("criteria chain does not include this"); |
194 | | - } |
195 | | - if (this.criteriaChain == null) { |
196 | | - this.criteriaChain = new LinkedList<>(); |
197 | | - this.criteriaChain.add(this); |
198 | | - } |
| 187 | + checkAndAddToCriteriaChain(); |
199 | 188 | QueryCriteria newThis = wrap(this); |
200 | 189 | QueryCriteria qc = wrap(criteria); |
201 | 190 | qc.criteriaChain = newThis.criteriaChain; |
@@ -719,4 +708,14 @@ public String toString() { |
719 | 708 | sb.append("}"); |
720 | 709 | return sb.toString(); |
721 | 710 | } |
| 711 | + |
| 712 | + private void checkAndAddToCriteriaChain() { |
| 713 | + if (this.criteriaChain != null && !this.criteriaChain.contains(this)) { |
| 714 | + throw new RuntimeException("criteria chain does not include this"); |
| 715 | + } |
| 716 | + if (this.criteriaChain == null) { |
| 717 | + this.criteriaChain = new LinkedList<>(); |
| 718 | + this.criteriaChain.add(this); |
| 719 | + } |
| 720 | + } |
722 | 721 | } |
0 commit comments