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: classes.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; private static class SerializedForm, V> implements Serializable { private final ImmutableMap, V> a; SerializedForm(ImmutableMap, V> immutableMap) { this.a = immutableMap; } Object a() { Builder builder = new Builder(); UnmodifiableIterator, V>> it = this.a.entrySet().iterator(); while (it.hasNext()) { Map.Entry, V> next = it.next(); builder.a(next.getKey(), next.getValue()); } return builder.a(); } Object readResolve() { return this.a.isEmpty() ? ImmutableRangeMap.of() : a(); } } ImmutableRangeMap(ImmutableList> immutableList, ImmutableList immutableList2) { this.ranges = immutableList; this.values = immutableList2; } public static , V> Builder builder() { return new Builder<>(); } 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.a((ImmutableList.Builder) entry.getKey()); builder2.a((ImmutableList.Builder) entry.getValue()); } return new ImmutableRangeMap<>(builder.a(), builder2.a()); } public static , V> ImmutableRangeMap of() { return (ImmutableRangeMap) EMPTY; } @Deprecated public void clear() { throw new UnsupportedOperationException(); } public boolean equals(Object obj) { if (obj instanceof RangeMap) { return asMapOfRanges().equals(((RangeMap) obj).asMapOfRanges()); } return false; } public V get(K k) { int a = SortedLists.a(this.ranges, (Function) Range.lowerBoundFn(), Cut.c(k), SortedLists.KeyPresentBehavior.ANY_PRESENT, SortedLists.KeyAbsentBehavior.NEXT_LOWER); if (a != -1 && this.ranges.get(a).contains(k)) { return this.values.get(a); } return null; } public Map.Entry, V> getEntry(K k) { int a = SortedLists.a(this.ranges, (Function) Range.lowerBoundFn(), Cut.c(k), SortedLists.KeyPresentBehavior.ANY_PRESENT, SortedLists.KeyAbsentBehavior.NEXT_LOWER); if (a == -1) { return null; } Range range = this.ranges.get(a); if (range.contains(k)) { return Maps.a(range, this.values.get(a)); } return null; } public int hashCode() { return asMapOfRanges().hashCode(); } @Deprecated public void put(Range range, V v) { throw new UnsupportedOperationException(); } @Deprecated public void putAll(RangeMap rangeMap) { throw new UnsupportedOperationException(); } @Deprecated public void putCoalescing(Range range, V v) { throw new UnsupportedOperationException(); } @Deprecated public void remove(Range range) { throw new UnsupportedOperationException(); } 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); } public String toString() { return asMapOfRanges().toString(); } Object writeReplace() { return new SerializedForm(asMapOfRanges()); } public static , V> ImmutableRangeMap of(Range range, V v) { return new ImmutableRangeMap<>(ImmutableList.of(range), ImmutableList.of(v)); } @Override // /* renamed from: asDescendingMapOfRanges, reason: merged with bridge method [inline-methods] */ public ImmutableMap, V> mo7asDescendingMapOfRanges() { return this.ranges.isEmpty() ? ImmutableMap.of() : new ImmutableSortedMap(new RegularImmutableSortedSet(this.ranges.reverse(), Range.rangeLexOrdering().b()), this.values.reverse()); } @Override // com.google.common.collect.RangeMap public ImmutableMap, V> asMapOfRanges() { return this.ranges.isEmpty() ? ImmutableMap.of() : new ImmutableSortedMap(new RegularImmutableSortedSet(this.ranges, Range.rangeLexOrdering()), this.values); } @Override // /* renamed from: subRangeMap */ public ImmutableRangeMap mo8subRangeMap(final Range range) { Preconditions.a(range); if (range.isEmpty()) { return of(); } if (this.ranges.isEmpty() || range.encloses(span())) { return this; } final int a = SortedLists.a(this.ranges, (Function>) Range.upperBoundFn(), range.lowerBound, SortedLists.KeyPresentBehavior.FIRST_AFTER, SortedLists.KeyAbsentBehavior.NEXT_HIGHER); int a2 = SortedLists.a(this.ranges, (Function>) Range.lowerBoundFn(), range.upperBound, SortedLists.KeyPresentBehavior.ANY_PRESENT, SortedLists.KeyAbsentBehavior.NEXT_HIGHER); if (a >= a2) { return of(); } final int i = a2 - a; return (ImmutableRangeMap) new ImmutableRangeMap(this, new ImmutableList>() { // from class: com.google.common.collect.ImmutableRangeMap.1 @Override // com.google.common.collect.ImmutableCollection 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.a(i2, i); return (i2 == 0 || i2 == i + (-1)) ? ((Range) ImmutableRangeMap.this.ranges.get(i2 + a)).intersection(range) : (Range) ImmutableRangeMap.this.ranges.get(i2 + a); } }, this.values.subList(a, a2)) { // from class: com.google.common.collect.ImmutableRangeMap.2 @Override // com.google.common.collect.ImmutableRangeMap /* renamed from: asDescendingMapOfRanges */ public /* bridge */ /* synthetic */ Map mo7asDescendingMapOfRanges() { return super.mo7asDescendingMapOfRanges(); } @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 /* renamed from: subRangeMap, reason: merged with bridge method [inline-methods] */ public ImmutableRangeMap mo8subRangeMap(Range range2) { return range.isConnected(range2) ? this.mo8subRangeMap((Range) range2.intersection(range)) : ImmutableRangeMap.of(); } }; } public static final class Builder, V> { private final List, V>> a = Lists.a(); public Builder a(Range range, V v) { Preconditions.a(range); Preconditions.a(v); Preconditions.a(!range.isEmpty(), "Range must not be empty, but was %s", range); this.a.add(Maps.a(range, v)); return this; } public ImmutableRangeMap a() { Collections.sort(this.a, Range.rangeLexOrdering().a()); ImmutableList.Builder builder = new ImmutableList.Builder(this.a.size()); ImmutableList.Builder builder2 = new ImmutableList.Builder(this.a.size()); for (int i = 0; i < this.a.size(); i++) { Range key = this.a.get(i).getKey(); if (i > 0) { Range key2 = this.a.get(i - 1).getKey(); if (key.isConnected(key2) && !key.intersection(key2).isEmpty()) { throw new IllegalArgumentException("Overlapping ranges: range " + key2 + " overlaps with entry " + key); } } builder.a((ImmutableList.Builder) key); builder2.a((ImmutableList.Builder) this.a.get(i).getValue()); } return new ImmutableRangeMap<>(builder.a(), builder2.a()); } } }