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

172 lines
6.8 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.firebase.firestore;
import com.google.firebase.Timestamp;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.model.DatabaseId;
import com.google.firebase.firestore.model.DocumentKey;
import com.google.firebase.firestore.model.ServerTimestamps;
import com.google.firebase.firestore.model.Values;
import com.google.firebase.firestore.util.Assert;
import com.google.firebase.firestore.util.Logger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import o.AQX;
import o.QwV;
import o.jrE;
import o.ldG;
import o.sbb;
import o.uOO;
/* loaded from: classes2.dex */
public class UserDataWriter {
private final FirebaseFirestore firestore;
private final DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior;
public UserDataWriter(FirebaseFirestore firebaseFirestore, DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior) {
this.firestore = firebaseFirestore;
this.serverTimestampBehavior = serverTimestampBehavior;
}
public Object convertValue(sbb sbbVar) {
AQX c;
QwV qwV;
jrE a;
jrE a2;
uOO e;
ldG d;
switch (Values.typeOrder(sbbVar)) {
case 0:
return null;
case 1:
return Boolean.valueOf(sbbVar.valueTypeCase_ == 1 ? ((Boolean) sbbVar.valueType_).booleanValue() : false);
case 2:
if (sbb.HBt.c(sbbVar.valueTypeCase_).equals(sbb.HBt.INTEGER_VALUE)) {
return Long.valueOf(sbbVar.valueTypeCase_ == 2 ? ((Long) sbbVar.valueType_).longValue() : 0L);
}
return Double.valueOf(sbbVar.valueTypeCase_ == 3 ? ((Double) sbbVar.valueType_).doubleValue() : 0.0d);
case 3:
if (sbbVar.valueTypeCase_ == 10) {
c = (AQX) sbbVar.valueType_;
} else {
c = AQX.c();
}
return convertTimestamp(c);
case 4:
return convertServerTimestamp(sbbVar);
case 5:
return sbbVar.valueTypeCase_ == 17 ? (String) sbbVar.valueType_ : "";
case 6:
if (sbbVar.valueTypeCase_ == 18) {
qwV = (QwV) sbbVar.valueType_;
} else {
qwV = QwV.a;
}
return Blob.fromByteString(qwV);
case 7:
return convertReference(sbbVar);
case 8:
if (sbbVar.valueTypeCase_ == 8) {
a = (jrE) sbbVar.valueType_;
} else {
a = jrE.a();
}
double d2 = a.latitude_;
if (sbbVar.valueTypeCase_ == 8) {
a2 = (jrE) sbbVar.valueType_;
} else {
a2 = jrE.a();
}
return new GeoPoint(d2, a2.longitude_);
case 9:
if (sbbVar.valueTypeCase_ == 9) {
e = (uOO) sbbVar.valueType_;
} else {
e = uOO.e();
}
return convertArray(e);
case 10:
if (sbbVar.valueTypeCase_ == 6) {
d = (ldG) sbbVar.valueType_;
} else {
d = ldG.d();
}
return convertObject(Collections.unmodifiableMap(d.fields_));
default:
StringBuilder sb = new StringBuilder("Unknown value type: ");
sb.append(sbb.HBt.c(sbbVar.valueTypeCase_));
throw Assert.fail(sb.toString(), new Object[0]);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public Map<String, Object> convertObject(Map<String, sbb> map) {
HashMap hashMap = new HashMap();
for (Map.Entry<String, sbb> entry : map.entrySet()) {
hashMap.put(entry.getKey(), convertValue(entry.getValue()));
}
return hashMap;
}
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: com.google.firebase.firestore.UserDataWriter$1, reason: invalid class name */
/* loaded from: classes2.dex */
public static /* synthetic */ class AnonymousClass1 {
static final int[] $SwitchMap$com$google$firebase$firestore$DocumentSnapshot$ServerTimestampBehavior;
static {
int[] iArr = new int[DocumentSnapshot.ServerTimestampBehavior.values().length];
$SwitchMap$com$google$firebase$firestore$DocumentSnapshot$ServerTimestampBehavior = iArr;
try {
iArr[DocumentSnapshot.ServerTimestampBehavior.PREVIOUS.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$com$google$firebase$firestore$DocumentSnapshot$ServerTimestampBehavior[DocumentSnapshot.ServerTimestampBehavior.ESTIMATE.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
}
}
private Object convertServerTimestamp(sbb sbbVar) {
int i = AnonymousClass1.$SwitchMap$com$google$firebase$firestore$DocumentSnapshot$ServerTimestampBehavior[this.serverTimestampBehavior.ordinal()];
if (i != 1) {
if (i != 2) {
return null;
}
return convertTimestamp(ServerTimestamps.getLocalWriteTime(sbbVar));
}
sbb previousValue = ServerTimestamps.getPreviousValue(sbbVar);
if (previousValue == null) {
return null;
}
return convertValue(previousValue);
}
private Object convertTimestamp(AQX aqx) {
return new Timestamp(aqx.seconds_, aqx.nanos_);
}
private List<Object> convertArray(uOO uoo) {
ArrayList arrayList = new ArrayList(uoo.values_.size());
Iterator<sbb> it = uoo.values_.iterator();
while (it.hasNext()) {
arrayList.add(convertValue(it.next()));
}
return arrayList;
}
private Object convertReference(sbb sbbVar) {
DatabaseId fromName = DatabaseId.fromName(sbbVar.valueTypeCase_ == 5 ? (String) sbbVar.valueType_ : "");
DocumentKey fromName2 = DocumentKey.fromName(sbbVar.valueTypeCase_ == 5 ? (String) sbbVar.valueType_ : "");
DatabaseId databaseId = this.firestore.getDatabaseId();
if (!fromName.equals(databaseId)) {
Logger.warn("DocumentSnapshot", "Document %s contains a document reference within a different database (%s/%s) which is not supported. It will be treated as a reference in the current database (%s/%s) instead.", fromName2.getPath(), fromName.getProjectId(), fromName.getDatabaseId(), databaseId.getProjectId(), databaseId.getDatabaseId());
}
return new DocumentReference(fromName2, this.firestore);
}
}