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 java.io.Serializable; import java.lang.Comparable; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; /* loaded from: classes2.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(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<>(); } /* loaded from: classes2.dex */ public static final class Builder, V> { private final List, V>> entries = Lists.newArrayList(); public final 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 final Builder putAll(RangeMap rangeMap) { for (Map.Entry, ? extends V> entry : rangeMap.asMapOfRanges().entrySet()) { put(entry.getKey(), entry.getValue()); } return this; } final Builder combine(Builder builder) { this.entries.addAll(builder.entries); return this; } public final 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); StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 47 + String.valueOf(valueOf2).length()); sb.append("Overlapping ranges: range "); sb.append(valueOf); sb.append(" overlaps with entry "); sb.append(valueOf2); throw new IllegalArgumentException(sb.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 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 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(r1.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(Range range) { if (((Range) Preconditions.checkNotNull(range)).isEmpty()) { return of(); } if (this.ranges.isEmpty() || range.encloses(span())) { return this; } 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(); } return (ImmutableRangeMap) new ImmutableRangeMap(this, new ImmutableList>(this, binarySearch2 - binarySearch, binarySearch, range) { // from class: com.google.common.collect.ImmutableRangeMap.1 final ImmutableRangeMap this$0; final int val$len; final int val$off; final Range val$range; /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ImmutableCollection public boolean isPartialView() { return true; } { this.this$0 = this; this.val$len = r2; this.val$off = binarySearch; this.val$range = range; } /* JADX WARN: Multi-variable type inference failed */ @Override // java.util.List public Range get(int i) { Preconditions.checkElementIndex(i, this.val$len); return (i == 0 || i == this.val$len + (-1)) ? ((Range) this.this$0.ranges.get(i + this.val$off)).intersection(this.val$range) : (Range) this.this$0.ranges.get(i + this.val$off); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public int size() { return this.val$len; } }, this.values.subList(binarySearch, binarySearch2), range, this) { // from class: com.google.common.collect.ImmutableRangeMap.2 final ImmutableRangeMap val$outer; final Range val$range; { this.val$range = range; this.val$outer = this; } @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 /* bridge */ /* synthetic */ RangeMap subRangeMap(Range range2) { return subRangeMap(range2); } @Override // com.google.common.collect.ImmutableRangeMap, com.google.common.collect.RangeMap public ImmutableRangeMap subRangeMap(Range range2) { if (this.val$range.isConnected(range2)) { return this.val$outer.subRangeMap((Range) range2.intersection(this.val$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(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: classes2.dex */ 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()); } public static , V> ImmutableRangeMap of() { return (ImmutableRangeMap) EMPTY; } }