Skip to content

Commit 9c25814

Browse files
shubham101096Shubham Mishra
and
Shubham Mishra
authored
Move duplicate code in QueryCriteria to new method. (#1706)
Co-authored-by: Shubham Mishra <[email protected]>
1 parent 6102661 commit 9c25814

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/main/java/org/springframework/data/couchbase/core/query/QueryCriteria.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* @author Michael Nitschinger
3939
* @author Michael Reiche
4040
* @author Mauro Monti
41+
* @author Shubham Mishra
4142
*/
4243
public class QueryCriteria implements QueryCriteriaDefinition {
4344

@@ -148,13 +149,7 @@ public QueryCriteria and(N1QLExpression key) {
148149
}
149150

150151
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();
158153
QueryCriteria newThis = wrap(this);
159154
QueryCriteria qc = wrap(criteria);
160155
newThis.criteriaChain.add(qc);
@@ -189,13 +184,7 @@ public QueryCriteria or(N1QLExpression key) {
189184
}
190185

191186
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();
199188
QueryCriteria newThis = wrap(this);
200189
QueryCriteria qc = wrap(criteria);
201190
qc.criteriaChain = newThis.criteriaChain;
@@ -719,4 +708,14 @@ public String toString() {
719708
sb.append("}");
720709
return sb.toString();
721710
}
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+
}
722721
}

0 commit comments

Comments
 (0)