21
21
* Represents a document in Firestore with a key, version, data and whether it has local mutations
22
22
* applied to it.
23
23
*
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.
29
28
*/
30
29
public final class MutableDocument implements Document , Cloneable {
31
30
@@ -66,6 +65,10 @@ private enum DocumentState {
66
65
private ObjectValue value ;
67
66
private DocumentState documentState ;
68
67
68
+ private MutableDocument (DocumentKey key ) {
69
+ this .key = key ;
70
+ }
71
+
69
72
private MutableDocument (
70
73
DocumentKey key ,
71
74
DocumentType documentType ,
@@ -95,14 +98,12 @@ public static MutableDocument newInvalidDocument(DocumentKey documentKey) {
95
98
/** Creates a new document that is known to exist with the given data at the given version. */
96
99
public static MutableDocument newFoundDocument (
97
100
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 );
100
102
}
101
103
102
104
/** Creates a new document that is known to not exisr at the given version. */
103
105
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 );
106
107
}
107
108
108
109
/**
@@ -111,12 +112,7 @@ public static MutableDocument newNoDocument(DocumentKey documentKey, SnapshotVer
111
112
*/
112
113
public static MutableDocument newUnknownDocument (
113
114
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 );
120
116
}
121
117
122
118
/**
0 commit comments