package com.google.common.collect; import com.google.common.base.Preconditions; 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: classes2.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; abstract ImmutableSet> createEntrySet(); abstract ImmutableSet createKeySet(); abstract ImmutableCollection createValues(); @Override // java.util.Map public abstract V get(Object obj); /* JADX INFO: Access modifiers changed from: package-private */ public boolean isHashCodeFast() { return false; } /* JADX INFO: Access modifiers changed from: package-private */ public abstract boolean isPartialView(); public static ImmutableMap of() { return (ImmutableMap) RegularImmutableMap.EMPTY; } public static ImmutableMap of(K k, V v) { CollectPreconditions.checkEntryNotNull(k, v); return RegularImmutableMap.create(1, new Object[]{k, v}); } public static ImmutableMap of(K k, V v, K k2, V v2) { CollectPreconditions.checkEntryNotNull(k, v); CollectPreconditions.checkEntryNotNull(k2, v2); return RegularImmutableMap.create(2, new Object[]{k, v, k2, v2}); } public static ImmutableMap of(K k, V v, K k2, V v2, K k3, V v3) { CollectPreconditions.checkEntryNotNull(k, v); CollectPreconditions.checkEntryNotNull(k2, v2); CollectPreconditions.checkEntryNotNull(k3, v3); return RegularImmutableMap.create(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.checkEntryNotNull(k, v); CollectPreconditions.checkEntryNotNull(k2, v2); CollectPreconditions.checkEntryNotNull(k3, v3); CollectPreconditions.checkEntryNotNull(k4, v4); return RegularImmutableMap.create(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.checkEntryNotNull(k, v); CollectPreconditions.checkEntryNotNull(k2, v2); CollectPreconditions.checkEntryNotNull(k3, v3); CollectPreconditions.checkEntryNotNull(k4, v4); CollectPreconditions.checkEntryNotNull(k5, v5); return RegularImmutableMap.create(5, new Object[]{k, v, k2, v2, k3, v3, k4, v4, k5, v5}); } /* JADX INFO: Access modifiers changed from: package-private */ public static Map.Entry entryOf(K k, V v) { CollectPreconditions.checkEntryNotNull(k, v); return new AbstractMap.SimpleImmutableEntry(k, v); } public static Builder builder() { return new Builder<>(); } public static Builder builderWithExpectedSize(int i) { CollectPreconditions.checkNonnegative(i, "expectedSize"); return new Builder<>(i); } /* JADX INFO: Access modifiers changed from: package-private */ public static void checkNoConflict(boolean z, String str, Map.Entry entry, Map.Entry entry2) { if (!z) { throw conflictException(str, entry, entry2); } } static IllegalArgumentException conflictException(String str, Object obj, Object obj2) { String valueOf = String.valueOf(obj); String valueOf2 = String.valueOf(obj2); StringBuilder sb = new StringBuilder(String.valueOf(str).length() + 34 + String.valueOf(valueOf).length() + String.valueOf(valueOf2).length()); sb.append("Multiple entries with same "); sb.append(str); sb.append(": "); sb.append(valueOf); sb.append(" and "); sb.append(valueOf2); return new IllegalArgumentException(sb.toString()); } /* loaded from: classes2.dex */ public static class Builder { Object[] alternatingKeysAndValues; boolean entriesUsed; int size; Comparator valueComparator; public Builder() { this(4); } /* JADX INFO: Access modifiers changed from: package-private */ public Builder(int i) { this.alternatingKeysAndValues = new Object[i << 1]; this.size = 0; this.entriesUsed = false; } private void ensureCapacity(int i) { int i2 = i << 1; Object[] objArr = this.alternatingKeysAndValues; if (i2 > objArr.length) { this.alternatingKeysAndValues = Arrays.copyOf(objArr, ImmutableCollection.Builder.expandedCapacity(objArr.length, i2)); this.entriesUsed = false; } } public Builder put(K k, V v) { ensureCapacity(this.size + 1); CollectPreconditions.checkEntryNotNull(k, v); Object[] objArr = this.alternatingKeysAndValues; int i = this.size; int i2 = i << 1; objArr[i2] = k; objArr[i2 + 1] = v; this.size = i + 1; return this; } public Builder put(Map.Entry entry) { return put(entry.getKey(), entry.getValue()); } public Builder putAll(Map map) { return putAll(map.entrySet()); } public Builder putAll(Iterable> iterable) { if (iterable instanceof Collection) { ensureCapacity(this.size + ((Collection) iterable).size()); } Iterator> it = iterable.iterator(); while (it.hasNext()) { put(it.next()); } return this; } public Builder orderEntriesByValue(Comparator comparator) { Preconditions.checkState(this.valueComparator == null, "valueComparator was already set"); this.valueComparator = (Comparator) Preconditions.checkNotNull(comparator, "valueComparator"); return this; } /* JADX INFO: Access modifiers changed from: package-private */ public Builder combine(Builder builder) { Preconditions.checkNotNull(builder); ensureCapacity(this.size + builder.size); System.arraycopy(builder.alternatingKeysAndValues, 0, this.alternatingKeysAndValues, this.size << 1, builder.size << 1); this.size += builder.size; return this; } public ImmutableMap build() { sortEntries(); this.entriesUsed = true; return RegularImmutableMap.create(this.size, this.alternatingKeysAndValues); } /* JADX INFO: Access modifiers changed from: package-private */ public void sortEntries() { int i; if (this.valueComparator != null) { if (this.entriesUsed) { this.alternatingKeysAndValues = Arrays.copyOf(this.alternatingKeysAndValues, this.size << 1); } Map.Entry[] entryArr = new Map.Entry[this.size]; int i2 = 0; while (true) { i = this.size; if (i2 >= i) { break; } Object[] objArr = this.alternatingKeysAndValues; int i3 = i2 << 1; entryArr[i2] = new AbstractMap.SimpleImmutableEntry(objArr[i3], objArr[i3 + 1]); i2++; } Arrays.sort(entryArr, 0, i, Ordering.from(this.valueComparator).onResultOf(Maps.valueFunction())); for (int i4 = 0; i4 < this.size; i4++) { int i5 = i4 << 1; this.alternatingKeysAndValues[i5] = entryArr[i4].getKey(); this.alternatingKeysAndValues[i5 + 1] = entryArr[i4].getValue(); } } } } 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()); } public static ImmutableMap copyOf(Iterable> iterable) { Builder builder = new Builder(iterable instanceof Collection ? ((Collection) iterable).size() : 4); builder.putAll(iterable); return builder.build(); } /* loaded from: classes2.dex */ static abstract class IteratorBasedImmutableMap extends ImmutableMap { abstract UnmodifiableIterator> entryIterator(); @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(); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ImmutableMap public ImmutableSet createKeySet() { return new ImmutableMapKeySet(this); } @Override // com.google.common.collect.ImmutableMap ImmutableSet> createEntrySet() { return new ImmutableMapEntrySet(this) { // from class: com.google.common.collect.ImmutableMap.IteratorBasedImmutableMap.1EntrySetImpl final IteratorBasedImmutableMap this$0; { this.this$0 = 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, com.google.common.collect.SortedIterable public /* bridge */ /* synthetic */ Iterator iterator() { return iterator(); } @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, com.google.common.collect.SortedIterable public UnmodifiableIterator> iterator() { return this.this$0.entryIterator(); } @Override // com.google.common.collect.ImmutableMapEntrySet ImmutableMap map() { return this.this$0; } }; } @Override // com.google.common.collect.ImmutableMap ImmutableCollection createValues() { return new ImmutableMapValues(this); } } @Override // java.util.Map @Deprecated public final V put(K k, V v) { throw new UnsupportedOperationException(); } @Override // java.util.Map @Deprecated public final V remove(Object obj) { throw new UnsupportedOperationException(); } @Override // java.util.Map @Deprecated public final void putAll(Map map) { throw new UnsupportedOperationException(); } @Override // java.util.Map @Deprecated public final void clear() { throw new UnsupportedOperationException(); } @Override // java.util.Map public boolean isEmpty() { return size() == 0; } @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); } @Override // java.util.Map public final V getOrDefault(Object obj, V v) { V v2 = get(obj); return v2 != null ? v2 : 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; } /* JADX INFO: Access modifiers changed from: package-private */ public UnmodifiableIterator keyIterator() { return new UnmodifiableIterator(this, entrySet().iterator()) { // from class: com.google.common.collect.ImmutableMap.1 final UnmodifiableIterator val$entryIterator; { this.val$entryIterator = r2; } @Override // java.util.Iterator public boolean hasNext() { return this.val$entryIterator.hasNext(); } @Override // java.util.Iterator public K next() { return (K) ((Map.Entry) this.val$entryIterator.next()).getKey(); } }; } @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 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; } /* loaded from: classes2.dex */ final class MapViewOfValuesAsSingletonSets extends IteratorBasedImmutableMap> { final ImmutableMap this$0; private MapViewOfValuesAsSingletonSets(ImmutableMap immutableMap) { this.this$0 = immutableMap; } @Override // java.util.Map public final int size() { return this.this$0.size(); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ImmutableMap.IteratorBasedImmutableMap, com.google.common.collect.ImmutableMap public final ImmutableSet createKeySet() { return this.this$0.keySet(); } @Override // com.google.common.collect.ImmutableMap, java.util.Map public final boolean containsKey(Object obj) { return this.this$0.containsKey(obj); } @Override // com.google.common.collect.ImmutableMap, java.util.Map public final ImmutableSet get(Object obj) { Object obj2 = this.this$0.get(obj); if (obj2 == null) { return null; } return ImmutableSet.of(obj2); } @Override // com.google.common.collect.ImmutableMap final boolean isPartialView() { return this.this$0.isPartialView(); } @Override // com.google.common.collect.ImmutableMap, java.util.Map public final int hashCode() { return this.this$0.hashCode(); } @Override // com.google.common.collect.ImmutableMap final boolean isHashCodeFast() { return this.this$0.isHashCodeFast(); } @Override // com.google.common.collect.ImmutableMap.IteratorBasedImmutableMap final UnmodifiableIterator>> entryIterator() { return new UnmodifiableIterator>>(this, this.this$0.entrySet().iterator()) { // from class: com.google.common.collect.ImmutableMap.MapViewOfValuesAsSingletonSets.1 final Iterator val$backingIterator; { this.val$backingIterator = r2; } @Override // java.util.Iterator public boolean hasNext() { return this.val$backingIterator.hasNext(); } @Override // java.util.Iterator public Map.Entry> next() { return new AbstractMapEntry>(this, (Map.Entry) this.val$backingIterator.next()) { // from class: com.google.common.collect.ImmutableMap.MapViewOfValuesAsSingletonSets.1.1 final Map.Entry val$backingEntry; { this.val$backingEntry = r2; } @Override // com.google.common.collect.AbstractMapEntry, java.util.Map.Entry public K getKey() { return (K) this.val$backingEntry.getKey(); } @Override // com.google.common.collect.AbstractMapEntry, java.util.Map.Entry public ImmutableSet getValue() { return ImmutableSet.of(this.val$backingEntry.getValue()); } }; } }; } } @Override // java.util.Map public boolean equals(Object obj) { return Maps.equalsImpl(this, obj); } @Override // java.util.Map public int hashCode() { return Sets.hashCodeImpl(entrySet()); } public String toString() { return Maps.toStringImpl(this); } /* loaded from: classes2.dex */ static class SerializedForm implements Serializable { private static final boolean USE_LEGACY_SERIALIZATION = true; private static final long serialVersionUID = 0; private final Object keys; private final Object values; /* JADX INFO: Access modifiers changed from: package-private */ public SerializedForm(ImmutableMap immutableMap) { Object[] objArr = new Object[immutableMap.size()]; Object[] objArr2 = new Object[immutableMap.size()]; UnmodifiableIterator> it = immutableMap.entrySet().iterator(); int i = 0; while (it.hasNext()) { Map.Entry next = it.next(); objArr[i] = next.getKey(); objArr2[i] = next.getValue(); i++; } this.keys = objArr; this.values = objArr2; } /* JADX WARN: Multi-variable type inference failed */ final Object readResolve() { Object obj = this.keys; if (!(obj instanceof ImmutableSet)) { return legacyReadResolve(); } ImmutableSet immutableSet = (ImmutableSet) obj; ImmutableCollection immutableCollection = (ImmutableCollection) this.values; Builder makeBuilder = makeBuilder(immutableSet.size()); UnmodifiableIterator it = immutableSet.iterator(); UnmodifiableIterator it2 = immutableCollection.iterator(); while (it.hasNext()) { makeBuilder.put(it.next(), it2.next()); } return makeBuilder.build(); } /* JADX WARN: Multi-variable type inference failed */ final Object legacyReadResolve() { Object[] objArr = (Object[]) this.keys; Object[] objArr2 = (Object[]) this.values; Builder makeBuilder = makeBuilder(objArr.length); for (int i = 0; i < objArr.length; i++) { makeBuilder.put(objArr[i], objArr2[i]); } return makeBuilder.build(); } Builder makeBuilder(int i) { return new Builder<>(i); } } Object writeReplace() { return new SerializedForm(this); } }