public static QuerySnapshot withDocuments ( final Query query , Timestamp readTime , final List < QueryDocumentSnapshot > documents ) { return new QuerySnapshot ( query , readTime ) { volatile List < DocumentChange > documentChanges ; @ Nonnull @ Override public List < QueryDocumentSnapshot > getDocuments ( ) { return Collections . unmodifiableList ( documents ) ; } @ Nonnull @ Override public List < DocumentChange > getDocumentChanges ( ) { if ( documentChanges == null ) { synchronized ( documents ) { if ( documentChanges == null ) { documentChanges = new ArrayList <> ( ) ; for ( int i = 0 ; i < documents . size ( ) ; ++ i ) { documentChanges . add ( new DocumentChange ( documents . get ( i ) , Type . ADDED , - 1 , i ) ) ; } } } } return Collections . unmodifiableList ( documentChanges ) ; } @ Override public int size ( ) { return documents . size ( ) ; } @ Override public boolean equals ( Object o ) { if ( this == o ) { return true ; } if ( o == null || getClass ( ) != o . getClass ( ) ) { return false ; } QuerySnapshot that = ( QuerySnapshot ) o ; return Objects . equals ( query , that . query ) && Objects . equals ( this . size ( ) , that . size ( ) ) && Objects . equals ( this . getDocuments ( ) , that . getDocuments ( ) ) ; } @ Override public int hashCode ( ) { return Objects . hash ( query , this . getDocuments ( ) ) ; } } ; }
Creates a new QuerySnapshot representing the results of a Query with added documents .