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

251 lines
8.5 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.firebase.firestore.model;
import com.airbnb.deeplinkdispatch.UrlTreeKt;
import com.google.firebase.firestore.model.mutation.FieldMask;
import com.google.firebase.firestore.util.Assert;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import o.C16063kpL;
import o.ldG;
import o.sbb;
/* loaded from: classes2.dex */
public final class ObjectValue implements Cloneable {
private final Map<String, Object> overlayMap;
private sbb partialValue;
public static ObjectValue fromMap(Map<String, sbb> map) {
return new ObjectValue(sbb.d().d(ldG.a().a(map)).build());
}
public ObjectValue(sbb sbbVar) {
this.overlayMap = new HashMap();
Assert.hardAssert(sbb.HBt.c(sbbVar.valueTypeCase_) == sbb.HBt.MAP_VALUE, "ObjectValues should be backed by a MapValue", new Object[0]);
Assert.hardAssert(!ServerTimestamps.isServerTimestamp(sbbVar), "ServerTimestamps should not be used as an ObjectValue", new Object[0]);
this.partialValue = sbbVar;
}
public ObjectValue() {
this(sbb.d().c(ldG.d()).build());
}
public final Map<String, sbb> getFieldsMap() {
ldG d;
sbb buildProto = buildProto();
if (buildProto.valueTypeCase_ == 6) {
d = (ldG) buildProto.valueType_;
} else {
d = ldG.d();
}
return Collections.unmodifiableMap(d.fields_);
}
public final FieldMask getFieldMask() {
ldG d;
sbb buildProto = buildProto();
if (buildProto.valueTypeCase_ == 6) {
d = (ldG) buildProto.valueType_;
} else {
d = ldG.d();
}
return extractFieldMask(d);
}
private FieldMask extractFieldMask(ldG ldg) {
ldG d;
HashSet hashSet = new HashSet();
for (Map.Entry entry : Collections.unmodifiableMap(ldg.fields_).entrySet()) {
FieldPath fromSingleSegment = FieldPath.fromSingleSegment((String) entry.getKey());
if (Values.isMapValue((sbb) entry.getValue())) {
sbb sbbVar = (sbb) entry.getValue();
if (sbbVar.valueTypeCase_ == 6) {
d = (ldG) sbbVar.valueType_;
} else {
d = ldG.d();
}
Set<FieldPath> mask = extractFieldMask(d).getMask();
if (mask.isEmpty()) {
hashSet.add(fromSingleSegment);
} else {
Iterator<FieldPath> it = mask.iterator();
while (it.hasNext()) {
hashSet.add(fromSingleSegment.append(it.next()));
}
}
} else {
hashSet.add(fromSingleSegment);
}
}
return FieldMask.fromSet(hashSet);
}
public final sbb get(FieldPath fieldPath) {
return extractNestedValue(buildProto(), fieldPath);
}
private sbb extractNestedValue(sbb sbbVar, FieldPath fieldPath) {
ldG d;
ldG d2;
if (fieldPath.isEmpty()) {
return sbbVar;
}
for (int i = 0; i < fieldPath.length() - 1; i++) {
if (sbbVar.valueTypeCase_ == 6) {
d2 = (ldG) sbbVar.valueType_;
} else {
d2 = ldG.d();
}
String segment = fieldPath.getSegment(i);
C16063kpL<String, sbb> c16063kpL = d2.fields_;
sbbVar = c16063kpL.containsKey(segment) ? c16063kpL.get(segment) : null;
if (!Values.isMapValue(sbbVar)) {
return null;
}
}
if (sbbVar.valueTypeCase_ == 6) {
d = (ldG) sbbVar.valueType_;
} else {
d = ldG.d();
}
String lastSegment = fieldPath.getLastSegment();
C16063kpL<String, sbb> c16063kpL2 = d.fields_;
if (c16063kpL2.containsKey(lastSegment)) {
return c16063kpL2.get(lastSegment);
}
return null;
}
private sbb buildProto() {
synchronized (this.overlayMap) {
ldG applyOverlay = applyOverlay(FieldPath.EMPTY_PATH, this.overlayMap);
if (applyOverlay != null) {
this.partialValue = sbb.d().c(applyOverlay).build();
this.overlayMap.clear();
}
}
return this.partialValue;
}
public final void delete(FieldPath fieldPath) {
Assert.hardAssert(!fieldPath.isEmpty(), "Cannot delete field for empty path on ObjectValue", new Object[0]);
setOverlay(fieldPath, null);
}
public final void set(FieldPath fieldPath, sbb sbbVar) {
Assert.hardAssert(!fieldPath.isEmpty(), "Cannot set field for empty path on ObjectValue", new Object[0]);
setOverlay(fieldPath, sbbVar);
}
public final void setAll(Map<FieldPath, sbb> map) {
for (Map.Entry<FieldPath, sbb> entry : map.entrySet()) {
FieldPath key = entry.getKey();
if (entry.getValue() == null) {
delete(key);
} else {
set(key, entry.getValue());
}
}
}
private void setOverlay(FieldPath fieldPath, sbb sbbVar) {
Map<String, Object> hashMap;
ldG d;
Map<String, Object> map = this.overlayMap;
for (int i = 0; i < fieldPath.length() - 1; i++) {
String segment = fieldPath.getSegment(i);
Object obj = map.get(segment);
if (obj instanceof Map) {
hashMap = (Map) obj;
} else {
if (obj instanceof sbb) {
sbb sbbVar2 = (sbb) obj;
if (sbb.HBt.c(sbbVar2.valueTypeCase_) == sbb.HBt.MAP_VALUE) {
if (sbbVar2.valueTypeCase_ == 6) {
d = (ldG) sbbVar2.valueType_;
} else {
d = ldG.d();
}
HashMap hashMap2 = new HashMap(Collections.unmodifiableMap(d.fields_));
map.put(segment, hashMap2);
map = hashMap2;
}
}
hashMap = new HashMap<>();
map.put(segment, hashMap);
}
map = hashMap;
}
map.put(fieldPath.getLastSegment(), sbbVar);
}
private ldG applyOverlay(FieldPath fieldPath, Map<String, Object> map) {
ldG.RVV a;
ldG d;
sbb extractNestedValue = extractNestedValue(this.partialValue, fieldPath);
if (Values.isMapValue(extractNestedValue)) {
if (extractNestedValue.valueTypeCase_ == 6) {
d = (ldG) extractNestedValue.valueType_;
} else {
d = ldG.d();
}
a = d.toBuilder();
} else {
a = ldG.a();
}
boolean z = false;
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value instanceof Map) {
ldG applyOverlay = applyOverlay(fieldPath.append(key), (Map) value);
if (applyOverlay != null) {
a.b(key, sbb.d().c(applyOverlay).build());
z = true;
}
} else {
if (value instanceof sbb) {
a.b(key, (sbb) value);
} else if (Collections.unmodifiableMap(((ldG) a.instance).fields_).containsKey(key)) {
Assert.hardAssert(value == null, "Expected entry to be a Map, a Value or null", new Object[0]);
a.e(key);
}
z = true;
}
}
if (z) {
return a.build();
}
return null;
}
public final boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof ObjectValue) {
return Values.equals(buildProto(), ((ObjectValue) obj).buildProto());
}
return false;
}
public final int hashCode() {
return buildProto().hashCode();
}
public final String toString() {
StringBuilder sb = new StringBuilder("ObjectValue{internalValue=");
sb.append(Values.canonicalId(buildProto()));
sb.append(UrlTreeKt.componentParamSuffixChar);
return sb.toString();
}
/* renamed from: clone, reason: merged with bridge method [inline-methods] */
public final ObjectValue m234clone() {
return new ObjectValue(buildProto());
}
}