Skip to content

Commit 3ea00d1

Browse files
Revert "Adding Equals to the Public API (googleapis#2955)" (googleapis#2964)
This reverts commit 7bafc31.
1 parent 7bafc31 commit 3ea00d1

File tree

16 files changed

+171
-384
lines changed

16 files changed

+171
-384
lines changed

google-cloud-firestore/src/main/java/com/google/cloud/firestore/Blob.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,15 @@ public byte[] toBytes() {
7474
return byteString.toByteArray();
7575
}
7676

77-
/**
78-
* Returns true if this Blob is equal to the provided object.
79-
*
80-
* @param obj The object to compare against.
81-
* @return Whether this Blob is equal to the provided object.
82-
*/
8377
@Override
84-
public boolean equals(Object obj) {
85-
if (this == obj) {
78+
public boolean equals(Object o) {
79+
if (this == o) {
8680
return true;
8781
}
88-
if (obj == null || getClass() != obj.getClass()) {
82+
if (o == null || getClass() != o.getClass()) {
8983
return false;
9084
}
91-
Blob blob = (Blob) obj;
85+
Blob blob = (Blob) o;
9286
return Objects.equals(byteString, blob.byteString);
9387
}
9488

google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentChange.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.google.cloud.firestore;
1818

19-
import java.util.Objects;
2019
import javax.annotation.Nonnull;
2120

2221
/**
@@ -88,30 +87,4 @@ public int getOldIndex() {
8887
public int getNewIndex() {
8988
return newIndex;
9089
}
91-
92-
/**
93-
* Returns true if this DocumentChange is equal to the provided object.
94-
*
95-
* @param obj The object to compare against.
96-
* @return Whether this DocumentChange is equal to the provided object.
97-
*/
98-
@Override
99-
public boolean equals(Object obj) {
100-
if (this == obj) {
101-
return true;
102-
}
103-
if (obj == null || getClass() != obj.getClass()) {
104-
return false;
105-
}
106-
DocumentChange that = (DocumentChange) obj;
107-
return oldIndex == that.oldIndex
108-
&& newIndex == that.newIndex
109-
&& type == that.type
110-
&& Objects.equals(document, that.document);
111-
}
112-
113-
@Override
114-
public int hashCode() {
115-
return Objects.hash(type, document, oldIndex, newIndex);
116-
}
11790
}

google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentReference.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -449,21 +449,15 @@ public String toString() {
449449
return String.format("DocumentReference{path=%s}", path);
450450
}
451451

452-
/**
453-
* Returns true if this DocumentReference is equal to the provided object.
454-
*
455-
* @param obj The object to compare against.
456-
* @return Whether this DocumentReference is equal to the provided object.
457-
*/
458452
@Override
459-
public boolean equals(Object obj) {
460-
if (this == obj) {
453+
public boolean equals(Object o) {
454+
if (this == o) {
461455
return true;
462456
}
463-
if (obj == null || getClass() != obj.getClass()) {
457+
if (o == null || getClass() != o.getClass()) {
464458
return false;
465459
}
466-
DocumentReference that = (DocumentReference) obj;
460+
DocumentReference that = (DocumentReference) o;
467461
return Objects.equals(path, that.path) && Objects.equals(firestore, that.firestore);
468462
}
469463

google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSet.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,57 @@ List<QueryDocumentSnapshot> toList() {
132132
public Iterator<QueryDocumentSnapshot> iterator() {
133133
return sortedSet.iterator();
134134
}
135+
136+
@Override
137+
public boolean equals(Object other) {
138+
if (this == other) {
139+
return true;
140+
}
141+
if (other == null || getClass() != other.getClass()) {
142+
return false;
143+
}
144+
145+
DocumentSet documentSet = (DocumentSet) other;
146+
147+
if (size() != documentSet.size()) {
148+
return false;
149+
}
150+
151+
Iterator<QueryDocumentSnapshot> thisIterator = iterator();
152+
Iterator<QueryDocumentSnapshot> otherIterator = documentSet.iterator();
153+
while (thisIterator.hasNext()) {
154+
DocumentSnapshot thisDoc = thisIterator.next();
155+
DocumentSnapshot otherDoc = otherIterator.next();
156+
if (!thisDoc.equals(otherDoc)) {
157+
return false;
158+
}
159+
}
160+
161+
return true;
162+
}
163+
164+
@Override
165+
public int hashCode() {
166+
int result = 0;
167+
for (DocumentSnapshot document : this) {
168+
result = 31 * result + document.hashCode();
169+
}
170+
return result;
171+
}
172+
173+
@Override
174+
public String toString() {
175+
StringBuilder builder = new StringBuilder("[");
176+
boolean first = true;
177+
for (DocumentSnapshot doc : this) {
178+
if (first) {
179+
first = false;
180+
} else {
181+
builder.append(", ");
182+
}
183+
builder.append(doc);
184+
}
185+
builder.append("]");
186+
return builder.toString();
187+
}
135188
}

google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -411,29 +411,25 @@ Write.Builder toPb() {
411411
return write;
412412
}
413413

414-
/**
415-
* Returns true if the document's data and path in this DocumentSnapshot equals the provided
416-
* snapshot.
417-
*
418-
* @param obj The object to compare against.
419-
* @return Whether this DocumentSnapshot is equal to the provided object.
420-
*/
421414
@Override
422-
public boolean equals(Object obj) {
423-
if (this == obj) {
415+
public boolean equals(Object o) {
416+
if (this == o) {
424417
return true;
425418
}
426-
if (obj == null || getClass() != obj.getClass()) {
419+
if (o == null || getClass() != o.getClass()) {
427420
return false;
428421
}
429-
DocumentSnapshot that = (DocumentSnapshot) obj;
422+
DocumentSnapshot that = (DocumentSnapshot) o;
430423
return Objects.equals(firestore, that.firestore)
431424
&& Objects.equals(docRef, that.docRef)
432-
&& Objects.equals(fields, that.fields);
425+
&& Objects.equals(fields, that.fields)
426+
&& Objects.equals(readTime, that.readTime)
427+
&& Objects.equals(updateTime, that.updateTime)
428+
&& Objects.equals(createTime, that.createTime);
433429
}
434430

435431
@Override
436432
public int hashCode() {
437-
return Objects.hash(firestore, docRef, fields);
433+
return Objects.hash(firestore, docRef, fields, readTime, updateTime, createTime);
438434
}
439435
}

google-cloud-firestore/src/main/java/com/google/cloud/firestore/FieldValue.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public abstract class FieldValue {
2424
static final Object SERVER_TIMESTAMP_SENTINEL = new Object();
2525
static final Object DELETE_SENTINEL = new Object();
2626

27-
private FieldValue() {}
27+
FieldValue() {}
2828

2929
/**
3030
* Returns a sentinel used with set() or update() to include a server-generated timestamp in the
@@ -40,19 +40,4 @@ public static Object serverTimestamp() {
4040
public static Object delete() {
4141
return DELETE_SENTINEL;
4242
}
43-
44-
/**
45-
* Returns true if this FieldValue is equal to the provided object.
46-
*
47-
* @param obj The object to compare against.
48-
* @return Whether this FieldValue is equal to the provided object.
49-
*/
50-
@Override
51-
public boolean equals(Object obj) {
52-
return this == obj;
53-
}
54-
55-
public int hashCode() {
56-
return super.hashCode();
57-
}
5843
}

google-cloud-firestore/src/main/java/com/google/cloud/firestore/GeoPoint.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.Serializable;
2222
import java.util.Objects;
2323
import javax.annotation.Nonnull;
24+
import javax.annotation.Nullable;
2425

2526
/** Immutable class representing a geographic location in Firestore */
2627
public class GeoPoint implements Serializable {
@@ -76,21 +77,16 @@ LatLng toProto() {
7677
public String toString() {
7778
return "GeoPoint { latitude=" + this.latitude + ", longitude=" + this.longitude + " }";
7879
}
79-
/**
80-
* Returns true if this GeoPoint is equal to the provided object.
81-
*
82-
* @param obj The object to compare against.
83-
* @return Whether this GeoPoint is equal to the provided object.
84-
*/
80+
8581
@Override
86-
public boolean equals(Object obj) {
87-
if (this == obj) {
82+
public boolean equals(@Nullable Object o) {
83+
if (this == o) {
8884
return true;
8985
}
90-
if (obj == null || getClass() != obj.getClass()) {
86+
if (o == null || getClass() != o.getClass()) {
9187
return false;
9288
}
93-
GeoPoint geoPoint = (GeoPoint) obj;
89+
GeoPoint geoPoint = (GeoPoint) o;
9490
return Double.compare(geoPoint.latitude, latitude) == 0
9591
&& Double.compare(geoPoint.longitude, longitude) == 0;
9692
}

google-cloud-firestore/src/main/java/com/google/cloud/firestore/Precondition.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,15 @@ com.google.firestore.v1beta1.Precondition toPb() {
8585
return precondition.build();
8686
}
8787

88-
/**
89-
* Returns true if this Precondition is equal to the provided object.
90-
*
91-
* @param obj The object to compare against.
92-
* @return Whether this Precondition is equal to the provided object.
93-
*/
9488
@Override
95-
public boolean equals(Object obj) {
96-
if (this == obj) {
89+
public boolean equals(Object o) {
90+
if (this == o) {
9791
return true;
9892
}
99-
if (obj == null || getClass() != obj.getClass()) {
93+
if (o == null || getClass() != o.getClass()) {
10094
return false;
10195
}
102-
Precondition that = (Precondition) obj;
96+
Precondition that = (Precondition) o;
10397
return Objects.equals(exists, that.exists) && Objects.equals(updateTime, that.updateTime);
10498
}
10599

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.google.api.core.ApiFuture;
2626
import com.google.api.core.SettableApiFuture;
2727
import com.google.api.gax.rpc.ApiStreamObserver;
28+
import com.google.cloud.firestore.DocumentChange.Type;
2829
import com.google.common.base.Preconditions;
2930
import com.google.firestore.v1beta1.Cursor;
3031
import com.google.firestore.v1beta1.Document;
@@ -995,10 +996,13 @@ ApiFuture<QuerySnapshot> get(@Nullable ByteString transactionId) {
995996
stream(
996997
new QuerySnapshotObserver() {
997998
List<QueryDocumentSnapshot> documentSnapshots = new ArrayList<>();
999+
List<DocumentChange> documentChanges = new ArrayList<>();
9981000

9991001
@Override
10001002
public void onNext(QueryDocumentSnapshot documentSnapshot) {
10011003
documentSnapshots.add(documentSnapshot);
1004+
documentChanges.add(
1005+
new DocumentChange(documentSnapshot, Type.ADDED, -1, documentSnapshots.size() - 1));
10021006
}
10031007

10041008
@Override
@@ -1009,7 +1013,8 @@ public void onError(Throwable throwable) {
10091013
@Override
10101014
public void onCompleted() {
10111015
QuerySnapshot querySnapshot =
1012-
QuerySnapshot.withDocuments(Query.this, this.getReadTime(), documentSnapshots);
1016+
new QuerySnapshot(
1017+
Query.this, this.getReadTime(), documentSnapshots, documentChanges);
10131018
result.set(querySnapshot);
10141019
}
10151020
},
@@ -1066,21 +1071,15 @@ ResourcePath getResourcePath() {
10661071
return path;
10671072
}
10681073

1069-
/**
1070-
* Returns true if this Query is equal to the provided object.
1071-
*
1072-
* @param obj The object to compare against.
1073-
* @return Whether this Query is equal to the provided object.
1074-
*/
10751074
@Override
1076-
public boolean equals(Object obj) {
1077-
if (this == obj) {
1075+
public boolean equals(Object o) {
1076+
if (this == o) {
10781077
return true;
10791078
}
1080-
if (obj == null || getClass() != obj.getClass()) {
1079+
if (o == null || getClass() != o.getClass()) {
10811080
return false;
10821081
}
1083-
Query query = (Query) obj;
1082+
Query query = (Query) o;
10841083
return Objects.equals(path, query.path)
10851084
&& Objects.equals(firestore, query.firestore)
10861085
&& Objects.equals(options, query.options);

0 commit comments

Comments
 (0)