what-the-bank/sources/com/google/common/graph/MapIteratorCache.java

112 lines
3.5 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.graph;
import com.google.common.base.Preconditions;
import com.google.common.collect.UnmodifiableIterator;
import java.util.AbstractSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public class MapIteratorCache<K, V> {
private final Map<K, V> backingMap;
private volatile transient Map.Entry<K, V> cacheEntry;
/* JADX INFO: Access modifiers changed from: package-private */
public MapIteratorCache(Map<K, V> map) {
this.backingMap = (Map) Preconditions.checkNotNull(map);
}
public final V put(K k, V v) {
clearCache();
return this.backingMap.put(k, v);
}
public final V remove(Object obj) {
clearCache();
return this.backingMap.remove(obj);
}
public final void clear() {
clearCache();
this.backingMap.clear();
}
public V get(Object obj) {
V ifCached = getIfCached(obj);
return ifCached != null ? ifCached : getWithoutCaching(obj);
}
public final V getWithoutCaching(Object obj) {
return this.backingMap.get(obj);
}
public final boolean containsKey(Object obj) {
return getIfCached(obj) != null || this.backingMap.containsKey(obj);
}
/* renamed from: com.google.common.graph.MapIteratorCache$1, reason: invalid class name */
/* loaded from: classes2.dex */
class AnonymousClass1 extends AbstractSet<K> {
final MapIteratorCache this$0;
AnonymousClass1(MapIteratorCache mapIteratorCache) {
this.this$0 = mapIteratorCache;
}
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set
public UnmodifiableIterator<K> iterator() {
return new UnmodifiableIterator<K>(this, this.this$0.backingMap.entrySet().iterator()) { // from class: com.google.common.graph.MapIteratorCache.1.1
final AnonymousClass1 this$1;
final Iterator val$entryIterator;
{
this.this$1 = this;
this.val$entryIterator = r2;
}
@Override // java.util.Iterator
public boolean hasNext() {
return this.val$entryIterator.hasNext();
}
@Override // java.util.Iterator
public K next() {
Map.Entry entry = (Map.Entry) this.val$entryIterator.next();
this.this$1.this$0.cacheEntry = entry;
return (K) entry.getKey();
}
};
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public int size() {
return this.this$0.backingMap.size();
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public boolean contains(Object obj) {
return this.this$0.containsKey(obj);
}
}
public final Set<K> unmodifiableKeySet() {
return new AnonymousClass1(this);
}
/* JADX INFO: Access modifiers changed from: protected */
public V getIfCached(Object obj) {
Map.Entry<K, V> entry = this.cacheEntry;
if (entry == null || entry.getKey() != obj) {
return null;
}
return entry.getValue();
}
/* JADX INFO: Access modifiers changed from: protected */
public void clearCache() {
this.cacheEntry = null;
}
}