1313 */
1414package 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 ;
1720import com .querydsl .core .types .Constant ;
1821import com .querydsl .core .types .Expression ;
1922import com .querydsl .core .types .ExpressionUtils ;
3033import com .querydsl .core .types .TemplateExpression ;
3134import com .querydsl .core .types .Visitor ;
3235import java .util .*;
36+ import java .util .function .*;
3337import java .util .regex .Pattern ;
3438import org .bson .BSONObject ;
3539import 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 ));
0 commit comments