Skip to content

Commit 315b7a4

Browse files
committed
Refactor MongoDB query operations: introduce QueryOperationWithField to eliminate redundancy and unify field name handling across query operations.
1 parent 0e795e6 commit 315b7a4

23 files changed

Lines changed: 75 additions & 111 deletions

client-java/controller/src/main/java/org/evomaster/client/java/controller/mongo/operations/AllOperation.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,15 @@
66
* Represent $all operation.
77
* Matches arrays that contain all elements specified in the query.
88
*/
9-
public class AllOperation<V> extends QueryOperation{
10-
private final String fieldName;
9+
public class AllOperation<V> extends QueryOperationWithField {
1110
private final List<V> values;
1211

1312
public AllOperation(String fieldName, List<V> values) {
14-
this.fieldName = fieldName;
13+
super(fieldName);
1514
this.values = values;
1615
}
1716

18-
public String getFieldName() {
19-
return fieldName;
20-
}
21-
2217
public List<V> getValues() {
2318
return values;
2419
}
25-
}
20+
}

client-java/controller/src/main/java/org/evomaster/client/java/controller/mongo/operations/AndOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Represent $and operation.
77
* Joins query clauses with a logical AND returns all documents that match the conditions of all clauses.
88
*/
9-
public class AndOperation extends QueryOperation{
9+
public class AndOperation extends QueryOperation {
1010
private final List<QueryOperation> conditions;
1111

1212
public AndOperation(List<QueryOperation> conditions) {
@@ -16,4 +16,4 @@ public AndOperation(List<QueryOperation> conditions) {
1616
public List<QueryOperation> getConditions() {
1717
return conditions;
1818
}
19-
}
19+
}
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
package org.evomaster.client.java.controller.mongo.operations;
22

3-
public abstract class ComparisonOperation<V> extends QueryOperation{
4-
private final String fieldName;
3+
public abstract class ComparisonOperation<V> extends QueryOperationWithField {
54
private final V value;
65

76
ComparisonOperation(String fieldName, V value) {
8-
this.fieldName = fieldName;
7+
super(fieldName);
98
this.value = value;
109
}
1110

12-
public String getFieldName() {
13-
return fieldName;
14-
}
15-
1611
public V getValue() {
1712
return value;
1813
}
19-
}
14+
}

client-java/controller/src/main/java/org/evomaster/client/java/controller/mongo/operations/ElemMatchOperation.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,15 @@
55
* Selects documents if element in the array field matches all the specified $elemMatch conditions.
66
* Here it only has one condition to match implementation in "com.mongodb.client.model.Filters"
77
*/
8-
public class ElemMatchOperation extends QueryOperation{
9-
private final String fieldName;
8+
public class ElemMatchOperation extends QueryOperationWithField {
109
private final QueryOperation condition;
1110

1211
public ElemMatchOperation(String fieldName, QueryOperation condition) {
13-
this.fieldName = fieldName;
12+
super( fieldName);
1413
this.condition = condition;
1514
}
1615

17-
public String getFieldName() {
18-
return fieldName;
19-
}
20-
2116
public QueryOperation getCondition() {
2217
return condition;
2318
}
24-
}
19+
}

client-java/controller/src/main/java/org/evomaster/client/java/controller/mongo/operations/EqualsOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* Represent $eq operation.
55
* Matches documents where the value of a field equals the specified value.
66
*/
7-
public class EqualsOperation<V> extends ComparisonOperation<V>{
7+
public class EqualsOperation<V> extends ComparisonOperation<V> {
88
public EqualsOperation(String fieldName, V value) {
99
super(fieldName, value);
1010
}
11-
}
11+
}

client-java/controller/src/main/java/org/evomaster/client/java/controller/mongo/operations/ExistsOperation.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,15 @@
55
* When boolean is true, $exists matches the documents that contain the field.
66
* When boolean is false, the query returns only the documents that do not contain the field.
77
*/
8-
public class ExistsOperation extends QueryOperation{
9-
private final String fieldName;
8+
public class ExistsOperation extends QueryOperationWithField {
109
private final Boolean bool;
1110

1211
public ExistsOperation(String fieldName, Boolean bool) {
13-
this.fieldName = fieldName;
12+
super(fieldName);
1413
this.bool = bool;
1514
}
1615

17-
public String getFieldName() {
18-
return fieldName;
19-
}
20-
2116
public Boolean getBoolean() {
2217
return bool;
2318
}
24-
}
19+
}

client-java/controller/src/main/java/org/evomaster/client/java/controller/mongo/operations/GreaterThanEqualsOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* Represent $gte operation.
55
* Selects the documents where the value of the field is greater than or equal to a specified value
66
*/
7-
public class GreaterThanEqualsOperation<V> extends ComparisonOperation<V>{
7+
public class GreaterThanEqualsOperation<V> extends ComparisonOperation<V> {
88
public GreaterThanEqualsOperation(String fieldName, V value) {
99
super(fieldName, value);
1010
}
11-
}
11+
}

client-java/controller/src/main/java/org/evomaster/client/java/controller/mongo/operations/GreaterThanOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* Represent $gt operation.
55
* Selects the documents where the value of the field is greater than or equal to a specified value
66
*/
7-
public class GreaterThanOperation<V> extends ComparisonOperation<V>{
7+
public class GreaterThanOperation<V> extends ComparisonOperation<V> {
88
public GreaterThanOperation(String fieldName, V value) {
99
super(fieldName, value);
1010
}
11-
}
11+
}

client-java/controller/src/main/java/org/evomaster/client/java/controller/mongo/operations/InOperation.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,15 @@
66
* Represent $in operation.
77
* Selects the documents where the value of a field equals any value in the specified array.
88
*/
9-
public class InOperation<V> extends QueryOperation{
10-
private final String fieldName;
9+
public class InOperation<V> extends QueryOperationWithField {
1110
private final List<V> values;
1211

1312
public InOperation(String fieldName, List<V> values) {
14-
this.fieldName = fieldName;
13+
super(fieldName);
1514
this.values = values;
1615
}
1716

18-
public String getFieldName() {
19-
return fieldName;
20-
}
21-
2217
public List<V> getValues() {
2318
return values;
2419
}
25-
}
20+
}

client-java/controller/src/main/java/org/evomaster/client/java/controller/mongo/operations/JsonSchemaOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Represent $jsonSchema operation.
55
* Matches documents that satisfy the specified JSON Schema.
66
*/
7-
public class JsonSchemaOperation extends QueryOperation{
7+
public class JsonSchemaOperation extends QueryOperation {
88
private final Object schema;
99

1010
public JsonSchemaOperation(Object schema) {
@@ -14,4 +14,4 @@ public JsonSchemaOperation(Object schema) {
1414
public Object getSchema() {
1515
return schema;
1616
}
17-
}
17+
}

0 commit comments

Comments
 (0)