@@ -286,10 +286,113 @@ public DocumentExpression unsetField(final String fieldName) {
286
286
/** @see Expression */
287
287
288
288
@ Override
289
- public <Q extends Expression , R extends Expression > R apply (final Function <Q , R > f ) {
289
+ public <R extends Expression > R passTo (final Function <? super Expression , R > f ) {
290
290
return f .apply (this .assertImplementsAllExpressions ());
291
291
}
292
292
293
+ @ Override
294
+ public <R extends Expression > R switchOn (final Function <Branches , ? extends BranchesTerminal <? super Expression , R >> switchMap ) {
295
+ return switchMapInternal (this .assertImplementsAllExpressions (), switchMap .apply (new Branches ()));
296
+ }
297
+
298
+ @ Override
299
+ public <R extends Expression > R passBooleanTo (final Function <? super BooleanExpression , R > f ) {
300
+ return f .apply (this .assertImplementsAllExpressions ());
301
+ }
302
+
303
+ @ Override
304
+ public <R extends Expression > R switchBooleanOn (final Function <Branches , ? extends BranchesTerminal <? super BooleanExpression , R >> switchMap ) {
305
+ return switchMapInternal (this .assertImplementsAllExpressions (), switchMap .apply (new Branches ()));
306
+ }
307
+
308
+ @ Override
309
+ public <R extends Expression > R passIntegerTo (final Function <? super IntegerExpression , R > f ) {
310
+ return f .apply (this .assertImplementsAllExpressions ());
311
+ }
312
+
313
+ @ Override
314
+ public <R extends Expression > R switchIntegerOn (final Function <Branches , ? extends BranchesTerminal <? super IntegerExpression , R >> switchMap ) {
315
+ return switchMapInternal (this .assertImplementsAllExpressions (), switchMap .apply (new Branches ()));
316
+ }
317
+
318
+ @ Override
319
+ public <R extends Expression > R passNumberTo (final Function <? super NumberExpression , R > f ) {
320
+ return f .apply (this .assertImplementsAllExpressions ());
321
+ }
322
+
323
+ @ Override
324
+ public <R extends Expression > R switchNumberOn (final Function <Branches , ? extends BranchesTerminal <? super NumberExpression , R >> switchMap ) {
325
+ return switchMapInternal (this .assertImplementsAllExpressions (), switchMap .apply (new Branches ()));
326
+ }
327
+
328
+ @ Override
329
+ public <R extends Expression > R passStringTo (final Function <? super StringExpression , R > f ) {
330
+ return f .apply (this .assertImplementsAllExpressions ());
331
+ }
332
+
333
+ @ Override
334
+ public <R extends Expression > R switchStringOn (final Function <Branches , ? extends BranchesTerminal <? super StringExpression , R >> switchMap ) {
335
+ return switchMapInternal (this .assertImplementsAllExpressions (), switchMap .apply (new Branches ()));
336
+ }
337
+
338
+ @ Override
339
+ public <R extends Expression > R passDateTo (final Function <? super DateExpression , R > f ) {
340
+ return f .apply (this .assertImplementsAllExpressions ());
341
+ }
342
+
343
+ @ Override
344
+ public <R extends Expression > R switchDateOn (final Function <Branches , ? extends BranchesTerminal <? super DateExpression , R >> switchMap ) {
345
+ return switchMapInternal (this .assertImplementsAllExpressions (), switchMap .apply (new Branches ()));
346
+ }
347
+
348
+ @ Override
349
+ public <R extends Expression > R passArrayTo (final Function <? super ArrayExpression <T >, R > f ) {
350
+ return f .apply (this .assertImplementsAllExpressions ());
351
+ }
352
+
353
+ @ Override
354
+ public <R extends Expression > R switchArrayOn (final Function <Branches , ? extends BranchesTerminal <? super ArrayExpression <T >, R >> switchMap ) {
355
+ return switchMapInternal (this .assertImplementsAllExpressions (), switchMap .apply (new Branches ()));
356
+ }
357
+
358
+ @ Override
359
+ public <R extends Expression > R passMapTo (final Function <? super MapExpression <T >, R > f ) {
360
+ return f .apply (this .assertImplementsAllExpressions ());
361
+ }
362
+
363
+ @ Override
364
+ public <R extends Expression > R switchMapOn (final Function <Branches , ? extends BranchesTerminal <? super MapExpression <T >, R >> switchMap ) {
365
+ return switchMapInternal (this .assertImplementsAllExpressions (), switchMap .apply (new Branches ()));
366
+ }
367
+
368
+ @ Override
369
+ public <R extends Expression > R passDocumentTo (final Function <? super DocumentExpression , R > f ) {
370
+ return f .apply (this .assertImplementsAllExpressions ());
371
+ }
372
+
373
+ @ Override
374
+ public <R extends Expression > R switchDocumentOn (final Function <Branches , ? extends BranchesTerminal <? super DocumentExpression , R >> switchMap ) {
375
+ return switchMapInternal (this .assertImplementsAllExpressions (), switchMap .apply (new Branches ()));
376
+ }
377
+
378
+ private <T0 extends Expression , R0 extends Expression > R0 switchMapInternal (
379
+ final T0 value , final BranchesTerminal <T0 , R0 > construct ) {
380
+ return newMqlExpression ((cr ) -> {
381
+ BsonArray branches = new BsonArray ();
382
+ for (Function <T0 , SwitchCase <R0 >> fn : construct .getBranches ()) {
383
+ SwitchCase <R0 > result = fn .apply (value );
384
+ branches .add (new BsonDocument ()
385
+ .append ("case" , extractBsonValue (cr , result .getCaseValue ()))
386
+ .append ("then" , extractBsonValue (cr , result .getThenValue ())));
387
+ }
388
+ BsonDocument switchBson = new BsonDocument ().append ("branches" , branches );
389
+ if (construct .getDefaults () != null ) {
390
+ switchBson = switchBson .append ("default" , extractBsonValue (cr , construct .getDefaults ().apply (value )));
391
+ }
392
+ return astDoc ("$switch" , switchBson );
393
+ });
394
+ }
395
+
293
396
@ Override
294
397
public BooleanExpression eq (final Expression eq ) {
295
398
return new MqlExpression <>(ast ("$eq" , eq ));
@@ -422,32 +525,6 @@ private Function<CodecRegistry, AstPlaceholder> convertInternal(final String to,
422
525
.append ("to" , new BsonString (to )));
423
526
}
424
527
425
- @ Override
426
- public <T0 extends Expression , R0 extends Expression > R0 switchMap (
427
- final Function <Branches , BranchesTerminal <T0 , R0 >> switchMap ) {
428
- T0 value = this .assertImplementsAllExpressions ();
429
- BranchesTerminal <T0 , R0 > construct = switchMap .apply (new Branches ());
430
- return switchMapInternal (value , construct );
431
- }
432
-
433
- private <T0 extends Expression , R0 extends Expression > R0 switchMapInternal (
434
- final T0 value , final BranchesTerminal <T0 , R0 > construct ) {
435
- return newMqlExpression ((cr ) -> {
436
- BsonArray branches = new BsonArray ();
437
- for (Function <T0 , SwitchCase <R0 >> fn : construct .getBranches ()) {
438
- SwitchCase <R0 > result = fn .apply (value );
439
- branches .add (new BsonDocument ()
440
- .append ("case" , extractBsonValue (cr , result .getCaseValue ()))
441
- .append ("then" , extractBsonValue (cr , result .getThenValue ())));
442
- }
443
- BsonDocument switchBson = new BsonDocument ().append ("branches" , branches );
444
- if (construct .getDefaults () != null ) {
445
- switchBson = switchBson .append ("default" , extractBsonValue (cr , construct .getDefaults ().apply (value )));
446
- }
447
- return astDoc ("$switch" , switchBson );
448
- });
449
- }
450
-
451
528
@ Override
452
529
public IntegerExpression parseInteger () {
453
530
Expression asLong = new MqlExpression <>(ast ("$toLong" ));
0 commit comments