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; /* loaded from: classes.dex */ 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; class BiMapEntry extends ForwardingMapEntry { private final Map.Entry a; BiMapEntry(Map.Entry entry) { this.a = entry; } @Override // com.google.common.collect.ForwardingMapEntry, java.util.Map.Entry public V setValue(V v) { Preconditions.b(AbstractBiMap.this.entrySet().contains(this), "entry no longer in map"); if (Objects.a(v, getValue())) { return v; } Preconditions.a(!AbstractBiMap.this.containsValue(v), "value already present: %s", v); V value = this.a.setValue(v); Preconditions.b(Objects.a(v, AbstractBiMap.this.get(getKey())), "entry no longer in map"); AbstractBiMap.this.updateInverseMap(getKey(), true, value, v); return value; } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.collect.ForwardingObject public Map.Entry delegate() { return this.a; } } private class EntrySet extends ForwardingSet> { final Set> a; private EntrySet() { this.a = AbstractBiMap.this.delegate.entrySet(); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public void clear() { AbstractBiMap.this.clear(); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public boolean contains(Object obj) { return Maps.a((Collection) 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.lang.Iterable, java.util.Set public Iterator> iterator() { return AbstractBiMap.this.entrySetIterator(); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public boolean remove(Object obj) { if (!this.a.contains(obj)) { return false; } Map.Entry entry = (Map.Entry) obj; ((AbstractBiMap) AbstractBiMap.this.inverse).delegate.remove(entry.getValue()); this.a.remove(entry); 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.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); } /* 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.a; } } static class Inverse extends AbstractBiMap { Inverse(Map map, AbstractBiMap abstractBiMap) { super(map, abstractBiMap); } private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { objectInputStream.defaultReadObject(); setInverse((AbstractBiMap) objectInputStream.readObject()); } private void writeObject(ObjectOutputStream objectOutputStream) throws IOException { objectOutputStream.defaultWriteObject(); objectOutputStream.writeObject(inverse()); } @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); } @Override // com.google.common.collect.AbstractBiMap, com.google.common.collect.ForwardingMap, com.google.common.collect.ForwardingObject protected /* bridge */ /* synthetic */ Object delegate() { return super.delegate(); } Object readResolve() { return inverse().inverse(); } @Override // com.google.common.collect.AbstractBiMap, com.google.common.collect.ForwardingMap, java.util.Map public /* bridge */ /* synthetic */ Collection values() { return super.values(); } } private class ValueSet extends ForwardingSet { final Set a; private ValueSet() { this.a = AbstractBiMap.this.inverse.keySet(); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator iterator() { return Maps.b(AbstractBiMap.this.entrySet().iterator()); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public Object[] toArray() { return standardToArray(); } @Override // com.google.common.collect.ForwardingObject public String toString() { return standardToString(); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public T[] toArray(T[] tArr) { return (T[]) standardToArray(tArr); } /* 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.a; } } private V putInBothMaps(K k, V v, boolean z) { checkKey(k); checkValue(v); boolean containsKey = containsKey(k); if (containsKey && Objects.a(v, get(k))) { return v; } if (z) { inverse().remove(v); } else { Preconditions.a(!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 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); } /* 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); } K checkKey(K k) { return k; } V checkValue(V v) { return v; } @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 boolean containsValue(Object obj) { return this.inverse.containsKey(obj); } @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; } Iterator> entrySetIterator() { final Iterator> it = this.delegate.entrySet().iterator(); return new Iterator>() { // from class: com.google.common.collect.AbstractBiMap.1 Map.Entry a; @Override // java.util.Iterator public boolean hasNext() { return it.hasNext(); } @Override // java.util.Iterator public void remove() { CollectPreconditions.a(this.a != null); V value = this.a.getValue(); it.remove(); AbstractBiMap.this.removeFromInverseMap(value); } @Override // java.util.Iterator public Map.Entry next() { this.a = (Map.Entry) it.next(); return new BiMapEntry(this.a); } }; } public V forcePut(K k, V v) { return putInBothMaps(k, v, true); } @Override // com.google.common.collect.BiMap public BiMap inverse() { return this.inverse; } @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; } AbstractBiMap makeInverse(Map map) { return new Inverse(map, this); } @Override // com.google.common.collect.ForwardingMap, java.util.Map public V put(K k, V v) { return putInBothMaps(k, v, false); } @Override // com.google.common.collect.ForwardingMap, java.util.Map 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 V remove(Object obj) { if (containsKey(obj)) { return removeFromBothMaps(obj); } return null; } void setDelegates(Map map, Map map2) { Preconditions.b(this.delegate == null); Preconditions.b(this.inverse == null); Preconditions.a(map.isEmpty()); Preconditions.a(map2.isEmpty()); Preconditions.a(map != map2); this.delegate = map; this.inverse = makeInverse(map2); } void setInverse(AbstractBiMap abstractBiMap) { this.inverse = abstractBiMap; } private class KeySet extends ForwardingSet { private KeySet() { } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public void clear() { AbstractBiMap.this.clear(); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator iterator() { return Maps.a(AbstractBiMap.this.entrySet().iterator()); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public boolean remove(Object obj) { if (!contains(obj)) { return false; } AbstractBiMap.this.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); } /* 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 AbstractBiMap.this.delegate.keySet(); } } AbstractBiMap(Map map, Map map2) { setDelegates(map, map2); } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.collect.ForwardingMap, com.google.common.collect.ForwardingObject public Map delegate() { return this.delegate; } @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; } private AbstractBiMap(Map map, AbstractBiMap abstractBiMap) { this.delegate = map; this.inverse = abstractBiMap; } }