Skip to content

Commit 77fddbf

Browse files
Next round
1 parent 095179c commit 77fddbf

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/model/MutableDocument.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
* Represents a document in Firestore with a key, version, data and whether it has local mutations
2222
* applied to it.
2323
*
24-
* <p>Documents can transition between states via {@link
25-
* #convertToFoundDocument(SnapshotVersion,ObjectValue)}, {@link
26-
* #convertToNoDocument(SnapshotVersion)} and {@link #convertToUnknownDocument(SnapshotVersion)}. If
27-
* a document does not transition to one of these states even after all mutations have been applied,
28-
* {@link #isValidDocument()} returns false and the document should be removed from all views.
24+
* <p>Documents can transition between states via {@link #convertToFoundDocument}, {@link
25+
* #convertToNoDocument} and {@link #convertToUnknownDocument}. If a document does not transition to
26+
* one of these states even after all mutations have been applied, {@link #isValidDocument} returns
27+
* false and the document should be removed from all views.
2928
*/
3029
public final class MutableDocument implements Document, Cloneable {
3130

@@ -66,6 +65,10 @@ private enum DocumentState {
6665
private ObjectValue value;
6766
private DocumentState documentState;
6867

68+
private MutableDocument(DocumentKey key) {
69+
this.key = key;
70+
}
71+
6972
private MutableDocument(
7073
DocumentKey key,
7174
DocumentType documentType,
@@ -95,14 +98,12 @@ public static MutableDocument newInvalidDocument(DocumentKey documentKey) {
9598
/** Creates a new document that is known to exist with the given data at the given version. */
9699
public static MutableDocument newFoundDocument(
97100
DocumentKey documentKey, SnapshotVersion version, ObjectValue value) {
98-
return new MutableDocument(
99-
documentKey, DocumentType.FOUND_DOCUMENT, version, value, DocumentState.SYNCED);
101+
return new MutableDocument(documentKey).convertToFoundDocument(version, value);
100102
}
101103

102104
/** Creates a new document that is known to not exisr at the given version. */
103105
public static MutableDocument newNoDocument(DocumentKey documentKey, SnapshotVersion version) {
104-
return new MutableDocument(
105-
documentKey, DocumentType.NO_DOCUMENT, version, new ObjectValue(), DocumentState.SYNCED);
106+
return new MutableDocument(documentKey).convertToNoDocument(version);
106107
}
107108

108109
/**
@@ -111,12 +112,7 @@ public static MutableDocument newNoDocument(DocumentKey documentKey, SnapshotVer
111112
*/
112113
public static MutableDocument newUnknownDocument(
113114
DocumentKey documentKey, SnapshotVersion version) {
114-
return new MutableDocument(
115-
documentKey,
116-
DocumentType.UNKNOWN_DOCUMENT,
117-
version,
118-
new ObjectValue(),
119-
DocumentState.HAS_COMMITTED_MUTATIONS);
115+
return new MutableDocument(documentKey).convertToUnknownDocument(version);
120116
}
121117

122118
/**

0 commit comments

Comments
 (0)