Skip to content

Commit d124aa9

Browse files
s/Document/MutableDocument
1 parent 93a1ece commit d124aa9

File tree

82 files changed

+794
-792
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+794
-792
lines changed

firebase-firestore/ktx/src/test/java/com/google/firebase/firestore/TestUtil.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.google.firebase.firestore.core.DocumentViewChange;
2424
import com.google.firebase.firestore.core.DocumentViewChange.Type;
2525
import com.google.firebase.firestore.core.ViewSnapshot;
26-
import com.google.firebase.firestore.model.Document;
26+
import com.google.firebase.firestore.model.MutableDocument;
2727
import com.google.firebase.firestore.model.DocumentKey;
2828
import com.google.firebase.firestore.model.DocumentSet;
2929
import com.google.firebase.firestore.model.ObjectValue;
@@ -72,22 +72,22 @@ public static QuerySnapshot querySnapshot(
7272
Map<String, ObjectValue> docsToAdd,
7373
boolean hasPendingWrites,
7474
boolean isFromCache) {
75-
DocumentSet oldDocuments = docSet(Document.keyComparator());
75+
DocumentSet oldDocuments = docSet(MutableDocument.keyComparator());
7676
ImmutableSortedSet<DocumentKey> mutatedKeys = DocumentKey.emptyKeySet();
7777
for (Map.Entry<String, ObjectValue> pair : oldDocs.entrySet()) {
7878
String docKey = path + "/" + pair.getKey();
79-
Document doc = doc(docKey, 1L, pair.getValue());
79+
MutableDocument doc = doc(docKey, 1L, pair.getValue());
8080
if (hasPendingWrites) doc.setLocalMutations();
8181
oldDocuments = oldDocuments.add(doc);
8282
if (hasPendingWrites) {
8383
mutatedKeys = mutatedKeys.insert(key(docKey));
8484
}
8585
}
86-
DocumentSet newDocuments = docSet(Document.keyComparator());
86+
DocumentSet newDocuments = docSet(MutableDocument.keyComparator());
8787
List<DocumentViewChange> documentChanges = new ArrayList<>();
8888
for (Map.Entry<String, ObjectValue> pair : docsToAdd.entrySet()) {
8989
String docKey = path + "/" + pair.getKey();
90-
Document docToAdd = doc(docKey, 1L, pair.getValue());
90+
MutableDocument docToAdd = doc(docKey, 1L, pair.getValue());
9191
if (hasPendingWrites) docToAdd.setLocalMutations();
9292
newDocuments = newDocuments.add(docToAdd);
9393
documentChanges.add(DocumentViewChange.create(Type.ADDED, docToAdd));

firebase-firestore/ktx/src/test/java/com/google/firebase/firestore/testutil/TestUtil.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import com.google.firebase.firestore.UserDataReader;
1919
import com.google.firebase.firestore.core.Query;
2020
import com.google.firebase.firestore.model.DatabaseId;
21-
import com.google.firebase.firestore.model.Document;
21+
import com.google.firebase.firestore.model.MutableDocument;
2222
import com.google.firebase.firestore.model.DocumentKey;
2323
import com.google.firebase.firestore.model.DocumentSet;
2424
import com.google.firebase.firestore.model.ObjectValue;
@@ -62,21 +62,21 @@ public static SnapshotVersion version(long versionMicros) {
6262
return new SnapshotVersion(new Timestamp(seconds, nanos));
6363
}
6464

65-
public static Document doc(String key, long version, Map<String, Object> data) {
66-
return new Document(key(key)).setFoundDocument(version(version), wrapObject(data));
65+
public static MutableDocument doc(String key, long version, Map<String, Object> data) {
66+
return new MutableDocument(key(key)).setFoundDocument(version(version), wrapObject(data));
6767
}
6868

69-
public static Document doc(DocumentKey key, long version, Map<String, Object> data) {
70-
return new Document(key).setFoundDocument(version(version), wrapObject(data));
69+
public static MutableDocument doc(DocumentKey key, long version, Map<String, Object> data) {
70+
return new MutableDocument(key).setFoundDocument(version(version), wrapObject(data));
7171
}
7272

73-
public static Document doc(String key, long version, ObjectValue data) {
74-
return new Document(key(key)).setFoundDocument(version(version), data);
73+
public static MutableDocument doc(String key, long version, ObjectValue data) {
74+
return new MutableDocument(key(key)).setFoundDocument(version(version), data);
7575
}
7676

77-
public static DocumentSet docSet(Comparator<Document> comparator, Document... documents) {
77+
public static DocumentSet docSet(Comparator<MutableDocument> comparator, MutableDocument... documents) {
7878
DocumentSet set = DocumentSet.emptySet(comparator);
79-
for (Document document : documents) {
79+
for (MutableDocument document : documents) {
8080
set = set.add(document);
8181
}
8282
return set;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import androidx.annotation.VisibleForTesting;
2222
import com.google.firebase.firestore.core.DocumentViewChange;
2323
import com.google.firebase.firestore.core.ViewSnapshot;
24-
import com.google.firebase.firestore.model.Document;
24+
import com.google.firebase.firestore.model.MutableDocument;
2525
import com.google.firebase.firestore.model.DocumentSet;
2626
import java.util.ArrayList;
2727
import java.util.List;
@@ -132,9 +132,9 @@ static List<DocumentChange> changesFromSnapshot(
132132
// changes on the first snapshot are adds so there are also no metadata-only changes to filter
133133
// out.
134134
int index = 0;
135-
Document lastDoc = null;
135+
MutableDocument lastDoc = null;
136136
for (DocumentViewChange change : snapshot.getChanges()) {
137-
Document document = change.getDocument();
137+
MutableDocument document = change.getDocument();
138138
QueryDocumentSnapshot documentSnapshot =
139139
QueryDocumentSnapshot.fromDocument(
140140
firestore,
@@ -159,7 +159,7 @@ static List<DocumentChange> changesFromSnapshot(
159159
&& change.getType() == DocumentViewChange.Type.METADATA) {
160160
continue;
161161
}
162-
Document document = change.getDocument();
162+
MutableDocument document = change.getDocument();
163163
QueryDocumentSnapshot documentSnapshot =
164164
QueryDocumentSnapshot.fromDocument(
165165
firestore,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import com.google.firebase.firestore.core.UserData.ParsedSetData;
3535
import com.google.firebase.firestore.core.UserData.ParsedUpdateData;
3636
import com.google.firebase.firestore.core.ViewSnapshot;
37-
import com.google.firebase.firestore.model.Document;
37+
import com.google.firebase.firestore.model.MutableDocument;
3838
import com.google.firebase.firestore.model.DocumentKey;
3939
import com.google.firebase.firestore.model.ResourcePath;
4040
import com.google.firebase.firestore.model.mutation.DeleteMutation;
@@ -278,8 +278,8 @@ public Task<DocumentSnapshot> get(@NonNull Source source) {
278278
.getDocumentFromLocalCache(key)
279279
.continueWith(
280280
Executors.DIRECT_EXECUTOR,
281-
(Task<Document> task) -> {
282-
Document doc = task.getResult();
281+
(Task<MutableDocument> task) -> {
282+
MutableDocument doc = task.getResult();
283283
boolean hasPendingWrites = doc != null && doc.hasLocalMutations();
284284
return new DocumentSnapshot(
285285
firestore, key, doc, /*isFromCache=*/ true, hasPendingWrites);
@@ -489,7 +489,7 @@ private ListenerRegistration addSnapshotListenerInternal(
489489
snapshot.getDocuments().size() <= 1,
490490
"Too many documents returned on a document query");
491491

492-
Document document = snapshot.getDocuments().getDocument(key);
492+
MutableDocument document = snapshot.getDocuments().getDocument(key);
493493
DocumentSnapshot documentSnapshot;
494494
if (document != null) {
495495
boolean hasPendingWrites = snapshot.getMutatedKeys().contains(document.getKey());

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import androidx.annotation.NonNull;
2020
import androidx.annotation.Nullable;
2121
import com.google.firebase.Timestamp;
22-
import com.google.firebase.firestore.model.Document;
22+
import com.google.firebase.firestore.model.MutableDocument;
2323
import com.google.firebase.firestore.model.DocumentKey;
2424
import com.google.firebase.firestore.util.CustomClassMapper;
2525
import com.google.firestore.v1.Value;
@@ -73,14 +73,15 @@ public enum ServerTimestampBehavior {
7373
private final DocumentKey key;
7474

7575
/** Is {@code null} if the document doesn't exist */
76-
private final @Nullable Document doc;
76+
private final @Nullable
77+
MutableDocument doc;
7778

7879
private final SnapshotMetadata metadata;
7980

8081
DocumentSnapshot(
8182
FirebaseFirestore firestore,
8283
DocumentKey key,
83-
@Nullable Document doc,
84+
@Nullable MutableDocument doc,
8485
boolean isFromCache,
8586
boolean hasPendingWrites) {
8687
this.firestore = checkNotNull(firestore);
@@ -90,7 +91,7 @@ public enum ServerTimestampBehavior {
9091
}
9192

9293
static DocumentSnapshot fromDocument(
93-
FirebaseFirestore firestore, Document doc, boolean fromCache, boolean hasPendingWrites) {
94+
FirebaseFirestore firestore, MutableDocument doc, boolean fromCache, boolean hasPendingWrites) {
9495
return new DocumentSnapshot(firestore, doc.getKey(), doc, fromCache, hasPendingWrites);
9596
}
9697

@@ -117,7 +118,7 @@ public boolean exists() {
117118
}
118119

119120
@Nullable
120-
Document getDocument() {
121+
MutableDocument getDocument() {
121122
return doc;
122123
}
123124

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import com.google.firebase.firestore.core.OrderBy;
3737
import com.google.firebase.firestore.core.QueryListener;
3838
import com.google.firebase.firestore.core.ViewSnapshot;
39-
import com.google.firebase.firestore.model.Document;
39+
import com.google.firebase.firestore.model.MutableDocument;
4040
import com.google.firebase.firestore.model.DocumentKey;
4141
import com.google.firebase.firestore.model.ResourcePath;
4242
import com.google.firebase.firestore.model.ServerTimestamps;
@@ -826,7 +826,7 @@ private Bound boundFromDocumentSnapshot(
826826
+ methodName
827827
+ "().");
828828
}
829-
Document document = snapshot.getDocument();
829+
MutableDocument document = snapshot.getDocument();
830830
List<Value> components = new ArrayList<>();
831831

832832
// Because people expect to continue/end a query at the exact document provided, we need to

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import androidx.annotation.NonNull;
2020
import androidx.annotation.Nullable;
21-
import com.google.firebase.firestore.model.Document;
21+
import com.google.firebase.firestore.model.MutableDocument;
2222
import com.google.firebase.firestore.model.DocumentKey;
2323
import com.google.firebase.firestore.util.Assert;
2424
import java.util.Map;
@@ -42,14 +42,14 @@ public class QueryDocumentSnapshot extends DocumentSnapshot {
4242
private QueryDocumentSnapshot(
4343
FirebaseFirestore firestore,
4444
DocumentKey key,
45-
@Nullable Document doc,
45+
@Nullable MutableDocument doc,
4646
boolean isFromCache,
4747
boolean hasPendingWrites) {
4848
super(firestore, key, doc, isFromCache, hasPendingWrites);
4949
}
5050

5151
static QueryDocumentSnapshot fromDocument(
52-
FirebaseFirestore firestore, Document doc, boolean fromCache, boolean hasPendingWrites) {
52+
FirebaseFirestore firestore, MutableDocument doc, boolean fromCache, boolean hasPendingWrites) {
5353
return new QueryDocumentSnapshot(firestore, doc.getKey(), doc, fromCache, hasPendingWrites);
5454
}
5555

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import androidx.annotation.NonNull;
2020
import androidx.annotation.Nullable;
2121
import com.google.firebase.firestore.core.ViewSnapshot;
22-
import com.google.firebase.firestore.model.Document;
22+
import com.google.firebase.firestore.model.MutableDocument;
2323
import java.util.ArrayList;
2424
import java.util.Collections;
2525
import java.util.Iterator;
@@ -55,9 +55,9 @@ public class QuerySnapshot implements Iterable<QueryDocumentSnapshot> {
5555
}
5656

5757
private class QuerySnapshotIterator implements Iterator<QueryDocumentSnapshot> {
58-
private final Iterator<com.google.firebase.firestore.model.Document> it;
58+
private final Iterator<MutableDocument> it;
5959

60-
QuerySnapshotIterator(Iterator<com.google.firebase.firestore.model.Document> it) {
60+
QuerySnapshotIterator(Iterator<MutableDocument> it) {
6161
this.it = it;
6262
}
6363

@@ -133,7 +133,7 @@ public List<DocumentChange> getDocumentChanges(@NonNull MetadataChanges metadata
133133
@NonNull
134134
public List<DocumentSnapshot> getDocuments() {
135135
List<DocumentSnapshot> res = new ArrayList<>(snapshot.getDocuments().size());
136-
for (com.google.firebase.firestore.model.Document doc : snapshot.getDocuments()) {
136+
for (MutableDocument doc : snapshot.getDocuments()) {
137137
res.add(convertDocument(doc));
138138
}
139139
return res;
@@ -186,7 +186,7 @@ public <T> List<T> toObjects(
186186
return res;
187187
}
188188

189-
private QueryDocumentSnapshot convertDocument(Document document) {
189+
private QueryDocumentSnapshot convertDocument(MutableDocument document) {
190190
return QueryDocumentSnapshot.fromDocument(
191191
firestore,
192192
document,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.google.android.gms.tasks.Tasks;
2424
import com.google.firebase.firestore.core.UserData.ParsedSetData;
2525
import com.google.firebase.firestore.core.UserData.ParsedUpdateData;
26-
import com.google.firebase.firestore.model.Document;
26+
import com.google.firebase.firestore.model.MutableDocument;
2727
import com.google.firebase.firestore.util.Executors;
2828
import com.google.firebase.firestore.util.Util;
2929
import java.util.Collections;
@@ -193,14 +193,14 @@ private Task<DocumentSnapshot> getAsync(DocumentReference documentRef) {
193193
if (!task.isSuccessful()) {
194194
throw task.getException();
195195
}
196-
List<Document> docs = task.getResult();
196+
List<MutableDocument> docs = task.getResult();
197197
if (docs.size() != 1) {
198198
throw fail("Mismatch in docs returned from document lookup.");
199199
}
200-
Document doc = docs.get(0);
200+
MutableDocument doc = docs.get(0);
201201
if (doc.isFoundDocument()) {
202202
return DocumentSnapshot.fromDocument(
203-
firestore, (Document) doc, /*fromCache=*/ false, /*hasPendingWrites=*/ false);
203+
firestore, (MutableDocument) doc, /*fromCache=*/ false, /*hasPendingWrites=*/ false);
204204
} else if (doc.isNoDocument()) {
205205
return DocumentSnapshot.fromNoDocument(
206206
firestore, doc.getKey(), /*fromCache=*/ false, /*hasPendingWrites=*/ false);

firebase-firestore/src/main/java/com/google/firebase/firestore/bundle/BundleCallback.java

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

1717
import com.google.firebase.database.collection.ImmutableSortedMap;
1818
import com.google.firebase.database.collection.ImmutableSortedSet;
19-
import com.google.firebase.firestore.model.Document;
19+
import com.google.firebase.firestore.model.MutableDocument;
2020
import com.google.firebase.firestore.model.DocumentKey;
2121

2222
/** Interface implemented by components that can apply changes from a bundle to local storage. */
@@ -26,8 +26,8 @@ public interface BundleCallback {
2626
*
2727
* <p>LocalDocuments are re-calculated if there are remaining mutations in the queue.
2828
*/
29-
ImmutableSortedMap<DocumentKey, Document> applyBundledDocuments(
30-
ImmutableSortedMap<DocumentKey, Document> documents, String bundleId);
29+
ImmutableSortedMap<DocumentKey, MutableDocument> applyBundledDocuments(
30+
ImmutableSortedMap<DocumentKey, MutableDocument> documents, String bundleId);
3131

3232
/** Saves the given NamedQuery to local persistence. */
3333
void saveNamedQuery(NamedQuery namedQuery, ImmutableSortedSet<DocumentKey> documentKeys);

firebase-firestore/src/main/java/com/google/firebase/firestore/bundle/BundleDocument.java

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

1515
package com.google.firebase.firestore.bundle;
1616

17-
import com.google.firebase.firestore.model.Document;
17+
import com.google.firebase.firestore.model.MutableDocument;
1818
import com.google.firebase.firestore.model.DocumentKey;
1919

2020
/** A document that was saved to a bundle. */
2121
public class BundleDocument implements BundleElement {
22-
private Document document;
22+
private MutableDocument document;
2323

24-
public BundleDocument(Document document) {
24+
public BundleDocument(MutableDocument document) {
2525
this.document = document;
2626
}
2727

@@ -31,7 +31,7 @@ public DocumentKey getKey() {
3131
}
3232

3333
/** Returns the document. */
34-
public Document getDocument() {
34+
public MutableDocument getDocument() {
3535
return document;
3636
}
3737

firebase-firestore/src/main/java/com/google/firebase/firestore/bundle/BundleLoader.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.google.firebase.database.collection.ImmutableSortedMap;
2121
import com.google.firebase.database.collection.ImmutableSortedSet;
2222
import com.google.firebase.firestore.LoadBundleTaskProgress;
23-
import com.google.firebase.firestore.model.Document;
23+
import com.google.firebase.firestore.model.MutableDocument;
2424
import com.google.firebase.firestore.model.DocumentKey;
2525
import com.google.firebase.firestore.util.Preconditions;
2626
import java.util.ArrayList;
@@ -38,7 +38,7 @@ public class BundleLoader {
3838
private final List<NamedQuery> queries;
3939
private final Map<DocumentKey, BundledDocumentMetadata> documentsMetadata;
4040

41-
private ImmutableSortedMap<DocumentKey, Document> documents;
41+
private ImmutableSortedMap<DocumentKey, MutableDocument> documents;
4242
private long bytesLoaded;
4343
@Nullable private DocumentKey currentDocument;
4444

@@ -72,7 +72,7 @@ public BundleLoader(BundleCallback bundleCallback, BundleMetadata bundleMetadata
7272
documents =
7373
documents.insert(
7474
bundledDocumentMetadata.getKey(),
75-
new Document(bundledDocumentMetadata.getKey())
75+
new MutableDocument(bundledDocumentMetadata.getKey())
7676
.setNoDocument(bundledDocumentMetadata.getReadTime()));
7777
currentDocument = null;
7878
}
@@ -100,7 +100,7 @@ public BundleLoader(BundleCallback bundleCallback, BundleMetadata bundleMetadata
100100
}
101101

102102
/** Applies the loaded documents and queries to local store. Returns the document view changes. */
103-
public ImmutableSortedMap<DocumentKey, Document> applyChanges() {
103+
public ImmutableSortedMap<DocumentKey, MutableDocument> applyChanges() {
104104
Preconditions.checkArgument(
105105
currentDocument == null,
106106
"Bundled documents end with a document metadata element instead of a document.");
@@ -111,7 +111,7 @@ public ImmutableSortedMap<DocumentKey, Document> applyChanges() {
111111
bundleMetadata.getTotalDocuments(),
112112
documents.size());
113113

114-
ImmutableSortedMap<DocumentKey, Document> changes =
114+
ImmutableSortedMap<DocumentKey, MutableDocument> changes =
115115
bundleCallback.applyBundledDocuments(documents, bundleMetadata.getBundleId());
116116

117117
Map<String, ImmutableSortedSet<DocumentKey>> queryDocumentMap = getQueryDocumentMapping();

firebase-firestore/src/main/java/com/google/firebase/firestore/bundle/BundleSerializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.google.firebase.firestore.core.OrderBy;
2424
import com.google.firebase.firestore.core.Query;
2525
import com.google.firebase.firestore.core.Target;
26-
import com.google.firebase.firestore.model.Document;
26+
import com.google.firebase.firestore.model.MutableDocument;
2727
import com.google.firebase.firestore.model.DocumentKey;
2828
import com.google.firebase.firestore.model.FieldPath;
2929
import com.google.firebase.firestore.model.ObjectValue;
@@ -111,7 +111,7 @@ BundleDocument decodeDocument(JSONObject document) throws JSONException {
111111
decodeMapValue(value, document.getJSONObject("fields"));
112112

113113
return new BundleDocument(
114-
new Document(key)
114+
new MutableDocument(key)
115115
.setFoundDocument(updateTime, ObjectValue.fromMap(value.getMapValue().getFieldsMap())));
116116
}
117117

0 commit comments

Comments
 (0)