what-the-bank/sources/com/google/firebase/firestore/QuerySnapshot.java

117 lines
4.9 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
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<QueryDocumentSnapshot> {
private List<DocumentChange> 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<QueryDocumentSnapshot> {
private final Iterator<Document> it;
final QuerySnapshot this$0;
QuerySnapshotIterator(QuerySnapshot querySnapshot, Iterator<Document> 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<DocumentChange> getDocumentChanges() {
return getDocumentChanges(MetadataChanges.EXCLUDE);
}
public List<DocumentChange> 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<QueryDocumentSnapshot> iterator() {
return new QuerySnapshotIterator(this, this.snapshot.getDocuments().iterator());
}
public <T> List<T> toObjects(Class<T> cls) {
return toObjects(cls, DocumentSnapshot.ServerTimestampBehavior.DEFAULT);
}
public <T> List<T> toObjects(Class<T> cls, DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior) {
Preconditions.checkNotNull(cls, "Provided POJO type must not be null.");
ArrayList arrayList = new ArrayList();
Iterator<QueryDocumentSnapshot> 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;
}
}