Skip to content

Commit 45e1030

Browse files
authored
Re-write API javadocs for COUNT API (#4143)
1 parent 6a0c610 commit 45e1030

File tree

4 files changed

+84
-27
lines changed

4 files changed

+84
-27
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/AggregateQuery.java

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,31 @@
2121
import com.google.firebase.firestore.util.Preconditions;
2222

2323
/**
24-
* A {@code AggregateQuery} computes some aggregation statistics from the result set of a base
25-
* {@link Query}.
24+
* A query that calculates aggregations over an underlying query.
2625
*
2726
* <p><b>Subclassing Note</b>: Cloud Firestore classes are not meant to be subclassed except for use
2827
* in test mocks. Subclassing is not supported in production code and new SDK releases may break
2928
* code that does so.
3029
*/
3130
public class AggregateQuery {
32-
// The base query.
31+
3332
private final Query query;
3433

3534
AggregateQuery(@NonNull Query query) {
3635
this.query = query;
3736
}
3837

39-
/** Returns the base {@link Query} for this aggregate query. */
38+
/** Returns the query whose aggregations will be calculated by this object. */
4039
@NonNull
4140
public Query getQuery() {
4241
return query;
4342
}
4443

4544
/**
46-
* Executes the aggregate query and returns the results as a {@code AggregateQuerySnapshot}.
45+
* Executes this query.
4746
*
48-
* @param source A value to configure the get behavior.
49-
* @return A Task that will be resolved with the results of the {@code AggregateQuery}.
47+
* @param source The source from which to acquire the aggregate results.
48+
* @return A {@link Task} that will be resolved with the results of the query.
5049
*/
5150
@NonNull
5251
public Task<AggregateQuerySnapshot> get(@NonNull AggregateSource source) {
@@ -70,14 +69,35 @@ public Task<AggregateQuerySnapshot> get(@NonNull AggregateSource source) {
7069
return tcs.getTask();
7170
}
7271

72+
/**
73+
* Compares this object with the given object for equality.
74+
*
75+
* <p>This object is considered "equal" to the other object if and only if all of the following
76+
* conditions are satisfied:
77+
*
78+
* <ol>
79+
* <li>{@code object} is a non-null instance of {@link AggregateQuery}.
80+
* <li>{@code object} performs the same aggregations as this {@link AggregateQuery}.
81+
* <li>The underlying {@link Query} of {@code object} compares equal to that of this object.
82+
* </ol>
83+
*
84+
* @param object The object to compare to this object for equality.
85+
* @return {@code true} if this object is "equal" to the given object, as defined above, or {@code
86+
* false} otherwise.
87+
*/
7388
@Override
74-
public boolean equals(Object o) {
75-
if (this == o) return true;
76-
if (!(o instanceof AggregateQuery)) return false;
77-
AggregateQuery that = (AggregateQuery) o;
78-
return query.equals(that.query);
89+
public boolean equals(Object object) {
90+
if (this == object) return true;
91+
if (!(object instanceof AggregateQuery)) return false;
92+
AggregateQuery other = (AggregateQuery) object;
93+
return query.equals(other.query);
7994
}
8095

96+
/**
97+
* Calculates and returns the hash code for this object.
98+
*
99+
* @return the hash code for this object.
100+
*/
81101
@Override
82102
public int hashCode() {
83103
return query.hashCode();

firebase-firestore/src/main/java/com/google/firebase/firestore/AggregateQuerySnapshot.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.util.Objects;
2121

2222
/**
23-
* A {@code AggregateQuerySnapshot} contains results of a {@link AggregateQuery}.
23+
* The results of executing an {@link AggregateQuery}.
2424
*
2525
* <p><b>Subclassing Note</b>: Cloud Firestore classes are not meant to be subclassed except for use
2626
* in test mocks. Subclassing is not supported in production code and new SDK releases may break
@@ -37,25 +37,46 @@ public class AggregateQuerySnapshot {
3737
this.count = count;
3838
}
3939

40-
/** @return The original {@link AggregateQuery} this snapshot is a result of. */
40+
/** Returns the query that was executed to produce this result. */
4141
@NonNull
4242
public AggregateQuery getQuery() {
4343
return query;
4444
}
4545

46-
/** @return The result of a document count aggregation. */
46+
/** Returns the number of documents in the result set of the underlying query. */
4747
public long getCount() {
4848
return count;
4949
}
5050

51+
/**
52+
* Compares this object with the given object for equality.
53+
*
54+
* <p>This object is considered "equal" to the other object if and only if all of the following
55+
* conditions are satisfied:
56+
*
57+
* <ol>
58+
* <li>{@code object} is a non-null instance of {@link AggregateQuerySnapshot}.
59+
* <li>The {@link AggregateQuery} of {@code object} compares equal to that of this object.
60+
* <li>{@code object} has the same results as this object.
61+
* </ol>
62+
*
63+
* @param object The object to compare to this object for equality.
64+
* @return {@code true} if this object is "equal" to the given object, as defined above, or {@code
65+
* false} otherwise.
66+
*/
5167
@Override
52-
public boolean equals(Object o) {
53-
if (this == o) return true;
54-
if (!(o instanceof AggregateQuerySnapshot)) return false;
55-
AggregateQuerySnapshot snapshot = (AggregateQuerySnapshot) o;
56-
return count == snapshot.count && query.equals(snapshot.query);
68+
public boolean equals(Object object) {
69+
if (this == object) return true;
70+
if (!(object instanceof AggregateQuerySnapshot)) return false;
71+
AggregateQuerySnapshot other = (AggregateQuerySnapshot) object;
72+
return count == other.count && query.equals(other.query);
5773
}
5874

75+
/**
76+
* Calculates and returns the hash code for this object.
77+
*
78+
* @return the hash code for this object.
79+
*/
5980
@Override
6081
public int hashCode() {
6182
return Objects.hash(count, query);

firebase-firestore/src/main/java/com/google/firebase/firestore/AggregateSource.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,23 @@
1414

1515
package com.google.firebase.firestore;
1616

17-
/** Configures the behavior of {@link AggregateQuery#get}. */
17+
/**
18+
* The sources from which an {@link AggregateQuery} can retrieve its results.
19+
*
20+
* @see AggregateQuery#get
21+
*/
1822
public enum AggregateSource {
1923
/**
20-
* Reach to the Firestore backend and surface the result verbatim, that is no local documents or
21-
* mutations in the SDK cache will be included in the surfaced result.
24+
* Perform the aggregation on the server and download the result.
2225
*
23-
* <p>Requires client to be online.
26+
* <p>The result received from the server is presented, unaltered, without considering any local
27+
* state. That is, documents in the local cache are not taken into consideration, neither are
28+
* local modifications not yet synchronized with the server. Previously-downloaded results, if
29+
* any, are not used: every request using this source necessarily involves a round trip to the
30+
* server.
31+
*
32+
* <p>The {@link AggregateQuery} will fail if the server cannot be reached, such as if the client
33+
* is offline.
2434
*/
2535
SERVER,
2636
}

firebase-firestore/src/main/java/com/google/firebase/firestore/Query.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,10 +1224,16 @@ private void validateHasExplicitOrderByForLimitToLast() {
12241224
}
12251225

12261226
/**
1227-
* Creates an {@link AggregateQuery} counting the number of documents matching this query.
1227+
* Returns a query that counts the documents in the result set of this query.
12281228
*
1229-
* @return An {@link AggregateQuery} object that can be used to count the number of documents in
1230-
* the result set of this query.
1229+
* <p>The returned query, when executed, counts the documents in the result set of this query
1230+
* <em>without actually downloading the documents</em>.
1231+
*
1232+
* <p>Using the returned query to count the documents is efficient because only the final count,
1233+
* not the documents' data, is downloaded. The returned query can even count the documents if the
1234+
* result set would be prohibitively large to download entirely (e.g. thousands of documents).
1235+
*
1236+
* @return a query that counts the documents in the result set of this query.
12311237
*/
12321238
@NonNull
12331239
public AggregateQuery count() {

0 commit comments

Comments
 (0)