239 lines
9.6 KiB
Java
239 lines
9.6 KiB
Java
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<K extends Comparable<?>, V> implements RangeMap<K, V>, Serializable {
|
|
private static final ImmutableRangeMap<Comparable<?>, Object> EMPTY = new ImmutableRangeMap<>(ImmutableList.of(), ImmutableList.of());
|
|
private static final long serialVersionUID = 0;
|
|
private final transient ImmutableList<Range<K>> ranges;
|
|
private final transient ImmutableList<V> values;
|
|
|
|
private static class SerializedForm<K extends Comparable<?>, V> implements Serializable {
|
|
private final ImmutableMap<Range<K>, V> a;
|
|
|
|
SerializedForm(ImmutableMap<Range<K>, V> immutableMap) {
|
|
this.a = immutableMap;
|
|
}
|
|
|
|
Object a() {
|
|
Builder builder = new Builder();
|
|
UnmodifiableIterator<Map.Entry<Range<K>, V>> it = this.a.entrySet().iterator();
|
|
while (it.hasNext()) {
|
|
Map.Entry<Range<K>, V> next = it.next();
|
|
builder.a(next.getKey(), next.getValue());
|
|
}
|
|
return builder.a();
|
|
}
|
|
|
|
Object readResolve() {
|
|
return this.a.isEmpty() ? ImmutableRangeMap.of() : a();
|
|
}
|
|
}
|
|
|
|
ImmutableRangeMap(ImmutableList<Range<K>> immutableList, ImmutableList<V> immutableList2) {
|
|
this.ranges = immutableList;
|
|
this.values = immutableList2;
|
|
}
|
|
|
|
public static <K extends Comparable<?>, V> Builder<K, V> builder() {
|
|
return new Builder<>();
|
|
}
|
|
|
|
public static <K extends Comparable<?>, V> ImmutableRangeMap<K, V> copyOf(RangeMap<K, ? extends V> rangeMap) {
|
|
if (rangeMap instanceof ImmutableRangeMap) {
|
|
return (ImmutableRangeMap) rangeMap;
|
|
}
|
|
Map<Range<K>, ? extends V> asMapOfRanges = rangeMap.asMapOfRanges();
|
|
ImmutableList.Builder builder = new ImmutableList.Builder(asMapOfRanges.size());
|
|
ImmutableList.Builder builder2 = new ImmutableList.Builder(asMapOfRanges.size());
|
|
for (Map.Entry<Range<K>, ? 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 <K extends Comparable<?>, V> ImmutableRangeMap<K, V> of() {
|
|
return (ImmutableRangeMap<K, V>) 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<? super E, Cut>) 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<Range<K>, V> getEntry(K k) {
|
|
int a = SortedLists.a(this.ranges, (Function<? super E, Cut>) Range.lowerBoundFn(), Cut.c(k), SortedLists.KeyPresentBehavior.ANY_PRESENT, SortedLists.KeyAbsentBehavior.NEXT_LOWER);
|
|
if (a == -1) {
|
|
return null;
|
|
}
|
|
Range<K> 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<K> range, V v) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
@Deprecated
|
|
public void putAll(RangeMap<K, V> rangeMap) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
@Deprecated
|
|
public void putCoalescing(Range<K> range, V v) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
@Deprecated
|
|
public void remove(Range<K> range) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
public Range<K> 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 <K extends Comparable<?>, V> ImmutableRangeMap<K, V> of(Range<K> 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<Range<K>, 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<Range<K>, V> asMapOfRanges() {
|
|
return this.ranges.isEmpty() ? ImmutableMap.of() : new ImmutableSortedMap(new RegularImmutableSortedSet(this.ranges, Range.rangeLexOrdering()), this.values);
|
|
}
|
|
|
|
@Override //
|
|
/* renamed from: subRangeMap */
|
|
public ImmutableRangeMap<K, V> mo8subRangeMap(final Range<K> 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<? super E, Cut<K>>) Range.upperBoundFn(), range.lowerBound, SortedLists.KeyPresentBehavior.FIRST_AFTER, SortedLists.KeyAbsentBehavior.NEXT_HIGHER);
|
|
int a2 = SortedLists.a(this.ranges, (Function<? super E, Cut<K>>) Range.lowerBoundFn(), range.upperBound, SortedLists.KeyPresentBehavior.ANY_PRESENT, SortedLists.KeyAbsentBehavior.NEXT_HIGHER);
|
|
if (a >= a2) {
|
|
return of();
|
|
}
|
|
final int i = a2 - a;
|
|
return (ImmutableRangeMap<K, V>) new ImmutableRangeMap<K, V>(this, new ImmutableList<Range<K>>() { // 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<K> 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<K, V> mo8subRangeMap(Range<K> range2) {
|
|
return range.isConnected(range2) ? this.mo8subRangeMap((Range) range2.intersection(range)) : ImmutableRangeMap.of();
|
|
}
|
|
};
|
|
}
|
|
|
|
public static final class Builder<K extends Comparable<?>, V> {
|
|
private final List<Map.Entry<Range<K>, V>> a = Lists.a();
|
|
|
|
public Builder<K, V> a(Range<K> 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<K, V> 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<K> key = this.a.get(i).getKey();
|
|
if (i > 0) {
|
|
Range<K> 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());
|
|
}
|
|
}
|
|
}
|