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

121 lines
4.6 KiB
Java

package com.google.firebase.firestore.model.mutation;
import com.airbnb.deeplinkdispatch.UrlTreeKt;
import com.google.firebase.Timestamp;
import com.google.firebase.firestore.model.DocumentKey;
import com.google.firebase.firestore.model.FieldPath;
import com.google.firebase.firestore.model.MutableDocument;
import com.google.firebase.firestore.model.ObjectValue;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import o.sbb;
/* loaded from: classes2.dex */
public final class PatchMutation extends Mutation {
private final FieldMask mask;
private final ObjectValue value;
public PatchMutation(DocumentKey documentKey, ObjectValue objectValue, FieldMask fieldMask, Precondition precondition) {
this(documentKey, objectValue, fieldMask, precondition, new ArrayList());
}
public PatchMutation(DocumentKey documentKey, ObjectValue objectValue, FieldMask fieldMask, Precondition precondition, List<FieldTransform> list) {
super(documentKey, precondition, list);
this.value = objectValue;
this.mask = fieldMask;
}
public final boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
PatchMutation patchMutation = (PatchMutation) obj;
return hasSameKeyAndPrecondition(patchMutation) && this.value.equals(patchMutation.value) && getFieldTransforms().equals(patchMutation.getFieldTransforms());
}
public final int hashCode() {
return (keyAndPreconditionHashCode() * 31) + this.value.hashCode();
}
public final String toString() {
StringBuilder sb = new StringBuilder("PatchMutation{");
sb.append(keyAndPreconditionToString());
sb.append(", mask=");
sb.append(this.mask);
sb.append(", value=");
sb.append(this.value);
sb.append(UrlTreeKt.componentParamSuffix);
return sb.toString();
}
@Override // com.google.firebase.firestore.model.mutation.Mutation
public final void applyToRemoteDocument(MutableDocument mutableDocument, MutationResult mutationResult) {
verifyKeyMatches(mutableDocument);
if (!getPrecondition().isValidFor(mutableDocument)) {
mutableDocument.convertToUnknownDocument(mutationResult.getVersion());
return;
}
Map<FieldPath, sbb> serverTransformResults = serverTransformResults(mutableDocument, mutationResult.getTransformResults());
ObjectValue data = mutableDocument.getData();
data.setAll(getPatch());
data.setAll(serverTransformResults);
mutableDocument.convertToFoundDocument(mutationResult.getVersion(), mutableDocument.getData()).setHasCommittedMutations();
}
@Override // com.google.firebase.firestore.model.mutation.Mutation
public final FieldMask applyToLocalView(MutableDocument mutableDocument, FieldMask fieldMask, Timestamp timestamp) {
verifyKeyMatches(mutableDocument);
if (!getPrecondition().isValidFor(mutableDocument)) {
return fieldMask;
}
Map<FieldPath, sbb> localTransformResults = localTransformResults(timestamp, mutableDocument);
Map<FieldPath, sbb> patch = getPatch();
ObjectValue data = mutableDocument.getData();
data.setAll(patch);
data.setAll(localTransformResults);
mutableDocument.convertToFoundDocument(mutableDocument.getVersion(), mutableDocument.getData()).setHasLocalMutations();
if (fieldMask == null) {
return null;
}
HashSet hashSet = new HashSet(fieldMask.getMask());
hashSet.addAll(this.mask.getMask());
hashSet.addAll(getFieldTransformPaths());
return FieldMask.fromSet(hashSet);
}
private List<FieldPath> getFieldTransformPaths() {
ArrayList arrayList = new ArrayList();
Iterator<FieldTransform> it = getFieldTransforms().iterator();
while (it.hasNext()) {
arrayList.add(it.next().getFieldPath());
}
return arrayList;
}
private Map<FieldPath, sbb> getPatch() {
HashMap hashMap = new HashMap();
for (FieldPath fieldPath : this.mask.getMask()) {
if (!fieldPath.isEmpty()) {
hashMap.put(fieldPath, this.value.get(fieldPath));
}
}
return hashMap;
}
public final ObjectValue getValue() {
return this.value;
}
@Override // com.google.firebase.firestore.model.mutation.Mutation
public final FieldMask getFieldMask() {
return this.mask;
}
}