package com.google.firebase.firestore; import com.google.firebase.firestore.DocumentSnapshot; import com.google.firebase.firestore.core.ViewSnapshot; import com.google.firebase.firestore.model.Document; import com.google.firebase.firestore.util.Preconditions; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; /* loaded from: classes2.dex */ public class QuerySnapshot implements Iterable { private List cachedChanges; private MetadataChanges cachedChangesMetadataState; private final FirebaseFirestore firestore; private final SnapshotMetadata metadata; private final Query originalQuery; private final ViewSnapshot snapshot; /* JADX INFO: Access modifiers changed from: package-private */ public QuerySnapshot(Query query, ViewSnapshot viewSnapshot, FirebaseFirestore firebaseFirestore) { this.originalQuery = (Query) Preconditions.checkNotNull(query); this.snapshot = (ViewSnapshot) Preconditions.checkNotNull(viewSnapshot); this.firestore = (FirebaseFirestore) Preconditions.checkNotNull(firebaseFirestore); this.metadata = new SnapshotMetadata(viewSnapshot.hasPendingWrites(), viewSnapshot.isFromCache()); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public class QuerySnapshotIterator implements Iterator { private final Iterator it; final QuerySnapshot this$0; QuerySnapshotIterator(QuerySnapshot querySnapshot, Iterator it) { this.this$0 = querySnapshot; this.it = it; } @Override // java.util.Iterator public boolean hasNext() { return this.it.hasNext(); } /* JADX WARN: Can't rename method to resolve collision */ @Override // java.util.Iterator public QueryDocumentSnapshot next() { return this.this$0.convertDocument(this.it.next()); } @Override // java.util.Iterator public void remove() { throw new UnsupportedOperationException("QuerySnapshot does not support remove()."); } } public List getDocumentChanges() { return getDocumentChanges(MetadataChanges.EXCLUDE); } public List getDocumentChanges(MetadataChanges metadataChanges) { if (MetadataChanges.INCLUDE.equals(metadataChanges) && this.snapshot.excludesMetadataChanges()) { throw new IllegalArgumentException("To include metadata changes with your document changes, you must also pass MetadataChanges.INCLUDE to addSnapshotListener()."); } if (this.cachedChanges == null || this.cachedChangesMetadataState != metadataChanges) { this.cachedChanges = Collections.unmodifiableList(DocumentChange.changesFromSnapshot(this.firestore, metadataChanges, this.snapshot)); this.cachedChangesMetadataState = metadataChanges; } return this.cachedChanges; } @Override // java.lang.Iterable public Iterator iterator() { return new QuerySnapshotIterator(this, this.snapshot.getDocuments().iterator()); } public List toObjects(Class cls) { return toObjects(cls, DocumentSnapshot.ServerTimestampBehavior.DEFAULT); } public List toObjects(Class cls, DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior) { Preconditions.checkNotNull(cls, "Provided POJO type must not be null."); ArrayList arrayList = new ArrayList(); Iterator it = iterator(); while (it.hasNext()) { arrayList.add(it.next().toObject(cls, serverTimestampBehavior)); } return arrayList; } /* JADX INFO: Access modifiers changed from: private */ public QueryDocumentSnapshot convertDocument(Document document) { return QueryDocumentSnapshot.fromDocument(this.firestore, document, this.snapshot.isFromCache(), this.snapshot.getMutatedKeys().contains(document.getKey())); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof QuerySnapshot)) { return false; } QuerySnapshot querySnapshot = (QuerySnapshot) obj; return this.firestore.equals(querySnapshot.firestore) && this.originalQuery.equals(querySnapshot.originalQuery) && this.snapshot.equals(querySnapshot.snapshot) && this.metadata.equals(querySnapshot.metadata); } public int hashCode() { int hashCode = this.firestore.hashCode(); int hashCode2 = this.originalQuery.hashCode(); return (((((hashCode * 31) + hashCode2) * 31) + this.snapshot.hashCode()) * 31) + this.metadata.hashCode(); } public SnapshotMetadata getMetadata() { return this.metadata; } }