6868 * .kind(kind)
6969 * .projection(Projection.property("age"), Projection.first("name"))
7070 * .filter(PropertyFilter.gt("age", 18))
71- * .distinct ("age")
71+ * .distinctOn ("age")
7272 * .orderBy(OrderBy.asc("age"))
7373 * .limit(10)
7474 * .build();
@@ -532,7 +532,6 @@ static class BaseBuilder<V, B extends BaseBuilder<V, B>> {
532532 private String kind ;
533533 private final List <String > projection = new LinkedList <>();
534534 private Filter filter ;
535- private boolean distinct = false ;
536535 private final List <String > distinctOn = new LinkedList <>();
537536 private final List <OrderBy > orderBy = new LinkedList <>();
538537 private Cursor startCursor ;
@@ -620,30 +619,18 @@ B addProjection(String projection, String... others) {
620619 return self ();
621620 }
622621
623- B clearDistinct () {
622+ B clearDistinctOn () {
624623 distinctOn .clear ();
625- distinct = false ;
626624 return self ();
627625 }
628626
629- B distinct (String ... properties ) {
630- clearDistinct ();
631- if (properties .length == 0 ) {
632- clearDistinct ();
633- this .distinct = true ;
634- this .distinctOn .addAll (this .projection );
635- } else if (properties .length == 1 ) {
636- addDistinct (properties [0 ]);
637- } else {
638- addDistinct (properties [0 ], Arrays .copyOfRange (properties , 1 , properties .length ));
639- }
627+ B distinctOn (String property , String ... others ) {
628+ clearDistinctOn ();
629+ addDistinctOn (property , others );
640630 return self ();
641631 }
642632
643- B addDistinct (String property , String ... others ) {
644- if (this .distinct ) {
645- throw new IllegalStateException ("\" distinct()\" is currently set." );
646- }
633+ B addDistinctOn (String property , String ... others ) {
647634 this .distinctOn .add (property );
648635 Collections .addAll (this .distinctOn , others );
649636 return self ();
@@ -677,7 +664,7 @@ B mergeFrom(com.google.datastore.v1beta3.Query queryPb) {
677664 addProjection (projectionPb .getProperty ().getName ());
678665 }
679666 for (com .google .datastore .v1beta3 .PropertyReference distinctOnPb : queryPb .getDistinctOnList ()) {
680- addDistinct (distinctOnPb .getName ());
667+ addDistinctOn (distinctOnPb .getName ());
681668 }
682669 return self ();
683670 }
@@ -717,7 +704,7 @@ public static final class KeyQueryBuilder extends BaseBuilder<Key, KeyQueryBuild
717704 protected KeyQueryBuilder mergeFrom (com .google .datastore .v1beta3 .Query queryPb ) {
718705 super .mergeFrom (queryPb );
719706 projection (KEY_PROPERTY_NAME );
720- clearDistinct ();
707+ clearDistinctOn ();
721708 return this ;
722709 }
723710
@@ -755,18 +742,18 @@ public ProjectionEntityQueryBuilder addProjection(String projection, String... o
755742 }
756743
757744 @ Override
758- public ProjectionEntityQueryBuilder clearDistinct () {
759- return super .clearDistinct ();
745+ public ProjectionEntityQueryBuilder clearDistinctOn () {
746+ return super .clearDistinctOn ();
760747 }
761748
762749 @ Override
763- public ProjectionEntityQueryBuilder distinct (String ... properties ) {
764- return super .distinct ( properties );
750+ public ProjectionEntityQueryBuilder distinctOn (String property , String ... others ) {
751+ return super .distinctOn ( property , others );
765752 }
766753
767754 @ Override
768- public ProjectionEntityQueryBuilder addDistinct (String property , String ... others ) {
769- return super .addDistinct (property , others );
755+ public ProjectionEntityQueryBuilder addDistinctOn (String property , String ... others ) {
756+ return super .addDistinctOn (property , others );
770757 }
771758 }
772759
@@ -786,7 +773,7 @@ public ProjectionEntityQueryBuilder addDistinct(String property, String... other
786773 @ Override
787774 public int hashCode () {
788775 return Objects .hash (namespace (), kind , startCursor , endCursor , offset , limit , filter , orderBy ,
789- distinct ());
776+ distinctOn ());
790777 }
791778
792779 @ Override
@@ -827,7 +814,7 @@ public Filter filter() {
827814 return filter ;
828815 }
829816
830- public List <String > distinct () {
817+ public List <String > distinctOn () {
831818 return distinctOn ;
832819 }
833820
0 commit comments