@@ -290,10 +290,8 @@ public void run() {
290
290
*/
291
291
@ NonNull
292
292
public Query startAfter (@ Nullable String value ) {
293
- if (value != null && params .getIndex ().equals (KeyIndex .getInstance ())) {
294
- return startAt (PushIdGenerator .successor (value ));
295
- }
296
- return startAt (value , ChildKey .getMaxName ().asString ());
293
+ Node node = value != null ? new StringNode (value , PriorityUtilities .NullPriority ()) : EmptyNode .Empty ();
294
+ return startAfter (node , null );
297
295
}
298
296
299
297
/**
@@ -306,7 +304,7 @@ public Query startAfter(@Nullable String value) {
306
304
*/
307
305
@ NonNull
308
306
public Query startAfter (double value ) {
309
- return startAt ( value , ChildKey . getMaxName (). asString () );
307
+ return startAfter ( new DoubleNode ( value , PriorityUtilities . NullPriority ()), null );
310
308
}
311
309
312
310
/**
@@ -319,7 +317,7 @@ public Query startAfter(double value) {
319
317
*/
320
318
@ NonNull
321
319
public Query startAfter (boolean value ) {
322
- return startAt ( value , ChildKey . getMaxName (). asString () );
320
+ return startAfter ( new BooleanNode ( value , PriorityUtilities . NullPriority ()), null );
323
321
}
324
322
325
323
/**
@@ -334,9 +332,6 @@ public Query startAfter(boolean value) {
334
332
*/
335
333
@ NonNull
336
334
public Query startAfter (@ Nullable String value , @ Nullable String key ) {
337
- if (value != null && params .getIndex ().equals (KeyIndex .getInstance ())) {
338
- value = PushIdGenerator .successor (value );
339
- }
340
335
Node node =
341
336
value != null ? new StringNode (value , PriorityUtilities .NullPriority ()) : EmptyNode .Empty ();
342
337
return startAfter (node , key );
@@ -373,7 +368,7 @@ public Query startAfter(boolean value, @Nullable String key) {
373
368
}
374
369
375
370
private Query startAfter (Node node , String key ) {
376
- return startAt (node , PushIdGenerator . successor ( key ) );
371
+ return startAt (node , key , false );
377
372
}
378
373
379
374
/**
@@ -426,7 +421,7 @@ public Query startAt(boolean value) {
426
421
public Query startAt (@ Nullable String value , @ Nullable String key ) {
427
422
Node node =
428
423
value != null ? new StringNode (value , PriorityUtilities .NullPriority ()) : EmptyNode .Empty ();
429
- return startAt (node , key );
424
+ return startAt (node , key , true );
430
425
}
431
426
432
427
/**
@@ -440,7 +435,7 @@ public Query startAt(@Nullable String value, @Nullable String key) {
440
435
*/
441
436
@ NonNull
442
437
public Query startAt (double value , @ Nullable String key ) {
443
- return startAt (new DoubleNode (value , PriorityUtilities .NullPriority ()), key );
438
+ return startAt (new DoubleNode (value , PriorityUtilities .NullPriority ()), key , true );
444
439
}
445
440
446
441
/**
@@ -455,10 +450,10 @@ public Query startAt(double value, @Nullable String key) {
455
450
*/
456
451
@ NonNull
457
452
public Query startAt (boolean value , @ Nullable String key ) {
458
- return startAt (new BooleanNode (value , PriorityUtilities .NullPriority ()), key );
453
+ return startAt (new BooleanNode (value , PriorityUtilities .NullPriority ()), key , true );
459
454
}
460
455
461
- private Query startAt (Node node , String key ) {
456
+ private Query startAt (Node node , String key , Boolean isInclusive ) {
462
457
Validation .validateNullableKey (key );
463
458
if (!(node .isLeafNode () || node .isEmpty ())) {
464
459
throw new IllegalArgumentException (
@@ -478,7 +473,7 @@ private Query startAt(Node node, String key) {
478
473
childKey = ChildKey .fromString (key );
479
474
}
480
475
}
481
- QueryParams newParams = params .startAt (node , childKey );
476
+ QueryParams newParams = isInclusive ? params .startAt ( node , childKey ) : params . startAfter (node , childKey );
482
477
validateLimit (newParams );
483
478
validateQueryEndpoints (newParams );
484
479
hardAssert (newParams .isValid ());
@@ -495,10 +490,7 @@ private Query startAt(Node node, String key) {
495
490
*/
496
491
@ NonNull
497
492
public Query endBefore (@ Nullable String value ) {
498
- if (value != null && params .getIndex ().equals (KeyIndex .getInstance ())) {
499
- return endAt (PushIdGenerator .predecessor (value ));
500
- }
501
- return endAt (value , ChildKey .getMinName ().asString ());
493
+ return endBefore (value , null );
502
494
}
503
495
504
496
/**
@@ -511,7 +503,7 @@ public Query endBefore(@Nullable String value) {
511
503
*/
512
504
@ NonNull
513
505
public Query endBefore (double value ) {
514
- return endAt (value , ChildKey . getMinName (). asString () );
506
+ return endAt (value , null );
515
507
}
516
508
517
509
/**
@@ -524,7 +516,7 @@ public Query endBefore(double value) {
524
516
*/
525
517
@ NonNull
526
518
public Query endBefore (boolean value ) {
527
- return endAt (value , ChildKey . getMinName (). asString () );
519
+ return endBefore (value , null );
528
520
}
529
521
530
522
/**
@@ -539,9 +531,6 @@ public Query endBefore(boolean value) {
539
531
*/
540
532
@ NonNull
541
533
public Query endBefore (@ Nullable String value , @ Nullable String key ) {
542
- if (value != null && params .getIndex ().equals (KeyIndex .getInstance ())) {
543
- value = PushIdGenerator .predecessor (value );
544
- }
545
534
Node node =
546
535
value != null ? new StringNode (value , PriorityUtilities .NullPriority ()) : EmptyNode .Empty ();
547
536
return endBefore (node , key );
@@ -578,7 +567,7 @@ public Query endBefore(boolean value, @Nullable String key) {
578
567
}
579
568
580
569
private Query endBefore (Node node , String key ) {
581
- return endAt (node , PushIdGenerator . predecessor ( key ) );
570
+ return endAt (node , key , false );
582
571
}
583
572
584
573
/**
@@ -631,7 +620,7 @@ public Query endAt(boolean value) {
631
620
public Query endAt (@ Nullable String value , @ Nullable String key ) {
632
621
Node node =
633
622
value != null ? new StringNode (value , PriorityUtilities .NullPriority ()) : EmptyNode .Empty ();
634
- return endAt (node , key );
623
+ return endAt (node , key , true );
635
624
}
636
625
637
626
/**
@@ -645,7 +634,7 @@ public Query endAt(@Nullable String value, @Nullable String key) {
645
634
*/
646
635
@ NonNull
647
636
public Query endAt (double value , @ Nullable String key ) {
648
- return endAt (new DoubleNode (value , PriorityUtilities .NullPriority ()), key );
637
+ return endAt (new DoubleNode (value , PriorityUtilities .NullPriority ()), key , true );
649
638
}
650
639
651
640
/**
@@ -660,10 +649,10 @@ public Query endAt(double value, @Nullable String key) {
660
649
*/
661
650
@ NonNull
662
651
public Query endAt (boolean value , @ Nullable String key ) {
663
- return endAt (new BooleanNode (value , PriorityUtilities .NullPriority ()), key );
652
+ return endAt (new BooleanNode (value , PriorityUtilities .NullPriority ()), key , true );
664
653
}
665
654
666
- private Query endAt (Node node , String key ) {
655
+ private Query endAt (Node node , String key , Boolean isInclusive ) {
667
656
Validation .validateNullableKey (key );
668
657
if (!(node .isLeafNode () || node .isEmpty ())) {
669
658
throw new IllegalArgumentException ("Can only use simple values for endAt()" );
@@ -672,7 +661,7 @@ private Query endAt(Node node, String key) {
672
661
if (params .hasEnd ()) {
673
662
throw new IllegalArgumentException ("Can't call endAt() or equalTo() multiple times" );
674
663
}
675
- QueryParams newParams = params .endAt (node , childKey );
664
+ QueryParams newParams = isInclusive ? params .endAt ( node , childKey ) : params . endBefore (node , childKey );
676
665
validateLimit (newParams );
677
666
validateQueryEndpoints (newParams );
678
667
hardAssert (newParams .isValid ());
0 commit comments