package com.google.common.collect; import com.google.common.base.Objects; import com.google.common.base.Preconditions; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Collection; 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 abstract class AbstractBiMap extends ForwardingMap implements BiMap, Serializable { private static final long serialVersionUID = 0; private transient Map delegate; private transient Set> entrySet; transient AbstractBiMap inverse; private transient Set keySet; private transient Set valueSet; K checkKey(K k) { return k; } V checkValue(V v) { return v; } /* JADX INFO: Access modifiers changed from: package-private */ public AbstractBiMap(Map map, Map map2) { setDelegates(map, map2); } private AbstractBiMap(Map map, AbstractBiMap abstractBiMap) { this.delegate = map; this.inverse = abstractBiMap; } /* JADX INFO: Access modifiers changed from: package-private */ public void setDelegates(Map map, Map map2) { Preconditions.checkState(this.delegate == null); Preconditions.checkState(this.inverse == null); Preconditions.checkArgument(map.isEmpty()); Preconditions.checkArgument(map2.isEmpty()); Preconditions.checkArgument(map != map2); this.delegate = map; this.inverse = makeInverse(map2); } AbstractBiMap makeInverse(Map map) { return new Inverse(map, this); } @Override // com.google.common.collect.ForwardingMap, java.util.Map public boolean containsValue(Object obj) { return this.inverse.containsKey(obj); } @Override // com.google.common.collect.ForwardingMap, java.util.Map, com.google.common.collect.BiMap public V put(K k, V v) { return putInBothMaps(k, v, false); } @Override // com.google.common.collect.BiMap public V forcePut(K k, V v) { return putInBothMaps(k, v, true); } private V putInBothMaps(K k, V v, boolean z) { checkKey(k); checkValue(v); boolean containsKey = containsKey(k); if (containsKey && Objects.equal(v, get(k))) { return v; } if (z) { inverse().remove(v); } else { Preconditions.checkArgument(!containsValue(v), "value already present: %s", v); } V put = this.delegate.put(k, v); updateInverseMap(k, containsKey, put, v); return put; } /* JADX INFO: Access modifiers changed from: private */ public void updateInverseMap(K k, boolean z, V v, V v2) { if (z) { removeFromInverseMap(v); } this.inverse.delegate.put(v2, k); } @Override // com.google.common.collect.ForwardingMap, java.util.Map public V remove(Object obj) { if (containsKey(obj)) { return removeFromBothMaps(obj); } return null; } /* JADX INFO: Access modifiers changed from: private */ public V removeFromBothMaps(Object obj) { V remove = this.delegate.remove(obj); removeFromInverseMap(remove); return remove; } /* JADX INFO: Access modifiers changed from: private */ public void removeFromInverseMap(V v) { this.inverse.delegate.remove(v); } @Override // com.google.common.collect.ForwardingMap, java.util.Map, com.google.common.collect.BiMap public void putAll(Map map) { for (Map.Entry entry : map.entrySet()) { put(entry.getKey(), entry.getValue()); } } @Override // com.google.common.collect.ForwardingMap, java.util.Map public void clear() { this.delegate.clear(); this.inverse.delegate.clear(); } @Override // com.google.common.collect.ForwardingMap, java.util.Map public Set keySet() { Set set = this.keySet; if (set != null) { return set; } KeySet keySet = new KeySet(); this.keySet = keySet; return keySet; } /* loaded from: classes2.dex */ class KeySet extends ForwardingSet { final AbstractBiMap this$0; private KeySet(AbstractBiMap abstractBiMap) { this.this$0 = abstractBiMap; } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.collect.ForwardingSet, com.google.common.collect.ForwardingCollection, com.google.common.collect.ForwardingObject public Set delegate() { return this.this$0.delegate.keySet(); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public void clear() { this.this$0.clear(); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public boolean remove(Object obj) { if (!contains(obj)) { return false; } this.this$0.removeFromBothMaps(obj); return true; } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public boolean removeAll(Collection collection) { return standardRemoveAll(collection); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public boolean retainAll(Collection collection) { return standardRetainAll(collection); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator iterator() { return Maps.keyIterator(this.this$0.entrySet().iterator()); } } @Override // com.google.common.collect.ForwardingMap, java.util.Map public Set values() { Set set = this.valueSet; if (set != null) { return set; } ValueSet valueSet = new ValueSet(); this.valueSet = valueSet; return valueSet; } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public class ValueSet extends ForwardingSet { final AbstractBiMap this$0; final Set valuesDelegate; private ValueSet(AbstractBiMap abstractBiMap) { this.this$0 = abstractBiMap; this.valuesDelegate = abstractBiMap.inverse.keySet(); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator iterator() { return Maps.valueIterator(this.this$0.entrySet().iterator()); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public Object[] toArray() { return standardToArray(); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public T[] toArray(T[] tArr) { return (T[]) standardToArray(tArr); } @Override // com.google.common.collect.ForwardingObject public String toString() { return standardToString(); } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.collect.ForwardingSet, com.google.common.collect.ForwardingCollection, com.google.common.collect.ForwardingObject public Set delegate() { return this.valuesDelegate; } } @Override // com.google.common.collect.ForwardingMap, java.util.Map public Set> entrySet() { Set> set = this.entrySet; if (set != null) { return set; } EntrySet entrySet = new EntrySet(); this.entrySet = entrySet; return entrySet; } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public class BiMapEntry extends ForwardingMapEntry { private final Map.Entry delegate; final AbstractBiMap this$0; BiMapEntry(AbstractBiMap abstractBiMap, Map.Entry entry) { this.this$0 = abstractBiMap; this.delegate = entry; } @Override // com.google.common.collect.ForwardingMapEntry, java.util.Map.Entry public V setValue(V v) { this.this$0.checkValue(v); Preconditions.checkState(this.this$0.entrySet().contains(this), "entry no longer in map"); if (Objects.equal(v, getValue())) { return v; } Preconditions.checkArgument(!this.this$0.containsValue(v), "value already present: %s", v); V value = this.delegate.setValue(v); Preconditions.checkState(Objects.equal(v, this.this$0.get(getKey())), "entry no longer in map"); this.this$0.updateInverseMap(getKey(), true, value, v); return value; } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.collect.ForwardingMapEntry, com.google.common.collect.ForwardingObject public Map.Entry delegate() { return this.delegate; } } Iterator> entrySetIterator() { return new Iterator>(this, this.delegate.entrySet().iterator()) { // from class: com.google.common.collect.AbstractBiMap.1 Map.Entry entry; final AbstractBiMap this$0; final Iterator val$iterator; { this.this$0 = this; this.val$iterator = r2; } @Override // java.util.Iterator public boolean hasNext() { return this.val$iterator.hasNext(); } @Override // java.util.Iterator public Map.Entry next() { Map.Entry entry = (Map.Entry) this.val$iterator.next(); this.entry = entry; return new BiMapEntry(this.this$0, entry); } @Override // java.util.Iterator public void remove() { CollectPreconditions.checkRemove(this.entry != null); V value = this.entry.getValue(); this.val$iterator.remove(); this.this$0.removeFromInverseMap(value); this.entry = null; } }; } /* loaded from: classes2.dex */ class EntrySet extends ForwardingSet> { final Set> esDelegate; final AbstractBiMap this$0; private EntrySet(AbstractBiMap abstractBiMap) { this.this$0 = abstractBiMap; this.esDelegate = abstractBiMap.delegate.entrySet(); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public void clear() { this.this$0.clear(); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public boolean remove(Object obj) { if (!this.esDelegate.contains(obj)) { return false; } Map.Entry entry = (Map.Entry) obj; ((AbstractBiMap) this.this$0.inverse).delegate.remove(entry.getValue()); this.esDelegate.remove(entry); return true; } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator> iterator() { return this.this$0.entrySetIterator(); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public Object[] toArray() { return standardToArray(); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public T[] toArray(T[] tArr) { return (T[]) standardToArray(tArr); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public boolean contains(Object obj) { return Maps.containsEntryImpl(delegate(), obj); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public boolean containsAll(Collection collection) { return standardContainsAll(collection); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public boolean removeAll(Collection collection) { return standardRemoveAll(collection); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public boolean retainAll(Collection collection) { return standardRetainAll(collection); } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.collect.ForwardingSet, com.google.common.collect.ForwardingCollection, com.google.common.collect.ForwardingObject public Set> delegate() { return this.esDelegate; } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public static class Inverse extends AbstractBiMap { private static final long serialVersionUID = 0; @Override // com.google.common.collect.AbstractBiMap, com.google.common.collect.ForwardingMap, com.google.common.collect.ForwardingObject protected /* bridge */ /* synthetic */ Object delegate() { return super.delegate(); } @Override // com.google.common.collect.AbstractBiMap, com.google.common.collect.ForwardingMap, java.util.Map public /* bridge */ /* synthetic */ Collection values() { return super.values(); } Inverse(Map map, AbstractBiMap abstractBiMap) { super(map, abstractBiMap); } @Override // com.google.common.collect.AbstractBiMap K checkKey(K k) { return this.inverse.checkValue(k); } @Override // com.google.common.collect.AbstractBiMap V checkValue(V v) { return this.inverse.checkKey(v); } private void writeObject(ObjectOutputStream objectOutputStream) throws IOException { objectOutputStream.defaultWriteObject(); objectOutputStream.writeObject(inverse()); } private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { objectInputStream.defaultReadObject(); setInverse((AbstractBiMap) objectInputStream.readObject()); } Object readResolve() { return inverse().inverse(); } } void setInverse(AbstractBiMap abstractBiMap) { this.inverse = abstractBiMap; } @Override // com.google.common.collect.BiMap public BiMap inverse() { return this.inverse; } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.collect.ForwardingMap, com.google.common.collect.ForwardingObject public Map delegate() { return this.delegate; } }