use of com.google.firebase.firestore.core.DocumentViewChange.Type in project firebase-android-sdk by firebase.
the class DocumentViewChangeSetTest method testDocumentViewChangeConstructor.
@Test
public void testDocumentViewChangeConstructor() {
MutableDocument doc1 = doc("a/b", 0, EMPTY_MAP);
Type type = Type.MODIFIED;
DocumentViewChange change = DocumentViewChange.create(type, doc1);
assertEquals(change.getDocument(), doc1);
assertEquals(change.getType(), type);
}
use of com.google.firebase.firestore.core.DocumentViewChange.Type in project firebase-android-sdk by firebase.
the class DocumentViewChangeSet method addChange.
public void addChange(DocumentViewChange change) {
DocumentKey key = change.getDocument().getKey();
DocumentViewChange old = changes.get(key);
if (old == null) {
changes.put(key, change);
return;
}
Type oldType = old.getType();
Type newType = change.getType();
if (newType != Type.ADDED && oldType == Type.METADATA) {
changes.put(key, change);
} else if (newType == Type.METADATA && oldType != Type.REMOVED) {
DocumentViewChange newChange = DocumentViewChange.create(oldType, change.getDocument());
changes.put(key, newChange);
} else if (newType == Type.MODIFIED && oldType == Type.MODIFIED) {
DocumentViewChange newChange = DocumentViewChange.create(Type.MODIFIED, change.getDocument());
changes.put(key, newChange);
} else if (newType == Type.MODIFIED && oldType == Type.ADDED) {
DocumentViewChange newChange = DocumentViewChange.create(Type.ADDED, change.getDocument());
changes.put(key, newChange);
} else if (newType == Type.REMOVED && oldType == Type.ADDED) {
changes.remove(key);
} else if (newType == Type.REMOVED && oldType == Type.MODIFIED) {
DocumentViewChange newChange = DocumentViewChange.create(Type.REMOVED, old.getDocument());
changes.put(key, newChange);
} else if (newType == Type.ADDED && oldType == Type.REMOVED) {
DocumentViewChange newChange = DocumentViewChange.create(Type.MODIFIED, change.getDocument());
changes.put(key, newChange);
} else {
// Removed -> Metadata
throw fail("Unsupported combination of changes %s after %s", newType, oldType);
}
}
Aggregations