package com.google.common.collect; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableMap; 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.NavigableMap; import java.util.Set; import java.util.SortedMap; /* loaded from: classes2.dex */ public final class ImmutableSortedMap extends ImmutableSortedMapFauxverideShim implements NavigableMap { private static final long serialVersionUID = 0; private transient ImmutableSortedMap descendingMap; private final transient RegularImmutableSortedSet keySet; private final transient ImmutableList valueList; private static final Comparator NATURAL_ORDER = Ordering.natural(); private static final ImmutableSortedMap NATURAL_EMPTY_MAP = new ImmutableSortedMap<>(ImmutableSortedSet.emptySet(Ordering.natural()), ImmutableList.of()); @Override // com.google.common.collect.ImmutableMap, java.util.Map public final /* bridge */ /* synthetic */ Set entrySet() { return entrySet(); } /* JADX WARN: Multi-variable type inference failed */ @Override // java.util.NavigableMap public final /* bridge */ /* synthetic */ NavigableMap headMap(Object obj, boolean z) { return headMap((ImmutableSortedMap) obj, z); } /* JADX WARN: Multi-variable type inference failed */ @Override // java.util.NavigableMap, java.util.SortedMap public final /* bridge */ /* synthetic */ SortedMap headMap(Object obj) { return headMap((ImmutableSortedMap) obj); } /* JADX WARN: Multi-variable type inference failed */ @Override // java.util.NavigableMap public final /* bridge */ /* synthetic */ NavigableMap subMap(Object obj, boolean z, Object obj2, boolean z2) { return subMap((boolean) obj, z, (boolean) obj2, z2); } /* JADX WARN: Multi-variable type inference failed */ @Override // java.util.NavigableMap public final /* bridge */ /* synthetic */ NavigableMap tailMap(Object obj, boolean z) { return tailMap((ImmutableSortedMap) obj, z); } /* JADX WARN: Multi-variable type inference failed */ @Override // java.util.NavigableMap, java.util.SortedMap public final /* bridge */ /* synthetic */ SortedMap tailMap(Object obj) { return tailMap((ImmutableSortedMap) obj); } @Override // com.google.common.collect.ImmutableMap, java.util.Map public final /* bridge */ /* synthetic */ Collection values() { return values(); } static ImmutableSortedMap emptyMap(Comparator comparator) { if (Ordering.natural().equals(comparator)) { return of(); } return new ImmutableSortedMap<>(ImmutableSortedSet.emptySet(comparator), ImmutableList.of()); } /* JADX WARN: Incorrect types in method signature: ;V:Ljava/lang/Object;>(TK;TV;)Lcom/google/common/collect/ImmutableSortedMap; */ public static ImmutableSortedMap of(Comparable comparable, Object obj) { return of(Ordering.natural(), comparable, obj); } /* JADX INFO: Access modifiers changed from: private */ public static ImmutableSortedMap of(Comparator comparator, K k, V v) { return new ImmutableSortedMap<>(new RegularImmutableSortedSet(ImmutableList.of(k), (Comparator) Preconditions.checkNotNull(comparator)), ImmutableList.of(v)); } /* JADX WARN: Incorrect types in method signature: ;V:Ljava/lang/Object;>(TK;TV;TK;TV;)Lcom/google/common/collect/ImmutableSortedMap; */ public static ImmutableSortedMap of(Comparable comparable, Object obj, Comparable comparable2, Object obj2) { return ofEntries(entryOf(comparable, obj), entryOf(comparable2, obj2)); } /* JADX WARN: Incorrect types in method signature: ;V:Ljava/lang/Object;>(TK;TV;TK;TV;TK;TV;)Lcom/google/common/collect/ImmutableSortedMap; */ public static ImmutableSortedMap of(Comparable comparable, Object obj, Comparable comparable2, Object obj2, Comparable comparable3, Object obj3) { return ofEntries(entryOf(comparable, obj), entryOf(comparable2, obj2), entryOf(comparable3, obj3)); } /* JADX WARN: Incorrect types in method signature: ;V:Ljava/lang/Object;>(TK;TV;TK;TV;TK;TV;TK;TV;)Lcom/google/common/collect/ImmutableSortedMap; */ public static ImmutableSortedMap of(Comparable comparable, Object obj, Comparable comparable2, Object obj2, Comparable comparable3, Object obj3, Comparable comparable4, Object obj4) { return ofEntries(entryOf(comparable, obj), entryOf(comparable2, obj2), entryOf(comparable3, obj3), entryOf(comparable4, obj4)); } /* JADX WARN: Incorrect types in method signature: ;V:Ljava/lang/Object;>(TK;TV;TK;TV;TK;TV;TK;TV;TK;TV;)Lcom/google/common/collect/ImmutableSortedMap; */ public static ImmutableSortedMap of(Comparable comparable, Object obj, Comparable comparable2, Object obj2, Comparable comparable3, Object obj3, Comparable comparable4, Object obj4, Comparable comparable5, Object obj5) { return ofEntries(entryOf(comparable, obj), entryOf(comparable2, obj2), entryOf(comparable3, obj3), entryOf(comparable4, obj4), entryOf(comparable5, obj5)); } private static , V> ImmutableSortedMap ofEntries(Map.Entry... entryArr) { return fromEntries(Ordering.natural(), false, entryArr, entryArr.length); } public static ImmutableSortedMap copyOf(Map map) { return copyOfInternal(map, (Ordering) NATURAL_ORDER); } public static ImmutableSortedMap copyOf(Map map, Comparator comparator) { return copyOfInternal(map, (Comparator) Preconditions.checkNotNull(comparator)); } public static ImmutableSortedMap copyOf(Iterable> iterable) { return copyOf(iterable, (Ordering) NATURAL_ORDER); } public static ImmutableSortedMap copyOf(Iterable> iterable, Comparator comparator) { return fromEntries((Comparator) Preconditions.checkNotNull(comparator), false, iterable); } public static ImmutableSortedMap copyOfSorted(SortedMap sortedMap) { Comparator comparator = sortedMap.comparator(); if (comparator == null) { comparator = NATURAL_ORDER; } if (sortedMap instanceof ImmutableSortedMap) { ImmutableSortedMap immutableSortedMap = (ImmutableSortedMap) sortedMap; if (!immutableSortedMap.isPartialView()) { return immutableSortedMap; } } return fromEntries(comparator, true, sortedMap.entrySet()); } private static ImmutableSortedMap copyOfInternal(Map map, Comparator comparator) { boolean z = false; if (map instanceof SortedMap) { Comparator comparator2 = ((SortedMap) map).comparator(); if (comparator2 != null) { z = comparator.equals(comparator2); } else if (comparator == NATURAL_ORDER) { z = true; } } if (z && (map instanceof ImmutableSortedMap)) { ImmutableSortedMap immutableSortedMap = (ImmutableSortedMap) map; if (!immutableSortedMap.isPartialView()) { return immutableSortedMap; } } return fromEntries(comparator, z, map.entrySet()); } private static ImmutableSortedMap fromEntries(Comparator comparator, boolean z, Iterable> iterable) { Map.Entry[] entryArr = (Map.Entry[]) Iterables.toArray(iterable, EMPTY_ENTRY_ARRAY); return fromEntries(comparator, z, entryArr, entryArr.length); } private static ImmutableSortedMap fromEntries(Comparator comparator, boolean z, Map.Entry[] entryArr, int i) { if (i == 0) { return emptyMap(comparator); } if (i == 1) { return of(comparator, entryArr[0].getKey(), entryArr[0].getValue()); } Object[] objArr = new Object[i]; Object[] objArr2 = new Object[i]; if (z) { for (int i2 = 0; i2 < i; i2++) { K key = entryArr[i2].getKey(); V value = entryArr[i2].getValue(); CollectPreconditions.checkEntryNotNull(key, value); objArr[i2] = key; objArr2[i2] = value; } } else { Arrays.sort(entryArr, 0, i, new Comparator>(comparator) { // from class: com.google.common.collect.ImmutableSortedMap.1 final Comparator val$comparator; { this.val$comparator = comparator; } @Override // java.util.Comparator public int compare(Map.Entry entry, Map.Entry entry2) { return this.val$comparator.compare(entry.getKey(), entry2.getKey()); } }); Object key2 = entryArr[0].getKey(); objArr[0] = key2; V value2 = entryArr[0].getValue(); objArr2[0] = value2; CollectPreconditions.checkEntryNotNull(objArr[0], value2); int i3 = 1; while (i3 < i) { Object key3 = entryArr[i3].getKey(); V value3 = entryArr[i3].getValue(); CollectPreconditions.checkEntryNotNull(key3, value3); objArr[i3] = key3; objArr2[i3] = value3; checkNoConflict(comparator.compare(key2, key3) != 0, "key", entryArr[i3 - 1], entryArr[i3]); i3++; key2 = key3; } } return new ImmutableSortedMap<>(new RegularImmutableSortedSet(ImmutableList.asImmutableList(objArr), comparator), ImmutableList.asImmutableList(objArr2)); } public static , V> Builder naturalOrder() { return new Builder<>(Ordering.natural()); } public static Builder orderedBy(Comparator comparator) { return new Builder<>(comparator); } public static , V> Builder reverseOrder() { return new Builder<>(Ordering.natural().reverse()); } /* loaded from: classes2.dex */ public static class Builder extends ImmutableMap.Builder { private final Comparator comparator; private transient Object[] keys; private transient Object[] values; /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.ImmutableMap.Builder public /* bridge */ /* synthetic */ ImmutableMap.Builder put(Object obj, Object obj2) { return put((Builder) obj, obj2); } public Builder(Comparator comparator) { this(comparator, 4); } private Builder(Comparator comparator, int i) { this.comparator = (Comparator) Preconditions.checkNotNull(comparator); this.keys = new Object[i]; this.values = new Object[i]; } private void ensureCapacity(int i) { Object[] objArr = this.keys; if (i > objArr.length) { int expandedCapacity = ImmutableCollection.Builder.expandedCapacity(objArr.length, i); this.keys = Arrays.copyOf(this.keys, expandedCapacity); this.values = Arrays.copyOf(this.values, expandedCapacity); } } @Override // com.google.common.collect.ImmutableMap.Builder public Builder put(K k, V v) { ensureCapacity(this.size + 1); CollectPreconditions.checkEntryNotNull(k, v); this.keys[this.size] = k; this.values[this.size] = v; this.size++; return this; } @Override // com.google.common.collect.ImmutableMap.Builder public Builder put(Map.Entry entry) { super.put((Map.Entry) entry); return this; } @Override // com.google.common.collect.ImmutableMap.Builder public Builder putAll(Map map) { super.putAll((Map) map); return this; } @Override // com.google.common.collect.ImmutableMap.Builder public Builder putAll(Iterable> iterable) { super.putAll((Iterable) iterable); return this; } @Override // com.google.common.collect.ImmutableMap.Builder @Deprecated public final Builder orderEntriesByValue(Comparator comparator) { throw new UnsupportedOperationException("Not available on ImmutableSortedMap.Builder"); } Builder combine(Builder builder) { ensureCapacity(this.size + builder.size); System.arraycopy(builder.keys, 0, this.keys, this.size, builder.size); System.arraycopy(builder.values, 0, this.values, this.size, builder.size); this.size += builder.size; return this; } @Override // com.google.common.collect.ImmutableMap.Builder public ImmutableSortedMap build() { int i = this.size; if (i == 0) { return ImmutableSortedMap.emptyMap(this.comparator); } if (i == 1) { return ImmutableSortedMap.of(this.comparator, this.keys[0], this.values[0]); } Object[] copyOf = Arrays.copyOf(this.keys, this.size); Arrays.sort(copyOf, this.comparator); Object[] objArr = new Object[this.size]; for (int i2 = 0; i2 < this.size; i2++) { if (i2 > 0) { int i3 = i2 - 1; if (this.comparator.compare(copyOf[i3], copyOf[i2]) == 0) { String valueOf = String.valueOf(copyOf[i3]); String valueOf2 = String.valueOf(copyOf[i2]); StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 57 + String.valueOf(valueOf2).length()); sb.append("keys required to be distinct but compared as equal: "); sb.append(valueOf); sb.append(" and "); sb.append(valueOf2); throw new IllegalArgumentException(sb.toString()); } } objArr[Arrays.binarySearch(copyOf, this.keys[i2], this.comparator)] = this.values[i2]; } return new ImmutableSortedMap<>(new RegularImmutableSortedSet(ImmutableList.asImmutableList(copyOf), this.comparator), ImmutableList.asImmutableList(objArr)); } } /* JADX INFO: Access modifiers changed from: package-private */ public ImmutableSortedMap(RegularImmutableSortedSet regularImmutableSortedSet, ImmutableList immutableList) { this(regularImmutableSortedSet, immutableList, null); } ImmutableSortedMap(RegularImmutableSortedSet regularImmutableSortedSet, ImmutableList immutableList, ImmutableSortedMap immutableSortedMap) { this.keySet = regularImmutableSortedSet; this.valueList = immutableList; this.descendingMap = immutableSortedMap; } @Override // java.util.Map public final int size() { return this.valueList.size(); } @Override // com.google.common.collect.ImmutableMap, java.util.Map public final V get(Object obj) { int indexOf = this.keySet.indexOf(obj); if (indexOf == -1) { return null; } return this.valueList.get(indexOf); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ImmutableMap public final boolean isPartialView() { return this.keySet.isPartialView() || this.valueList.isPartialView(); } @Override // com.google.common.collect.ImmutableMap, java.util.Map public final ImmutableSet> entrySet() { return super.entrySet(); } /* JADX INFO: Access modifiers changed from: package-private */ /* renamed from: com.google.common.collect.ImmutableSortedMap$1EntrySet, reason: invalid class name */ /* loaded from: classes2.dex */ public class C1EntrySet extends ImmutableMapEntrySet { final ImmutableSortedMap this$0; C1EntrySet(ImmutableSortedMap immutableSortedMap) { this.this$0 = immutableSortedMap; } @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 asList().iterator(); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ImmutableSet public ImmutableList> createAsList() { return new ImmutableList>(this) { // from class: com.google.common.collect.ImmutableSortedMap.1EntrySet.1 final C1EntrySet this$1; /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ImmutableCollection public boolean isPartialView() { return true; } { this.this$1 = this; } @Override // java.util.List public Map.Entry get(int i) { return new AbstractMap.SimpleImmutableEntry(this.this$1.this$0.keySet.asList().get(i), this.this$1.this$0.valueList.get(i)); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public int size() { return this.this$1.this$0.size(); } }; } @Override // com.google.common.collect.ImmutableMapEntrySet ImmutableMap map() { return this.this$0; } } @Override // com.google.common.collect.ImmutableMap final ImmutableSet> createEntrySet() { return isEmpty() ? ImmutableSet.of() : new C1EntrySet(this); } @Override // com.google.common.collect.ImmutableMap final ImmutableSet createKeySet() { throw new AssertionError("should never be called"); } @Override // com.google.common.collect.ImmutableMap final ImmutableCollection createValues() { throw new AssertionError("should never be called"); } @Override // java.util.SortedMap public final Comparator comparator() { return keySet().comparator(); } @Override // java.util.SortedMap public final K firstKey() { return keySet().first(); } @Override // java.util.SortedMap public final K lastKey() { return keySet().last(); } private ImmutableSortedMap getSubMap(int i, int i2) { if (i == 0 && i2 == size()) { return this; } if (i == i2) { return emptyMap(comparator()); } return new ImmutableSortedMap<>(this.keySet.getSubSet(i, i2), this.valueList.subList(i, i2)); } @Override // java.util.NavigableMap, java.util.SortedMap public final ImmutableSortedMap headMap(K k) { return headMap((ImmutableSortedMap) k, false); } @Override // java.util.NavigableMap public final ImmutableSortedMap headMap(K k, boolean z) { return getSubMap(0, this.keySet.headIndex(Preconditions.checkNotNull(k), z)); } @Override // java.util.NavigableMap, java.util.SortedMap public final ImmutableSortedMap subMap(K k, K k2) { return subMap((boolean) k, true, (boolean) k2, false); } /* JADX WARN: Multi-variable type inference failed */ @Override // java.util.NavigableMap public final ImmutableSortedMap subMap(K k, boolean z, K k2, boolean z2) { Preconditions.checkNotNull(k); Preconditions.checkNotNull(k2); Preconditions.checkArgument(comparator().compare(k, k2) <= 0, "expected fromKey <= toKey but %s > %s", k, k2); return headMap((ImmutableSortedMap) k2, z2).tailMap((ImmutableSortedMap) k, z); } @Override // java.util.NavigableMap, java.util.SortedMap public final ImmutableSortedMap tailMap(K k) { return tailMap((ImmutableSortedMap) k, true); } @Override // java.util.NavigableMap public final ImmutableSortedMap tailMap(K k, boolean z) { return getSubMap(this.keySet.tailIndex(Preconditions.checkNotNull(k), z), size()); } @Override // java.util.NavigableMap public final Map.Entry lowerEntry(K k) { return headMap((ImmutableSortedMap) k, false).lastEntry(); } @Override // java.util.NavigableMap public final K lowerKey(K k) { return (K) Maps.keyOrNull(lowerEntry(k)); } @Override // java.util.NavigableMap public final Map.Entry floorEntry(K k) { return headMap((ImmutableSortedMap) k, true).lastEntry(); } @Override // java.util.NavigableMap public final K floorKey(K k) { return (K) Maps.keyOrNull(floorEntry(k)); } @Override // java.util.NavigableMap public final Map.Entry ceilingEntry(K k) { return tailMap((ImmutableSortedMap) k, true).firstEntry(); } @Override // java.util.NavigableMap public final K ceilingKey(K k) { return (K) Maps.keyOrNull(ceilingEntry(k)); } @Override // java.util.NavigableMap public final Map.Entry higherEntry(K k) { return tailMap((ImmutableSortedMap) k, false).firstEntry(); } @Override // java.util.NavigableMap public final K higherKey(K k) { return (K) Maps.keyOrNull(higherEntry(k)); } @Override // java.util.NavigableMap public final Map.Entry firstEntry() { if (isEmpty()) { return null; } return entrySet().asList().get(0); } @Override // java.util.NavigableMap public final Map.Entry lastEntry() { if (isEmpty()) { return null; } return entrySet().asList().get(size() - 1); } @Override // java.util.NavigableMap @Deprecated public final Map.Entry pollFirstEntry() { throw new UnsupportedOperationException(); } @Override // java.util.NavigableMap @Deprecated public final Map.Entry pollLastEntry() { throw new UnsupportedOperationException(); } @Override // java.util.NavigableMap public final ImmutableSortedMap descendingMap() { ImmutableSortedMap immutableSortedMap = this.descendingMap; if (immutableSortedMap != null) { return immutableSortedMap; } if (isEmpty()) { return emptyMap(Ordering.from(comparator()).reverse()); } return new ImmutableSortedMap<>((RegularImmutableSortedSet) this.keySet.descendingSet(), this.valueList.reverse(), this); } @Override // java.util.NavigableMap public final ImmutableSortedSet descendingKeySet() { return this.keySet.descendingSet(); } /* loaded from: classes2.dex */ static class SerializedForm extends ImmutableMap.SerializedForm { private static final long serialVersionUID = 0; private final Comparator comparator; SerializedForm(ImmutableSortedMap immutableSortedMap) { super(immutableSortedMap); this.comparator = immutableSortedMap.comparator(); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ImmutableMap.SerializedForm public Builder makeBuilder(int i) { return new Builder<>(this.comparator); } } @Override // com.google.common.collect.ImmutableMap final Object writeReplace() { return new SerializedForm(this); } @Override // com.google.common.collect.ImmutableMap, java.util.Map public final ImmutableCollection values() { return this.valueList; } @Override // java.util.NavigableMap public final ImmutableSortedSet navigableKeySet() { return this.keySet; } @Override // com.google.common.collect.ImmutableMap, java.util.Map public final ImmutableSortedSet keySet() { return this.keySet; } public static ImmutableSortedMap of() { return (ImmutableSortedMap) NATURAL_EMPTY_MAP; } }