package com.google.common.collect; import com.google.common.collect.ImmutableCollection; import java.io.Serializable; import java.util.AbstractMap; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.SortedMap; /* loaded from: classes.dex */ public abstract class ImmutableMap implements Map, Serializable { static final Map.Entry[] EMPTY_ENTRY_ARRAY = new Map.Entry[0]; private transient ImmutableSet> entrySet; private transient ImmutableSet keySet; private transient ImmutableSetMultimap multimapView; private transient ImmutableCollection values; public static class Builder { Comparator a; Object[] b; int c; boolean d; public Builder() { this(4); } private void a(int i) { int i2 = i * 2; Object[] objArr = this.b; if (i2 > objArr.length) { this.b = Arrays.copyOf(objArr, ImmutableCollection.Builder.a(objArr.length, i2)); this.d = false; } } void b() { int i; if (this.a != null) { if (this.d) { this.b = Arrays.copyOf(this.b, this.c * 2); } Map.Entry[] entryArr = new Map.Entry[this.c]; int i2 = 0; while (true) { i = this.c; if (i2 >= i) { break; } Object[] objArr = this.b; int i3 = i2 * 2; entryArr[i2] = new AbstractMap.SimpleImmutableEntry(objArr[i3], objArr[i3 + 1]); i2++; } Arrays.sort(entryArr, 0, i, Ordering.a(this.a).a(Maps.d())); for (int i4 = 0; i4 < this.c; i4++) { int i5 = i4 * 2; this.b[i5] = entryArr[i4].getKey(); this.b[i5 + 1] = entryArr[i4].getValue(); } } } Builder(int i) { this.b = new Object[i * 2]; this.c = 0; this.d = false; } public Builder a(K k, V v) { a(this.c + 1); CollectPreconditions.a(k, v); Object[] objArr = this.b; int i = this.c; objArr[i * 2] = k; objArr[(i * 2) + 1] = v; this.c = i + 1; return this; } public Builder a(Map.Entry entry) { return a(entry.getKey(), entry.getValue()); } public Builder a(Map map) { return a(map.entrySet()); } public Builder a(Iterable> iterable) { if (iterable instanceof Collection) { a(this.c + ((Collection) iterable).size()); } Iterator> it = iterable.iterator(); while (it.hasNext()) { a(it.next()); } return this; } public ImmutableMap a() { b(); this.d = true; return RegularImmutableMap.a(this.c, this.b); } } static abstract class IteratorBasedImmutableMap extends ImmutableMap { IteratorBasedImmutableMap() { } abstract UnmodifiableIterator> a(); @Override // com.google.common.collect.ImmutableMap ImmutableSet> createEntrySet() { return new ImmutableMapEntrySet() { // from class: com.google.common.collect.ImmutableMap.IteratorBasedImmutableMap.1EntrySetImpl @Override // com.google.common.collect.ImmutableMapEntrySet ImmutableMap a() { return IteratorBasedImmutableMap.this; } @Override // com.google.common.collect.ImmutableSet, com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set, java.util.NavigableSet public UnmodifiableIterator> iterator() { return IteratorBasedImmutableMap.this.a(); } }; } @Override // com.google.common.collect.ImmutableMap ImmutableSet createKeySet() { return new ImmutableMapKeySet(this); } @Override // com.google.common.collect.ImmutableMap ImmutableCollection createValues() { return new ImmutableMapValues(this); } @Override // com.google.common.collect.ImmutableMap, java.util.Map public /* bridge */ /* synthetic */ Set entrySet() { return super.entrySet(); } @Override // com.google.common.collect.ImmutableMap, java.util.Map public /* bridge */ /* synthetic */ Set keySet() { return super.keySet(); } @Override // com.google.common.collect.ImmutableMap, java.util.Map public /* bridge */ /* synthetic */ Collection values() { return super.values(); } } private final class MapViewOfValuesAsSingletonSets extends IteratorBasedImmutableMap> { private MapViewOfValuesAsSingletonSets() { } @Override // com.google.common.collect.ImmutableMap.IteratorBasedImmutableMap UnmodifiableIterator>> a() { final UnmodifiableIterator> it = ImmutableMap.this.entrySet().iterator(); return new UnmodifiableIterator>>(this) { // from class: com.google.common.collect.ImmutableMap.MapViewOfValuesAsSingletonSets.1 @Override // java.util.Iterator public boolean hasNext() { return it.hasNext(); } @Override // java.util.Iterator public Map.Entry> next() { final Map.Entry entry = (Map.Entry) it.next(); return new AbstractMapEntry>(this) { // from class: com.google.common.collect.ImmutableMap.MapViewOfValuesAsSingletonSets.1.1 @Override // com.google.common.collect.AbstractMapEntry, java.util.Map.Entry public K getKey() { return (K) entry.getKey(); } @Override // com.google.common.collect.AbstractMapEntry, java.util.Map.Entry public ImmutableSet getValue() { return ImmutableSet.of(entry.getValue()); } }; } }; } @Override // com.google.common.collect.ImmutableMap, java.util.Map public boolean containsKey(Object obj) { return ImmutableMap.this.containsKey(obj); } @Override // com.google.common.collect.ImmutableMap.IteratorBasedImmutableMap, com.google.common.collect.ImmutableMap ImmutableSet createKeySet() { return ImmutableMap.this.keySet(); } @Override // com.google.common.collect.ImmutableMap, java.util.Map public int hashCode() { return ImmutableMap.this.hashCode(); } @Override // com.google.common.collect.ImmutableMap boolean isHashCodeFast() { return ImmutableMap.this.isHashCodeFast(); } @Override // com.google.common.collect.ImmutableMap boolean isPartialView() { return ImmutableMap.this.isPartialView(); } @Override // java.util.Map public int size() { return ImmutableMap.this.size(); } @Override // com.google.common.collect.ImmutableMap, java.util.Map public ImmutableSet get(Object obj) { Object obj2 = ImmutableMap.this.get(obj); if (obj2 == null) { return null; } return ImmutableSet.of(obj2); } } static class SerializedForm implements Serializable { private final Object[] a; private final Object[] b; SerializedForm(ImmutableMap immutableMap) { this.a = new Object[immutableMap.size()]; this.b = new Object[immutableMap.size()]; UnmodifiableIterator> it = immutableMap.entrySet().iterator(); int i = 0; while (it.hasNext()) { Map.Entry next = it.next(); this.a[i] = next.getKey(); this.b[i] = next.getValue(); i++; } } Object a(Builder builder) { int i = 0; while (true) { Object[] objArr = this.a; if (i >= objArr.length) { return builder.a(); } builder.a(objArr[i], this.b[i]); i++; } } Object readResolve() { return a(new Builder<>(this.a.length)); } } ImmutableMap() { } public static Builder builder() { return new Builder<>(); } static void checkNoConflict(boolean z, String str, Map.Entry entry, Map.Entry entry2) { if (z) { return; } throw new IllegalArgumentException("Multiple entries with same " + str + ": " + entry + " and " + entry2); } public static ImmutableMap copyOf(Map map) { if ((map instanceof ImmutableMap) && !(map instanceof SortedMap)) { ImmutableMap immutableMap = (ImmutableMap) map; if (!immutableMap.isPartialView()) { return immutableMap; } } return copyOf(map.entrySet()); } static Map.Entry entryOf(K k, V v) { CollectPreconditions.a(k, v); return new AbstractMap.SimpleImmutableEntry(k, v); } public static ImmutableMap of() { return (ImmutableMap) RegularImmutableMap.d; } public ImmutableSetMultimap asMultimap() { if (isEmpty()) { return ImmutableSetMultimap.of(); } ImmutableSetMultimap immutableSetMultimap = this.multimapView; if (immutableSetMultimap != null) { return immutableSetMultimap; } ImmutableSetMultimap immutableSetMultimap2 = new ImmutableSetMultimap<>(new MapViewOfValuesAsSingletonSets(), size(), null); this.multimapView = immutableSetMultimap2; return immutableSetMultimap2; } @Override // java.util.Map @Deprecated public final void clear() { throw new UnsupportedOperationException(); } @Override // java.util.Map public boolean containsKey(Object obj) { return get(obj) != null; } @Override // java.util.Map public boolean containsValue(Object obj) { return values().contains(obj); } abstract ImmutableSet> createEntrySet(); abstract ImmutableSet createKeySet(); abstract ImmutableCollection createValues(); @Override // java.util.Map public boolean equals(Object obj) { return Maps.c(this, obj); } @Override // java.util.Map public abstract V get(Object obj); @Override // java.util.Map public int hashCode() { return Sets.a(entrySet()); } @Override // java.util.Map public boolean isEmpty() { return size() == 0; } boolean isHashCodeFast() { return false; } abstract boolean isPartialView(); UnmodifiableIterator keyIterator() { final UnmodifiableIterator> it = entrySet().iterator(); return new UnmodifiableIterator(this) { // from class: com.google.common.collect.ImmutableMap.1 @Override // java.util.Iterator public boolean hasNext() { return it.hasNext(); } @Override // java.util.Iterator public K next() { return (K) ((Map.Entry) it.next()).getKey(); } }; } @Override // java.util.Map @Deprecated public final V put(K k, V v) { throw new UnsupportedOperationException(); } @Override // java.util.Map @Deprecated public final void putAll(Map map) { throw new UnsupportedOperationException(); } @Override // java.util.Map @Deprecated public final V remove(Object obj) { throw new UnsupportedOperationException(); } public String toString() { return Maps.a(this); } Object writeReplace() { return new SerializedForm(this); } public static ImmutableMap of(K k, V v) { CollectPreconditions.a(k, v); return RegularImmutableMap.a(1, new Object[]{k, v}); } @Override // java.util.Map public ImmutableSet> entrySet() { ImmutableSet> immutableSet = this.entrySet; if (immutableSet != null) { return immutableSet; } ImmutableSet> createEntrySet = createEntrySet(); this.entrySet = createEntrySet; return createEntrySet; } @Override // java.util.Map public ImmutableSet keySet() { ImmutableSet immutableSet = this.keySet; if (immutableSet != null) { return immutableSet; } ImmutableSet createKeySet = createKeySet(); this.keySet = createKeySet; return createKeySet; } @Override // java.util.Map public ImmutableCollection values() { ImmutableCollection immutableCollection = this.values; if (immutableCollection != null) { return immutableCollection; } ImmutableCollection createValues = createValues(); this.values = createValues; return createValues; } public static ImmutableMap of(K k, V v, K k2, V v2) { CollectPreconditions.a(k, v); CollectPreconditions.a(k2, v2); return RegularImmutableMap.a(2, new Object[]{k, v, k2, v2}); } public static ImmutableMap copyOf(Iterable> iterable) { Builder builder = new Builder(iterable instanceof Collection ? ((Collection) iterable).size() : 4); builder.a(iterable); return builder.a(); } public static ImmutableMap of(K k, V v, K k2, V v2, K k3, V v3) { CollectPreconditions.a(k, v); CollectPreconditions.a(k2, v2); CollectPreconditions.a(k3, v3); return RegularImmutableMap.a(3, new Object[]{k, v, k2, v2, k3, v3}); } public static ImmutableMap of(K k, V v, K k2, V v2, K k3, V v3, K k4, V v4) { CollectPreconditions.a(k, v); CollectPreconditions.a(k2, v2); CollectPreconditions.a(k3, v3); CollectPreconditions.a(k4, v4); return RegularImmutableMap.a(4, new Object[]{k, v, k2, v2, k3, v3, k4, v4}); } public static ImmutableMap of(K k, V v, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) { CollectPreconditions.a(k, v); CollectPreconditions.a(k2, v2); CollectPreconditions.a(k3, v3); CollectPreconditions.a(k4, v4); CollectPreconditions.a(k5, v5); return RegularImmutableMap.a(5, new Object[]{k, v, k2, v2, k3, v3, k4, v4, k5, v5}); } }