Skip to content

Commit df6a738

Browse files
issue #1421 fix for typos
1 parent be33b70 commit df6a738

2 files changed

Lines changed: 23 additions & 29 deletions

File tree

querydsl-libraries/querydsl-mongodb/src/main/java/com/querydsl/mongodb/MongodbSerializer.java

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
*/
1414
package com.querydsl.mongodb;
1515

16-
import com.mongodb.*;
16+
import com.mongodb.BasicDBList;
17+
import com.mongodb.BasicDBObject;
18+
import com.mongodb.DBObject;
19+
import com.mongodb.DBRef;
1720
import com.querydsl.core.types.Constant;
1821
import com.querydsl.core.types.Expression;
1922
import com.querydsl.core.types.ExpressionUtils;
@@ -30,6 +33,7 @@
3033
import com.querydsl.core.types.TemplateExpression;
3134
import com.querydsl.core.types.Visitor;
3235
import java.util.*;
36+
import java.util.function.*;
3337
import java.util.regex.Pattern;
3438
import org.bson.BSONObject;
3539
import org.bson.conversions.Bson;
@@ -194,7 +198,7 @@ protected DBObject asDBObjectOrExpressionBetween(Operation<?> expr) {
194198
}
195199
}
196200

197-
protected DBObject asDBObjectOrExpresson(String op, Operation<?> expr) {
201+
protected DBObject asDBObjectOrExpression(String op, Operation<?> expr) {
198202
if (expr.getArg(1) instanceof Constant<?>) { // preferred if constant for better performance
199203
return asDBObject(asDBKey(expr, 0), asDBObject(op, asDBValue(expr, 1)));
200204
} else {
@@ -217,22 +221,14 @@ private enum STRING_MATCH_TYPE {
217221
MATCHES;
218222

219223
public Function<Object, List<?>> toRegex() {
220-
return s -> {
221-
switch (this) {
222-
case STARTS_WITH:
223-
return List.of("^", s);
224-
case ENDS_WITH:
225-
return List.of("", s, "\\$");
226-
case EQUALS:
227-
return List.of("^", s, "\\$");
228-
case CONTAINS:
229-
return List.of(".*", s, ".*");
230-
case MATCHES:
231-
return List.of(s);
232-
default:
233-
throw new IllegalArgumentException("Unknown match type: " + this);
234-
}
235-
};
224+
return s ->
225+
switch (this) {
226+
case STARTS_WITH -> List.of("^", s);
227+
case ENDS_WITH -> List.of("", s, "\\$");
228+
case EQUALS -> List.of("^", s, "\\$");
229+
case CONTAINS -> List.of(".*", s, ".*");
230+
case MATCHES -> List.of(s);
231+
};
236232
}
237233
}
238234

@@ -257,18 +253,16 @@ private BasicDBObject createRegexMatch(
257253
public Object visit(Operation<?> expr, Void context) {
258254
var op = expr.getOperator();
259255
if (op == Ops.EQ) {
260-
if (expr.getArg(0) instanceof Operation) {
261-
Operation<?> lhs = (Operation<?>) expr.getArg(0);
256+
if (expr.getArg(0) instanceof Operation<?> lhs) {
262257
if (lhs.getOperator() == Ops.COL_SIZE || lhs.getOperator() == Ops.ARRAY_SIZE) {
263258
return asDBObject(asDBKey(lhs, 0), asDBObject("$size", asDBValue(expr, 1)));
264259
} else {
265260
throw new UnsupportedOperationException("Illegal operation " + expr);
266261
}
267-
} else if (expr.getArg(0) instanceof Path) {
268-
Path<?> path = (Path<?>) expr.getArg(0);
262+
} else if (expr.getArg(0) instanceof Path<?> path) {
269263
Object constant = expr.getArg(1);
270-
if (constant instanceof Constant<?> constatntValue) {
271-
return asDBObject(asDBKey(expr, 0), convert(path, constatntValue));
264+
if (constant instanceof Constant<?> constantValue) {
265+
return asDBObject(asDBKey(expr, 0), convert(path, constantValue));
272266
} else {
273267
Object rightField = MONGO_EXPR_SYMBOL + asDBKey(expr, 1);
274268
Object leftField = MONGO_EXPR_SYMBOL + asDBKey(expr, 0);
@@ -439,15 +433,15 @@ public Object visit(Operation<?> expr, Void context) {
439433
return asDBObject("$or", list);
440434

441435
} else if (op == Ops.LT) {
442-
return asDBObjectOrExpresson("$lt", expr);
436+
return asDBObjectOrExpression("$lt", expr);
443437

444438
} else if (op == Ops.GT) {
445-
return asDBObjectOrExpresson("$gt", expr);
439+
return asDBObjectOrExpression("$gt", expr);
446440

447441
} else if (op == Ops.LOE) {
448-
return asDBObjectOrExpresson("$lte", expr);
442+
return asDBObjectOrExpression("$lte", expr);
449443
} else if (op == Ops.GOE) {
450-
return asDBObjectOrExpresson("$gte", expr);
444+
return asDBObjectOrExpression("$gte", expr);
451445

452446
} else if (op == Ops.IS_NULL) {
453447
return asDBObject(asDBKey(expr, 0), asDBObject("$exists", false));

querydsl-libraries/querydsl-mongodb/src/test/java/com/querydsl/mongodb/MongoExpressionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ public void minStock_or_test() {
362362
}
363363

364364
@Test
365-
public void desctription_eq_constant() {
365+
public void description_eq_constant() {
366366
List<Product> results = query().where(product.shotDesc.eq("Lux")).fetch();
367367
long expected = data.stream().filter(p -> "Lux".equals(p.getShotDesc())).count();
368368
assertEquals((int) expected, results.size());

0 commit comments

Comments
 (0)