package com.google.common.collect; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableCollection; import com.google.errorprone.annotations.DoNotMock; import com.google.errorprone.annotations.concurrent.LazyInit; import java.io.Serializable; import java.util.AbstractMap; import java.util.Arrays; import java.util.BitSet; import java.util.Collection; import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.SortedMap; import javax.annotation.CheckForNull; @DoNotMock("Use ImmutableMap.of or another implementation") @ElementTypesAreNonnullByDefault /* loaded from: classes3.dex */ public abstract class ImmutableMap implements Map, Serializable { static final Map.Entry[] EMPTY_ENTRY_ARRAY = new Map.Entry[0]; @CheckForNull @LazyInit private transient ImmutableSet> entrySet; @CheckForNull @LazyInit private transient ImmutableSet keySet; @CheckForNull @LazyInit private transient ImmutableSetMultimap multimapView; @CheckForNull @LazyInit private transient ImmutableCollection values; abstract ImmutableSet> createEntrySet(); abstract ImmutableSet createKeySet(); abstract ImmutableCollection createValues(); @Override // java.util.Map @CheckForNull public abstract V get(@CheckForNull 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}); } public static ImmutableMap of(K k, V v, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6) { CollectPreconditions.checkEntryNotNull(k, v); CollectPreconditions.checkEntryNotNull(k2, v2); CollectPreconditions.checkEntryNotNull(k3, v3); CollectPreconditions.checkEntryNotNull(k4, v4); CollectPreconditions.checkEntryNotNull(k5, v5); CollectPreconditions.checkEntryNotNull(k6, v6); return RegularImmutableMap.create(6, new Object[]{k, v, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6}); } public static ImmutableMap of(K k, V v, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7) { CollectPreconditions.checkEntryNotNull(k, v); CollectPreconditions.checkEntryNotNull(k2, v2); CollectPreconditions.checkEntryNotNull(k3, v3); CollectPreconditions.checkEntryNotNull(k4, v4); CollectPreconditions.checkEntryNotNull(k5, v5); CollectPreconditions.checkEntryNotNull(k6, v6); CollectPreconditions.checkEntryNotNull(k7, v7); return RegularImmutableMap.create(7, new Object[]{k, v, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7}); } public static ImmutableMap of(K k, V v, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8) { CollectPreconditions.checkEntryNotNull(k, v); CollectPreconditions.checkEntryNotNull(k2, v2); CollectPreconditions.checkEntryNotNull(k3, v3); CollectPreconditions.checkEntryNotNull(k4, v4); CollectPreconditions.checkEntryNotNull(k5, v5); CollectPreconditions.checkEntryNotNull(k6, v6); CollectPreconditions.checkEntryNotNull(k7, v7); CollectPreconditions.checkEntryNotNull(k8, v8); return RegularImmutableMap.create(8, new Object[]{k, v, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8}); } public static ImmutableMap of(K k, V v, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9) { CollectPreconditions.checkEntryNotNull(k, v); CollectPreconditions.checkEntryNotNull(k2, v2); CollectPreconditions.checkEntryNotNull(k3, v3); CollectPreconditions.checkEntryNotNull(k4, v4); CollectPreconditions.checkEntryNotNull(k5, v5); CollectPreconditions.checkEntryNotNull(k6, v6); CollectPreconditions.checkEntryNotNull(k7, v7); CollectPreconditions.checkEntryNotNull(k8, v8); CollectPreconditions.checkEntryNotNull(k9, v9); return RegularImmutableMap.create(9, new Object[]{k, v, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9}); } public static ImmutableMap of(K k, V v, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10) { CollectPreconditions.checkEntryNotNull(k, v); CollectPreconditions.checkEntryNotNull(k2, v2); CollectPreconditions.checkEntryNotNull(k3, v3); CollectPreconditions.checkEntryNotNull(k4, v4); CollectPreconditions.checkEntryNotNull(k5, v5); CollectPreconditions.checkEntryNotNull(k6, v6); CollectPreconditions.checkEntryNotNull(k7, v7); CollectPreconditions.checkEntryNotNull(k8, v8); CollectPreconditions.checkEntryNotNull(k9, v9); CollectPreconditions.checkEntryNotNull(k10, v10); return RegularImmutableMap.create(10, new Object[]{k, v, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10}); } @SafeVarargs public static ImmutableMap ofEntries(Map.Entry... entryArr) { return copyOf(Arrays.asList(entryArr)); } /* 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, Object obj, Object obj2) { if (!z) { throw conflictException(str, obj, obj2); } } static IllegalArgumentException conflictException(String str, Object obj, Object obj2) { String valueOf = String.valueOf(obj); String valueOf2 = String.valueOf(obj2); return new IllegalArgumentException(new StringBuilder(String.valueOf(str).length() + 34 + String.valueOf(valueOf).length() + String.valueOf(valueOf2).length()).append("Multiple entries with same ").append(str).append(": ").append(valueOf).append(" and ").append(valueOf2).toString()); } @DoNotMock /* loaded from: classes3.dex */ public static class Builder { Object[] alternatingKeysAndValues; DuplicateKey duplicateKey; boolean entriesUsed; int size; @CheckForNull Comparator valueComparator; public Builder() { this(4); } /* JADX INFO: Access modifiers changed from: package-private */ public Builder(int i) { this.alternatingKeysAndValues = new Object[i * 2]; this.size = 0; this.entriesUsed = false; } private void ensureCapacity(int i) { int i2 = i * 2; 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; objArr[i * 2] = k; objArr[(i * 2) + 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 * 2, builder.size * 2); this.size += builder.size; return this; } private ImmutableMap build(boolean z) { Object[] objArr; DuplicateKey duplicateKey; DuplicateKey duplicateKey2; if (z && (duplicateKey2 = this.duplicateKey) != null) { throw duplicateKey2.exception(); } int i = this.size; if (this.valueComparator == null) { objArr = this.alternatingKeysAndValues; } else { if (this.entriesUsed) { this.alternatingKeysAndValues = Arrays.copyOf(this.alternatingKeysAndValues, i * 2); } objArr = this.alternatingKeysAndValues; if (!z) { objArr = lastEntryForEachKey(objArr, this.size); if (objArr.length < this.alternatingKeysAndValues.length) { i = objArr.length >>> 1; } } sortEntries(objArr, i, this.valueComparator); } this.entriesUsed = true; RegularImmutableMap create = RegularImmutableMap.create(i, objArr, this); if (!z || (duplicateKey = this.duplicateKey) == null) { return create; } throw duplicateKey.exception(); } public ImmutableMap build() { return buildOrThrow(); } public ImmutableMap buildOrThrow() { return build(true); } public ImmutableMap buildKeepingLast() { return build(false); } /* JADX INFO: Access modifiers changed from: package-private */ public static void sortEntries(Object[] objArr, int i, Comparator comparator) { Map.Entry[] entryArr = new Map.Entry[i]; for (int i2 = 0; i2 < i; i2++) { int i3 = i2 * 2; entryArr[i2] = new AbstractMap.SimpleImmutableEntry(Objects.requireNonNull(objArr[i3]), Objects.requireNonNull(objArr[i3 + 1])); } Arrays.sort(entryArr, 0, i, Ordering.from(comparator).onResultOf(Maps.valueFunction())); for (int i4 = 0; i4 < i; i4++) { int i5 = i4 * 2; objArr[i5] = entryArr[i4].getKey(); objArr[i5 + 1] = entryArr[i4].getValue(); } } private Object[] lastEntryForEachKey(Object[] objArr, int i) { HashSet hashSet = new HashSet(); BitSet bitSet = new BitSet(); for (int i2 = i - 1; i2 >= 0; i2--) { if (!hashSet.add(Objects.requireNonNull(objArr[i2 * 2]))) { bitSet.set(i2); } } if (bitSet.isEmpty()) { return objArr; } Object[] objArr2 = new Object[(i - bitSet.cardinality()) * 2]; int i3 = 0; int i4 = 0; while (i3 < i * 2) { if (bitSet.get(i3 >>> 1)) { i3 += 2; } else { int i5 = i4 + 1; int i6 = i3 + 1; objArr2[i4] = Objects.requireNonNull(objArr[i3]); i4 += 2; i3 += 2; objArr2[i5] = Objects.requireNonNull(objArr[i6]); } } return objArr2; } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes3.dex */ public static final class DuplicateKey { private final Object key; private final Object value1; private final Object value2; /* JADX INFO: Access modifiers changed from: package-private */ public DuplicateKey(Object obj, Object obj2, Object obj3) { this.key = obj; this.value1 = obj2; this.value2 = obj3; } /* JADX INFO: Access modifiers changed from: package-private */ public IllegalArgumentException exception() { String valueOf = String.valueOf(this.key); String valueOf2 = String.valueOf(this.value1); String valueOf3 = String.valueOf(this.key); String valueOf4 = String.valueOf(this.value2); return new IllegalArgumentException(new StringBuilder(String.valueOf(valueOf).length() + 39 + String.valueOf(valueOf2).length() + String.valueOf(valueOf3).length() + String.valueOf(valueOf4).length()).append("Multiple entries with same key: ").append(valueOf).append("=").append(valueOf2).append(" and ").append(valueOf3).append("=").append(valueOf4).toString()); } } } 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(); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes3.dex */ public 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, com.google.common.collect.BiMap 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() { // from class: com.google.common.collect.ImmutableMap.IteratorBasedImmutableMap.1EntrySetImpl @Override // com.google.common.collect.ImmutableMapEntrySet ImmutableMap map() { 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, com.google.common.collect.SortedIterable public UnmodifiableIterator> iterator() { return IteratorBasedImmutableMap.this.entryIterator(); } }; } @Override // com.google.common.collect.ImmutableMap ImmutableCollection createValues() { return new ImmutableMapValues(this); } } @Override // java.util.Map @CheckForNull @Deprecated public final V put(K k, V v) { throw new UnsupportedOperationException(); } @Override // java.util.Map @CheckForNull @Deprecated public final V remove(@CheckForNull 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(@CheckForNull Object obj) { return get(obj) != null; } @Override // java.util.Map public boolean containsValue(@CheckForNull Object obj) { return values().contains(obj); } @Override // java.util.Map @CheckForNull public final V getOrDefault(@CheckForNull Object obj, @CheckForNull 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() { 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, com.google.common.collect.BiMap 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: classes3.dex */ private final class MapViewOfValuesAsSingletonSets extends IteratorBasedImmutableMap> { private MapViewOfValuesAsSingletonSets() { } @Override // java.util.Map public int size() { return ImmutableMap.this.size(); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ImmutableMap.IteratorBasedImmutableMap, com.google.common.collect.ImmutableMap public ImmutableSet createKeySet() { return ImmutableMap.this.keySet(); } @Override // com.google.common.collect.ImmutableMap, java.util.Map public boolean containsKey(@CheckForNull Object obj) { return ImmutableMap.this.containsKey(obj); } @Override // com.google.common.collect.ImmutableMap, java.util.Map @CheckForNull public ImmutableSet get(@CheckForNull Object obj) { Object obj2 = ImmutableMap.this.get(obj); if (obj2 == null) { return null; } return ImmutableSet.of(obj2); } @Override // com.google.common.collect.ImmutableMap boolean isPartialView() { return ImmutableMap.this.isPartialView(); } @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.IteratorBasedImmutableMap UnmodifiableIterator>> entryIterator() { 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 // java.util.Map public boolean equals(@CheckForNull 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: classes3.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; } 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.buildOrThrow(); } /* 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.buildOrThrow(); } Builder makeBuilder(int i) { return new Builder<>(i); } } Object writeReplace() { return new SerializedForm(this); } }