private List < DocumentChange > computeSnapshot ( Timestamp readTime ) { List < DocumentChange > appliedChanges = new ArrayList <> ( ) ; ChangeSet changeSet = extractChanges ( readTime ) ; // Process the sorted changes in the order that is expected by our clients (removals, additions, // and then modifications). We also need to sort the individual changes to assure that // oldIndex/newIndex keep incrementing. Collections . sort ( changeSet . deletes , comparator ) ; for ( QueryDocumentSnapshot delete : changeSet . deletes ) { appliedChanges . add ( deleteDoc ( delete ) ) ; } Collections . sort ( changeSet . adds , comparator ) ; for ( QueryDocumentSnapshot add : changeSet . adds ) { appliedChanges . add ( addDoc ( add ) ) ; } Collections . sort ( changeSet . updates , comparator ) ; for ( QueryDocumentSnapshot update : changeSet . updates ) { DocumentChange change = modifyDoc ( update ) ; if ( change != null ) { appliedChanges . add ( change ) ; } } return appliedChanges ; }
Applies the mutations in changeMap to the document tree . Modified documentSet in - place and returns the changed documents .