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

97 lines
3.9 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.firebase.firestore.local;
import com.google.firebase.database.collection.ImmutableSortedSet;
import com.google.firebase.firestore.core.Target;
import com.google.firebase.firestore.model.DocumentKey;
import com.google.firebase.firestore.model.SnapshotVersion;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public final class MemoryTargetCache implements TargetCache {
private int highestTargetId;
private final MemoryPersistence persistence;
private final Map<Target, TargetData> targets = new HashMap();
private final ReferenceSet references = new ReferenceSet();
private SnapshotVersion lastRemoteSnapshotVersion = SnapshotVersion.NONE;
private long highestSequenceNumber = 0;
/* JADX INFO: Access modifiers changed from: package-private */
public MemoryTargetCache(MemoryPersistence memoryPersistence) {
this.persistence = memoryPersistence;
}
@Override // com.google.firebase.firestore.local.TargetCache
public final void addTargetData(TargetData targetData) {
this.targets.put(targetData.getTarget(), targetData);
int targetId = targetData.getTargetId();
if (targetId > this.highestTargetId) {
this.highestTargetId = targetId;
}
if (targetData.getSequenceNumber() > this.highestSequenceNumber) {
this.highestSequenceNumber = targetData.getSequenceNumber();
}
}
@Override // com.google.firebase.firestore.local.TargetCache
public final void updateTargetData(TargetData targetData) {
addTargetData(targetData);
}
public final void removeTargetData(TargetData targetData) {
this.targets.remove(targetData.getTarget());
this.references.removeReferencesForId(targetData.getTargetId());
}
@Override // com.google.firebase.firestore.local.TargetCache
public final TargetData getTargetData(Target target) {
return this.targets.get(target);
}
@Override // com.google.firebase.firestore.local.TargetCache
public final void addMatchingKeys(ImmutableSortedSet<DocumentKey> immutableSortedSet, int i) {
this.references.addReferences(immutableSortedSet, i);
ReferenceDelegate referenceDelegate = this.persistence.getReferenceDelegate();
Iterator<DocumentKey> it = immutableSortedSet.iterator();
while (it.hasNext()) {
referenceDelegate.addReference(it.next());
}
}
@Override // com.google.firebase.firestore.local.TargetCache
public final void removeMatchingKeys(ImmutableSortedSet<DocumentKey> immutableSortedSet, int i) {
this.references.removeReferences(immutableSortedSet, i);
ReferenceDelegate referenceDelegate = this.persistence.getReferenceDelegate();
Iterator<DocumentKey> it = immutableSortedSet.iterator();
while (it.hasNext()) {
referenceDelegate.removeReference(it.next());
}
}
@Override // com.google.firebase.firestore.local.TargetCache
public final ImmutableSortedSet<DocumentKey> getMatchingKeysForTargetId(int i) {
return this.references.referencesForId(i);
}
public final boolean containsKey(DocumentKey documentKey) {
return this.references.containsKey(documentKey);
}
@Override // com.google.firebase.firestore.local.TargetCache
public final void setLastRemoteSnapshotVersion(SnapshotVersion snapshotVersion) {
this.lastRemoteSnapshotVersion = snapshotVersion;
}
@Override // com.google.firebase.firestore.local.TargetCache
public final SnapshotVersion getLastRemoteSnapshotVersion() {
return this.lastRemoteSnapshotVersion;
}
@Override // com.google.firebase.firestore.local.TargetCache
public final int getHighestTargetId() {
return this.highestTargetId;
}
}