package com.squareup.haha.guava.collect; import com.squareup.haha.guava.base.Function; import com.squareup.haha.guava.base.Joiner; import java.util.AbstractCollection; import java.util.AbstractMap; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; /* loaded from: classes.dex */ public final class Maps { /* JADX WARN: $VALUES field not found */ /* JADX WARN: Failed to restore enum class, 'enum' modifier and super class removed */ static abstract class EntryFunction implements Function, Object> { public static final EntryFunction KEY = new EntryFunction("KEY", 0) { // from class: com.squareup.haha.guava.collect.Maps.EntryFunction.1 { byte b = 0; } @Override // com.squareup.haha.guava.base.Function public final /* bridge */ /* synthetic */ Object apply(Map.Entry entry) { return entry.getKey(); } }; public static final EntryFunction VALUE = new EntryFunction("VALUE", 1) { // from class: com.squareup.haha.guava.collect.Maps.EntryFunction.2 { int i = 1; byte b = 0; } @Override // com.squareup.haha.guava.base.Function public final /* bridge */ /* synthetic */ Object apply(Map.Entry entry) { return entry.getValue(); } }; static { EntryFunction[] entryFunctionArr = {KEY, VALUE}; } private EntryFunction(String str, int i) { } /* synthetic */ EntryFunction(String str, int i, byte b) { this(str, i); } } static abstract class EntrySet extends Sets$ImprovedAbstractSet> { EntrySet() { } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public void clear() { map().clear(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean contains(Object obj) { if (obj instanceof Map.Entry) { Map.Entry entry = (Map.Entry) obj; Object key = entry.getKey(); Object safeGet = Maps.safeGet(map(), key); if (Joiner.equal(safeGet, entry.getValue()) && (safeGet != null || map().containsKey(key))) { return true; } } return false; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean isEmpty() { return map().isEmpty(); } abstract Map map(); @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean remove(Object obj) { if (contains(obj)) { return map().keySet().remove(((Map.Entry) obj).getKey()); } return false; } @Override // com.squareup.haha.guava.collect.Sets$ImprovedAbstractSet, java.util.AbstractSet, java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean removeAll(Collection collection) { try { return super.removeAll((Collection) Joiner.checkNotNull(collection)); } catch (UnsupportedOperationException unused) { return Joiner.removeAllImpl(this, collection.iterator()); } } @Override // com.squareup.haha.guava.collect.Sets$ImprovedAbstractSet, java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean retainAll(Collection collection) { try { return super.retainAll((Collection) Joiner.checkNotNull(collection)); } catch (UnsupportedOperationException unused) { HashSet hashSet = new HashSet(Maps.capacity(collection.size())); for (Object obj : collection) { if (contains(obj)) { hashSet.add(((Map.Entry) obj).getKey()); } } return map().keySet().retainAll(hashSet); } } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public int size() { return map().size(); } } static abstract class ImprovedAbstractMap extends AbstractMap { private transient Set> entrySet; private transient Set keySet; private transient Collection values; ImprovedAbstractMap() { } abstract Set> createEntrySet(); /* renamed from: createKeySet */ Set mo16createKeySet() { return new KeySet(this); } @Override // java.util.AbstractMap, java.util.Map public Set> entrySet() { Set> set = this.entrySet; if (set != null) { return set; } Set> createEntrySet = createEntrySet(); this.entrySet = createEntrySet; return createEntrySet; } @Override // java.util.AbstractMap, java.util.Map public Set keySet() { Set set = this.keySet; if (set != null) { return set; } Set mo16createKeySet = mo16createKeySet(); this.keySet = mo16createKeySet; return mo16createKeySet; } @Override // java.util.AbstractMap, java.util.Map public Collection values() { Collection collection = this.values; if (collection != null) { return collection; } Values values = new Values(this); this.values = values; return values; } } static class KeySet extends Sets$ImprovedAbstractSet { final Map map; KeySet(Map map) { this.map = (Map) Joiner.checkNotNull(map); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public void clear() { this.map.clear(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean contains(Object obj) { return this.map.containsKey(obj); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean isEmpty() { return this.map.isEmpty(); } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator iterator() { return Maps.keyIterator(this.map.entrySet().iterator()); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean remove(Object obj) { if (!contains(obj)) { return false; } this.map.remove(obj); return true; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public int size() { return this.map.size(); } } static class Values extends AbstractCollection { private Map map; Values(Map map) { this.map = (Map) Joiner.checkNotNull(map); } @Override // java.util.AbstractCollection, java.util.Collection public final void clear() { this.map.clear(); } @Override // java.util.AbstractCollection, java.util.Collection public final boolean contains(Object obj) { return this.map.containsValue(obj); } @Override // java.util.AbstractCollection, java.util.Collection public final boolean isEmpty() { return this.map.isEmpty(); } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable public final Iterator iterator() { return Maps.valueIterator(this.map.entrySet().iterator()); } @Override // java.util.AbstractCollection, java.util.Collection public final boolean remove(Object obj) { try { return super.remove(obj); } catch (UnsupportedOperationException unused) { for (Map.Entry entry : this.map.entrySet()) { if (Joiner.equal(obj, entry.getValue())) { this.map.remove(entry.getKey()); return true; } } return false; } } @Override // java.util.AbstractCollection, java.util.Collection public final boolean removeAll(Collection collection) { try { return super.removeAll((Collection) Joiner.checkNotNull(collection)); } catch (UnsupportedOperationException unused) { HashSet hashSet = new HashSet(); for (Map.Entry entry : this.map.entrySet()) { if (collection.contains(entry.getValue())) { hashSet.add(entry.getKey()); } } return this.map.keySet().removeAll(hashSet); } } @Override // java.util.AbstractCollection, java.util.Collection public final boolean retainAll(Collection collection) { try { return super.retainAll((Collection) Joiner.checkNotNull(collection)); } catch (UnsupportedOperationException unused) { HashSet hashSet = new HashSet(); for (Map.Entry entry : this.map.entrySet()) { if (collection.contains(entry.getValue())) { hashSet.add(entry.getKey()); } } return this.map.keySet().retainAll(hashSet); } } @Override // java.util.AbstractCollection, java.util.Collection public final int size() { return this.map.size(); } } static { new Joiner.MapJoiner(Collections2.STANDARD_JOINER, "=", (byte) 0); } public static int capacity(int i) { if (i >= 3) { if (i < 1073741824) { return i + (i / 3); } return Integer.MAX_VALUE; } if (i >= 0) { return i + 1; } throw new IllegalArgumentException("expectedSize cannot be negative but was: " + i); } public static Map.Entry immutableEntry(K k, V v) { return new ImmutableEntry(k, v); } static Iterator keyIterator(Iterator> it) { return Iterators.transform(it, EntryFunction.KEY); } public static HashMap newHashMap() { return new HashMap<>(); } static boolean safeContainsKey(Map map, Object obj) { Joiner.checkNotNull(map); try { return map.containsKey(obj); } catch (ClassCastException | NullPointerException unused) { return false; } } static V safeGet(Map map, Object obj) { Joiner.checkNotNull(map); try { return map.get(obj); } catch (ClassCastException | NullPointerException unused) { return null; } } static V safeRemove(Map map, Object obj) { Joiner.checkNotNull(map); try { return map.remove(obj); } catch (ClassCastException | NullPointerException unused) { return null; } } static Iterator valueIterator(Iterator> it) { return Iterators.transform(it, EntryFunction.VALUE); } }