Search in sources :

Example 1 with Type

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);
}
Also used : Type(com.google.firebase.firestore.core.DocumentViewChange.Type) MutableDocument(com.google.firebase.firestore.model.MutableDocument) Test(org.junit.Test)

Example 2 with 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);
    }
}
Also used : Type(com.google.firebase.firestore.core.DocumentViewChange.Type) DocumentKey(com.google.firebase.firestore.model.DocumentKey)

Aggregations

Type (com.google.firebase.firestore.core.DocumentViewChange.Type)2 DocumentKey (com.google.firebase.firestore.model.DocumentKey)1 MutableDocument (com.google.firebase.firestore.model.MutableDocument)1 Test (org.junit.Test)1