alexandroid/decompiled/jadx/sources/com/google/common/graph/MapIteratorCache.java
KaKi87 a47fad5135 📦 Add decompiled Alexa 2.2.730155.0 (jadx, apktool, Hermes strings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 00:04:16 +01:00

105 lines
3.5 KiB
Java

package com.google.common.graph;
import com.google.common.base.Preconditions;
import com.google.common.collect.UnmodifiableIterator;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.AbstractSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
/* loaded from: classes8.dex */
class MapIteratorCache<K, V> {
private final Map<K, V> backingMap;
private volatile transient Map.Entry<K, V> cacheEntry;
public MapIteratorCache(Map<K, V> map) {
this.backingMap = (Map) Preconditions.checkNotNull(map);
}
public final void clear() {
clearCache();
this.backingMap.clear();
}
public void clearCache() {
this.cacheEntry = null;
}
public final boolean containsKey(Object obj) {
return getIfCached(obj) != null || this.backingMap.containsKey(obj);
}
public V get(Object obj) {
Preconditions.checkNotNull(obj);
V ifCached = getIfCached(obj);
return ifCached == null ? getWithoutCaching(obj) : ifCached;
}
public V getIfCached(Object obj) {
Map.Entry<K, V> entry = this.cacheEntry;
if (entry == null || entry.getKey() != obj) {
return null;
}
return entry.getValue();
}
public final V getWithoutCaching(Object obj) {
Preconditions.checkNotNull(obj);
return this.backingMap.get(obj);
}
@CanIgnoreReturnValue
public final V put(K k, V v) {
Preconditions.checkNotNull(k);
Preconditions.checkNotNull(v);
clearCache();
return this.backingMap.put(k, v);
}
@CanIgnoreReturnValue
public final V remove(Object obj) {
Preconditions.checkNotNull(obj);
clearCache();
return this.backingMap.remove(obj);
}
public final Set<K> unmodifiableKeySet() {
return new AbstractSet<K>() { // from class: com.google.common.graph.MapIteratorCache.1
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public boolean contains(Object obj) {
return MapIteratorCache.this.containsKey(obj);
}
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set
public UnmodifiableIterator<K> iterator() {
final Iterator<Map.Entry<K, V>> it2 = MapIteratorCache.this.backingMap.entrySet().iterator();
return new UnmodifiableIterator<K>(this) { // from class: com.google.common.graph.MapIteratorCache.1.1
final /* synthetic */ AnonymousClass1 this$1;
{
this.this$1 = this;
}
@Override // java.util.Iterator
public boolean hasNext() {
return it2.hasNext();
}
@Override // java.util.Iterator
public K next() {
Map.Entry entry = (Map.Entry) it2.next();
MapIteratorCache.this.cacheEntry = entry;
return (K) entry.getKey();
}
};
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public int size() {
return MapIteratorCache.this.backingMap.size();
}
};
}
}