Move duplicate code in QueryCriteria to new method. (#1706)
Co-authored-by: Shubham Mishra <sh277446@dal.ca>
This commit is contained in:
committed by
mikereiche
parent
a8992f1e22
commit
7a402abe07
@@ -38,6 +38,7 @@ import com.couchbase.client.java.json.JsonValue;
|
||||
* @author Michael Nitschinger
|
||||
* @author Michael Reiche
|
||||
* @author Mauro Monti
|
||||
* @author Shubham Mishra
|
||||
*/
|
||||
public class QueryCriteria implements QueryCriteriaDefinition {
|
||||
|
||||
@@ -148,13 +149,7 @@ public class QueryCriteria implements QueryCriteriaDefinition {
|
||||
}
|
||||
|
||||
public QueryCriteria and(QueryCriteria criteria) {
|
||||
if (this.criteriaChain != null && !this.criteriaChain.contains(this)) {
|
||||
throw new RuntimeException("criteria chain does not include this");
|
||||
}
|
||||
if (this.criteriaChain == null) {
|
||||
this.criteriaChain = new LinkedList<>();
|
||||
this.criteriaChain.add(this);
|
||||
}
|
||||
checkAndAddToCriteriaChain();
|
||||
QueryCriteria newThis = wrap(this);
|
||||
QueryCriteria qc = wrap(criteria);
|
||||
newThis.criteriaChain.add(qc);
|
||||
@@ -189,13 +184,7 @@ public class QueryCriteria implements QueryCriteriaDefinition {
|
||||
}
|
||||
|
||||
public QueryCriteria or(QueryCriteria criteria) {
|
||||
if (this.criteriaChain != null && !this.criteriaChain.contains(this)) {
|
||||
throw new RuntimeException("criteria chain does not include this");
|
||||
}
|
||||
if (this.criteriaChain == null) {
|
||||
this.criteriaChain = new LinkedList<>();
|
||||
this.criteriaChain.add(this);
|
||||
}
|
||||
checkAndAddToCriteriaChain();
|
||||
QueryCriteria newThis = wrap(this);
|
||||
QueryCriteria qc = wrap(criteria);
|
||||
qc.criteriaChain = newThis.criteriaChain;
|
||||
@@ -719,4 +708,14 @@ public class QueryCriteria implements QueryCriteriaDefinition {
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private void checkAndAddToCriteriaChain() {
|
||||
if (this.criteriaChain != null && !this.criteriaChain.contains(this)) {
|
||||
throw new RuntimeException("criteria chain does not include this");
|
||||
}
|
||||
if (this.criteriaChain == null) {
|
||||
this.criteriaChain = new LinkedList<>();
|
||||
this.criteriaChain.add(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user