90 lines
3.6 KiB
Java
90 lines
3.6 KiB
Java
package com.google.firebase.firestore;
|
|
|
|
import com.airbnb.deeplinkdispatch.UrlTreeKt;
|
|
import com.google.firebase.firestore.model.Document;
|
|
import com.google.firebase.firestore.model.DocumentKey;
|
|
import com.google.firebase.firestore.util.CustomClassMapper;
|
|
import com.google.firebase.firestore.util.Preconditions;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class DocumentSnapshot {
|
|
private final Document doc;
|
|
private final FirebaseFirestore firestore;
|
|
private final DocumentKey key;
|
|
private final SnapshotMetadata metadata;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public enum ServerTimestampBehavior {
|
|
NONE,
|
|
ESTIMATE,
|
|
PREVIOUS;
|
|
|
|
static final ServerTimestampBehavior DEFAULT = NONE;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public DocumentSnapshot(FirebaseFirestore firebaseFirestore, DocumentKey documentKey, Document document, boolean z, boolean z2) {
|
|
this.firestore = (FirebaseFirestore) Preconditions.checkNotNull(firebaseFirestore);
|
|
this.key = (DocumentKey) Preconditions.checkNotNull(documentKey);
|
|
this.doc = document;
|
|
this.metadata = new SnapshotMetadata(z2, z);
|
|
}
|
|
|
|
public Map<String, Object> getData(ServerTimestampBehavior serverTimestampBehavior) {
|
|
Preconditions.checkNotNull(serverTimestampBehavior, "Provided serverTimestampBehavior value must not be null.");
|
|
UserDataWriter userDataWriter = new UserDataWriter(this.firestore, serverTimestampBehavior);
|
|
Document document = this.doc;
|
|
if (document == null) {
|
|
return null;
|
|
}
|
|
return userDataWriter.convertObject(document.getData().getFieldsMap());
|
|
}
|
|
|
|
public <T> T toObject(Class<T> cls, ServerTimestampBehavior serverTimestampBehavior) {
|
|
Preconditions.checkNotNull(cls, "Provided POJO type must not be null.");
|
|
Preconditions.checkNotNull(serverTimestampBehavior, "Provided serverTimestampBehavior value must not be null.");
|
|
Map<String, Object> data = getData(serverTimestampBehavior);
|
|
if (data == null) {
|
|
return null;
|
|
}
|
|
return (T) CustomClassMapper.convertToCustomClass(data, cls, getReference());
|
|
}
|
|
|
|
public DocumentReference getReference() {
|
|
return new DocumentReference(this.key, this.firestore);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
Document document;
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof DocumentSnapshot)) {
|
|
return false;
|
|
}
|
|
DocumentSnapshot documentSnapshot = (DocumentSnapshot) obj;
|
|
return this.firestore.equals(documentSnapshot.firestore) && this.key.equals(documentSnapshot.key) && ((document = this.doc) != null ? document.equals(documentSnapshot.doc) : documentSnapshot.doc == null) && this.metadata.equals(documentSnapshot.metadata);
|
|
}
|
|
|
|
public int hashCode() {
|
|
int hashCode = this.firestore.hashCode();
|
|
int hashCode2 = this.key.hashCode();
|
|
Document document = this.doc;
|
|
int hashCode3 = document != null ? document.getKey().hashCode() : 0;
|
|
Document document2 = this.doc;
|
|
return (((((((hashCode * 31) + hashCode2) * 31) + hashCode3) * 31) + (document2 != null ? document2.getData().hashCode() : 0)) * 31) + this.metadata.hashCode();
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder sb = new StringBuilder("DocumentSnapshot{key=");
|
|
sb.append(this.key);
|
|
sb.append(", metadata=");
|
|
sb.append(this.metadata);
|
|
sb.append(", doc=");
|
|
sb.append(this.doc);
|
|
sb.append(UrlTreeKt.componentParamSuffixChar);
|
|
return sb.toString();
|
|
}
|
|
}
|