package com.google.common.collect; import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.SortedLists; import com.google.errorprone.annotations.DoNotMock; import java.io.Serializable; import java.lang.Comparable; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; import javax.annotation.CheckForNull; @ElementTypesAreNonnullByDefault /* loaded from: classes3.dex */ public class ImmutableRangeMap, V> implements RangeMap, Serializable { private static final ImmutableRangeMap, Object> EMPTY = new ImmutableRangeMap<>(ImmutableList.of(), ImmutableList.of()); private static final long serialVersionUID = 0; private final transient ImmutableList> ranges; private final transient ImmutableList values; public static , V> ImmutableRangeMap of() { return (ImmutableRangeMap) EMPTY; } public static , V> ImmutableRangeMap of(Range range, V v) { return new ImmutableRangeMap<>(ImmutableList.of(range), ImmutableList.of(v)); } public static , V> ImmutableRangeMap copyOf(RangeMap rangeMap) { if (rangeMap instanceof ImmutableRangeMap) { return (ImmutableRangeMap) rangeMap; } Map, ? extends V> asMapOfRanges = rangeMap.asMapOfRanges(); ImmutableList.Builder builder = new ImmutableList.Builder(asMapOfRanges.size()); ImmutableList.Builder builder2 = new ImmutableList.Builder(asMapOfRanges.size()); for (Map.Entry, ? extends V> entry : asMapOfRanges.entrySet()) { builder.add((ImmutableList.Builder) entry.getKey()); builder2.add((ImmutableList.Builder) entry.getValue()); } return new ImmutableRangeMap<>(builder.build(), builder2.build()); } public static , V> Builder builder() { return new Builder<>(); } @DoNotMock /* loaded from: classes3.dex */ public static final class Builder, V> { private final List, V>> entries = Lists.newArrayList(); public Builder put(Range range, V v) { Preconditions.checkNotNull(range); Preconditions.checkNotNull(v); Preconditions.checkArgument(!range.isEmpty(), "Range must not be empty, but was %s", range); this.entries.add(Maps.immutableEntry(range, v)); return this; } public Builder putAll(RangeMap rangeMap) { for (Map.Entry, ? extends V> entry : rangeMap.asMapOfRanges().entrySet()) { put(entry.getKey(), entry.getValue()); } return this; } Builder combine(Builder builder) { this.entries.addAll(builder.entries); return this; } public ImmutableRangeMap build() { Collections.sort(this.entries, Range.rangeLexOrdering().onKeys()); ImmutableList.Builder builder = new ImmutableList.Builder(this.entries.size()); ImmutableList.Builder builder2 = new ImmutableList.Builder(this.entries.size()); for (int i = 0; i < this.entries.size(); i++) { Range key = this.entries.get(i).getKey(); if (i > 0) { Range key2 = this.entries.get(i - 1).getKey(); if (key.isConnected(key2) && !key.intersection(key2).isEmpty()) { String valueOf = String.valueOf(key2); String valueOf2 = String.valueOf(key); throw new IllegalArgumentException(new StringBuilder(String.valueOf(valueOf).length() + 47 + String.valueOf(valueOf2).length()).append("Overlapping ranges: range ").append(valueOf).append(" overlaps with entry ").append(valueOf2).toString()); } } builder.add((ImmutableList.Builder) key); builder2.add((ImmutableList.Builder) this.entries.get(i).getValue()); } return new ImmutableRangeMap<>(builder.build(), builder2.build()); } } ImmutableRangeMap(ImmutableList> immutableList, ImmutableList immutableList2) { this.ranges = immutableList; this.values = immutableList2; } @Override // com.google.common.collect.RangeMap @CheckForNull public V get(K k) { int binarySearch = SortedLists.binarySearch(this.ranges, (Function) Range.lowerBoundFn(), Cut.belowValue(k), SortedLists.KeyPresentBehavior.ANY_PRESENT, SortedLists.KeyAbsentBehavior.NEXT_LOWER); if (binarySearch != -1 && this.ranges.get(binarySearch).contains(k)) { return this.values.get(binarySearch); } return null; } @Override // com.google.common.collect.RangeMap @CheckForNull public Map.Entry, V> getEntry(K k) { int binarySearch = SortedLists.binarySearch(this.ranges, (Function) Range.lowerBoundFn(), Cut.belowValue(k), SortedLists.KeyPresentBehavior.ANY_PRESENT, SortedLists.KeyAbsentBehavior.NEXT_LOWER); if (binarySearch == -1) { return null; } Range range = this.ranges.get(binarySearch); if (range.contains(k)) { return Maps.immutableEntry(range, this.values.get(binarySearch)); } return null; } @Override // com.google.common.collect.RangeMap public Range span() { if (this.ranges.isEmpty()) { throw new NoSuchElementException(); } return Range.create(this.ranges.get(0).lowerBound, this.ranges.get(r2.size() - 1).upperBound); } @Override // com.google.common.collect.RangeMap @Deprecated public final void put(Range range, V v) { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.RangeMap @Deprecated public final void putCoalescing(Range range, V v) { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.RangeMap @Deprecated public final void putAll(RangeMap rangeMap) { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.RangeMap @Deprecated public final void clear() { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.RangeMap @Deprecated public final void remove(Range range) { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.RangeMap public ImmutableMap, V> asMapOfRanges() { if (this.ranges.isEmpty()) { return ImmutableMap.of(); } return new ImmutableSortedMap(new RegularImmutableSortedSet(this.ranges, Range.rangeLexOrdering()), this.values); } @Override // com.google.common.collect.RangeMap public ImmutableMap, V> asDescendingMapOfRanges() { if (this.ranges.isEmpty()) { return ImmutableMap.of(); } return new ImmutableSortedMap(new RegularImmutableSortedSet(this.ranges.reverse(), Range.rangeLexOrdering().reverse()), this.values.reverse()); } @Override // com.google.common.collect.RangeMap public ImmutableRangeMap subRangeMap(final Range range) { if (((Range) Preconditions.checkNotNull(range)).isEmpty()) { return of(); } if (this.ranges.isEmpty() || range.encloses(span())) { return this; } final int binarySearch = SortedLists.binarySearch(this.ranges, (Function>) Range.upperBoundFn(), range.lowerBound, SortedLists.KeyPresentBehavior.FIRST_AFTER, SortedLists.KeyAbsentBehavior.NEXT_HIGHER); int binarySearch2 = SortedLists.binarySearch(this.ranges, (Function>) Range.lowerBoundFn(), range.upperBound, SortedLists.KeyPresentBehavior.ANY_PRESENT, SortedLists.KeyAbsentBehavior.NEXT_HIGHER); if (binarySearch >= binarySearch2) { return of(); } final int i = binarySearch2 - binarySearch; return (ImmutableRangeMap) new ImmutableRangeMap(this, new ImmutableList>() { // from class: com.google.common.collect.ImmutableRangeMap.1 /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ImmutableCollection public boolean isPartialView() { return true; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public int size() { return i; } /* JADX WARN: Multi-variable type inference failed */ @Override // java.util.List public Range get(int i2) { Preconditions.checkElementIndex(i2, i); return (i2 == 0 || i2 == i + (-1)) ? ((Range) ImmutableRangeMap.this.ranges.get(i2 + binarySearch)).intersection(range) : (Range) ImmutableRangeMap.this.ranges.get(i2 + binarySearch); } }, this.values.subList(binarySearch, binarySearch2)) { // from class: com.google.common.collect.ImmutableRangeMap.2 @Override // com.google.common.collect.ImmutableRangeMap, com.google.common.collect.RangeMap public /* bridge */ /* synthetic */ Map asDescendingMapOfRanges() { return super.asDescendingMapOfRanges(); } @Override // com.google.common.collect.ImmutableRangeMap, com.google.common.collect.RangeMap public /* bridge */ /* synthetic */ Map asMapOfRanges() { return super.asMapOfRanges(); } @Override // com.google.common.collect.ImmutableRangeMap, com.google.common.collect.RangeMap public ImmutableRangeMap subRangeMap(Range range2) { if (range.isConnected(range2)) { return this.subRangeMap((Range) range2.intersection(range)); } return ImmutableRangeMap.of(); } }; } @Override // com.google.common.collect.RangeMap public int hashCode() { return asMapOfRanges().hashCode(); } @Override // com.google.common.collect.RangeMap public boolean equals(@CheckForNull Object obj) { if (obj instanceof RangeMap) { return asMapOfRanges().equals(((RangeMap) obj).asMapOfRanges()); } return false; } @Override // com.google.common.collect.RangeMap public String toString() { return asMapOfRanges().toString(); } /* loaded from: classes3.dex */ private static class SerializedForm, V> implements Serializable { private static final long serialVersionUID = 0; private final ImmutableMap, V> mapOfRanges; SerializedForm(ImmutableMap, V> immutableMap) { this.mapOfRanges = immutableMap; } Object readResolve() { if (this.mapOfRanges.isEmpty()) { return ImmutableRangeMap.of(); } return createRangeMap(); } Object createRangeMap() { Builder builder = new Builder(); UnmodifiableIterator, V>> it = this.mapOfRanges.entrySet().iterator(); while (it.hasNext()) { Map.Entry, V> next = it.next(); builder.put(next.getKey(), next.getValue()); } return builder.build(); } } Object writeReplace() { return new SerializedForm(asMapOfRanges()); } }