@@ -255,7 +255,7 @@ Long geoSearchStore(byte[] destKey, byte[] key, GeoReference<byte[]> reference,
255255 *
256256 * @since 2.6
257257 */
258- interface GeoShape {
258+ interface GeoShape extends Shape {
259259
260260 /**
261261 * Create a shape used as predicate for geo queries from a {@link Distance radius} around the query center point.
@@ -350,17 +350,44 @@ public Metric getMetric() {
350350 }
351351 }
352352
353+ interface GeoCommandArgs {
354+
355+ @ Nullable
356+ public Direction getSortDirection ();
357+
358+ @ Nullable
359+ Long getLimit ();
360+
361+ Set <? extends GeoCommandFlag > getFlags ();
362+
363+ default boolean hasLimit () {
364+ return getLimit () != null ;
365+ }
366+
367+ default boolean hasSortDirection () {
368+ return getSortDirection () != null ;
369+ }
370+
371+ default boolean hasFlags () {
372+ return !getFlags ().isEmpty ();
373+ }
374+
375+ public interface GeoCommandFlag {}
376+ }
377+
353378 /**
354379 * Additional arguments (like count/sort/...) to be used with {@link RedisGeoCommands}.
355380 *
356381 * @author Mark Paluch
357382 * @since 2.6
358383 */
359- class GeoSearchCommandArgs implements Cloneable {
384+ class GeoSearchCommandArgs implements GeoCommandArgs , Cloneable {
385+
386+ protected final Set <Flag > flags = new LinkedHashSet <>(2 , 1 );
360387
361- Set < Flag > flags = new LinkedHashSet <>( 2 , 1 ) ;
362- @ Nullable Long limit ;
363- @ Nullable Direction sortDirection ;
388+ @ Nullable protected Long limit ;
389+
390+ @ Nullable protected Direction sortDirection ;
364391
365392 private GeoSearchCommandArgs () {}
366393
@@ -433,10 +460,7 @@ public GeoSearchCommandArgs sortDescending() {
433460 * @return never {@literal null}.
434461 */
435462 public GeoSearchCommandArgs limit (long count ) {
436-
437- Assert .isTrue (count > 0 , "Count has to positive value." );
438- limit = count ;
439- return this ;
463+ return limit (count , false );
440464 }
441465
442466 /**
@@ -450,7 +474,9 @@ public GeoSearchCommandArgs limit(long count, boolean any) {
450474
451475 Assert .isTrue (count > 0 , "Count has to positive value." );
452476 limit = count ;
453- flags .add (Flag .ANY );
477+ if (any ) {
478+ flags .add (Flag .ANY );
479+ }
454480 return this ;
455481 }
456482
@@ -477,30 +503,18 @@ public Direction getSortDirection() {
477503 return sortDirection ;
478504 }
479505
480- public boolean hasFlags () {
481- return !flags .isEmpty ();
482- }
483-
484- public boolean hasSortDirection () {
485- return sortDirection != null ;
486- }
487-
488- public boolean hasLimit () {
489- return limit != null ;
490- }
491-
492506 public boolean hasAnyLimit () {
493507 return hasLimit () && flags .contains (Flag .ANY );
494508 }
495509
496510 @ Override
497511 protected GeoSearchCommandArgs clone () {
498512
499- GeoSearchCommandArgs tmp = new GeoSearchCommandArgs ();
500- tmp .flags = this . flags != null ? new LinkedHashSet <> (this .flags ) : new LinkedHashSet <>( 2 );
501- tmp .limit = this .limit ;
502- tmp .sortDirection = this .sortDirection ;
503- return tmp ;
513+ GeoSearchCommandArgs that = new GeoSearchCommandArgs ();
514+ that .flags . addAll (this .flags );
515+ that .limit = this .limit ;
516+ that .sortDirection = this .sortDirection ;
517+ return that ;
504518 }
505519 }
506520
@@ -510,11 +524,13 @@ protected GeoSearchCommandArgs clone() {
510524 * @author Mark Paluch
511525 * @since 2.6
512526 */
513- class GeoSearchStoreCommandArgs implements Cloneable {
527+ class GeoSearchStoreCommandArgs implements GeoCommandArgs , Cloneable {
528+
529+ private final Set <Flag > flags = new LinkedHashSet <>(2 , 1 );
514530
515- Set < Flag > flags = new LinkedHashSet <>( 2 , 1 ) ;
516- @ Nullable Long limit ;
517- @ Nullable Direction sortDirection ;
531+ @ Nullable private Long limit ;
532+
533+ @ Nullable private Direction sortDirection ;
518534
519535 private GeoSearchStoreCommandArgs () {}
520536
@@ -576,10 +592,7 @@ public GeoSearchStoreCommandArgs sortDescending() {
576592 * @return never {@literal null}.
577593 */
578594 public GeoSearchStoreCommandArgs limit (long count ) {
579-
580- Assert .isTrue (count > 0 , "Count has to positive value." );
581- limit = count ;
582- return this ;
595+ return limit (count , false );
583596 }
584597
585598 /**
@@ -592,8 +605,10 @@ public GeoSearchStoreCommandArgs limit(long count) {
592605 public GeoSearchStoreCommandArgs limit (long count , boolean any ) {
593606
594607 Assert .isTrue (count > 0 , "Count has to positive value." );
595- limit = count ;
596- flags .add (Flag .ANY );
608+ this .limit = count ;
609+ if (any ) {
610+ flags .add (Flag .ANY );
611+ }
597612 return this ;
598613 }
599614
@@ -624,26 +639,18 @@ public boolean isStoreDistance() {
624639 return flags .contains (Flag .STOREDIST );
625640 }
626641
627- public boolean hasSortDirection () {
628- return sortDirection != null ;
629- }
630-
631- public boolean hasLimit () {
632- return limit != null ;
633- }
634-
635642 public boolean hasAnyLimit () {
636643 return hasLimit () && flags .contains (Flag .ANY );
637644 }
638645
639646 @ Override
640647 protected GeoSearchStoreCommandArgs clone () {
641648
642- GeoSearchStoreCommandArgs tmp = new GeoSearchStoreCommandArgs ();
643- tmp .flags = this . flags != null ? new LinkedHashSet <> (this .flags ) : new LinkedHashSet <>( 2 );
644- tmp .limit = this .limit ;
645- tmp .sortDirection = this .sortDirection ;
646- return tmp ;
649+ GeoSearchStoreCommandArgs that = new GeoSearchStoreCommandArgs ();
650+ that .flags . addAll (this .flags );
651+ that .limit = this .limit ;
652+ that .sortDirection = this .sortDirection ;
653+ return that ;
647654 }
648655 }
649656
@@ -729,18 +736,18 @@ public GeoRadiusCommandArgs limit(long count) {
729736 return this ;
730737 }
731738
732- public enum Flag {
739+ public enum Flag implements GeoCommandFlag {
733740 WITHCOORD , WITHDIST , ANY , STOREDIST
734741 }
735742
736743 @ Override
737744 protected GeoRadiusCommandArgs clone () {
738745
739- GeoRadiusCommandArgs tmp = new GeoRadiusCommandArgs ();
740- tmp .flags = this . flags != null ? new LinkedHashSet <> (this .flags ) : new LinkedHashSet <>( 2 );
741- tmp .limit = this .limit ;
742- tmp .sortDirection = this .sortDirection ;
743- return tmp ;
746+ GeoRadiusCommandArgs that = new GeoRadiusCommandArgs ();
747+ that .flags . addAll (this .flags );
748+ that .limit = this .limit ;
749+ that .sortDirection = this .sortDirection ;
750+ return that ;
744751 }
745752 }
746753
0 commit comments