what-the-bank/sources/com/google/common/collect/TreeRangeSet.java

869 lines
41 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.collect;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import java.io.Serializable;
import java.lang.Comparable;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.NavigableMap;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.TreeMap;
/* loaded from: classes2.dex */
public class TreeRangeSet<C extends Comparable<?>> extends AbstractRangeSet<C> implements Serializable {
private transient Set<Range<C>> asDescendingSetOfRanges;
private transient Set<Range<C>> asRanges;
private transient RangeSet<C> complement;
final NavigableMap<Cut<C>, Range<C>> rangesByLowerBound;
@Override // com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public /* bridge */ /* synthetic */ void addAll(RangeSet rangeSet) {
super.addAll(rangeSet);
}
@Override // com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public /* bridge */ /* synthetic */ void addAll(Iterable iterable) {
super.addAll(iterable);
}
@Override // com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public /* bridge */ /* synthetic */ void clear() {
super.clear();
}
@Override // com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public /* bridge */ /* synthetic */ boolean contains(Comparable comparable) {
return super.contains(comparable);
}
@Override // com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public /* bridge */ /* synthetic */ boolean enclosesAll(RangeSet rangeSet) {
return super.enclosesAll(rangeSet);
}
@Override // com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public /* bridge */ /* synthetic */ boolean enclosesAll(Iterable iterable) {
return super.enclosesAll(iterable);
}
@Override // com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public /* bridge */ /* synthetic */ boolean equals(Object obj) {
return super.equals(obj);
}
@Override // com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public /* bridge */ /* synthetic */ boolean isEmpty() {
return super.isEmpty();
}
@Override // com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public /* bridge */ /* synthetic */ void removeAll(RangeSet rangeSet) {
super.removeAll(rangeSet);
}
@Override // com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public /* bridge */ /* synthetic */ void removeAll(Iterable iterable) {
super.removeAll(iterable);
}
public static <C extends Comparable<?>> TreeRangeSet<C> create() {
return new TreeRangeSet<>(new TreeMap());
}
public static <C extends Comparable<?>> TreeRangeSet<C> create(RangeSet<C> rangeSet) {
TreeRangeSet<C> create = create();
create.addAll(rangeSet);
return create;
}
public static <C extends Comparable<?>> TreeRangeSet<C> create(Iterable<Range<C>> iterable) {
TreeRangeSet<C> create = create();
create.addAll(iterable);
return create;
}
private TreeRangeSet(NavigableMap<Cut<C>, Range<C>> navigableMap) {
this.rangesByLowerBound = navigableMap;
}
@Override // com.google.common.collect.RangeSet
public Set<Range<C>> asRanges() {
Set<Range<C>> set = this.asRanges;
if (set != null) {
return set;
}
AsRanges asRanges = new AsRanges(this, this.rangesByLowerBound.values());
this.asRanges = asRanges;
return asRanges;
}
@Override // com.google.common.collect.RangeSet
public Set<Range<C>> asDescendingSetOfRanges() {
Set<Range<C>> set = this.asDescendingSetOfRanges;
if (set != null) {
return set;
}
AsRanges asRanges = new AsRanges(this, this.rangesByLowerBound.descendingMap().values());
this.asDescendingSetOfRanges = asRanges;
return asRanges;
}
/* loaded from: classes2.dex */
final class AsRanges extends ForwardingCollection<Range<C>> implements Set<Range<C>> {
final Collection<Range<C>> delegate;
AsRanges(TreeRangeSet treeRangeSet, Collection<Range<C>> collection) {
this.delegate = collection;
}
@Override // java.util.Collection, java.util.Set
public final int hashCode() {
return Sets.hashCodeImpl(this);
}
@Override // java.util.Collection, java.util.Set
public final boolean equals(Object obj) {
return Sets.equalsImpl(this, obj);
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.collect.ForwardingCollection, com.google.common.collect.ForwardingObject
public final Collection<Range<C>> delegate() {
return this.delegate;
}
}
@Override // com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public Range<C> rangeContaining(C c) {
Preconditions.checkNotNull(c);
Map.Entry<Cut<C>, Range<C>> floorEntry = this.rangesByLowerBound.floorEntry(Cut.belowValue(c));
if (floorEntry == null || !floorEntry.getValue().contains(c)) {
return null;
}
return floorEntry.getValue();
}
@Override // com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public boolean intersects(Range<C> range) {
Preconditions.checkNotNull(range);
Map.Entry<Cut<C>, Range<C>> ceilingEntry = this.rangesByLowerBound.ceilingEntry(range.lowerBound);
if (ceilingEntry != null && ceilingEntry.getValue().isConnected(range) && !ceilingEntry.getValue().intersection(range).isEmpty()) {
return true;
}
Map.Entry<Cut<C>, Range<C>> lowerEntry = this.rangesByLowerBound.lowerEntry(range.lowerBound);
return (lowerEntry == null || !lowerEntry.getValue().isConnected(range) || lowerEntry.getValue().intersection(range).isEmpty()) ? false : true;
}
@Override // com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public boolean encloses(Range<C> range) {
Preconditions.checkNotNull(range);
Map.Entry<Cut<C>, Range<C>> floorEntry = this.rangesByLowerBound.floorEntry(range.lowerBound);
return floorEntry != null && floorEntry.getValue().encloses(range);
}
/* JADX INFO: Access modifiers changed from: private */
public Range<C> rangeEnclosing(Range<C> range) {
Preconditions.checkNotNull(range);
Map.Entry<Cut<C>, Range<C>> floorEntry = this.rangesByLowerBound.floorEntry(range.lowerBound);
if (floorEntry == null || !floorEntry.getValue().encloses(range)) {
return null;
}
return floorEntry.getValue();
}
@Override // com.google.common.collect.RangeSet
public Range<C> span() {
Map.Entry<Cut<C>, Range<C>> firstEntry = this.rangesByLowerBound.firstEntry();
Map.Entry<Cut<C>, Range<C>> lastEntry = this.rangesByLowerBound.lastEntry();
if (firstEntry == null) {
throw new NoSuchElementException();
}
return Range.create(firstEntry.getValue().lowerBound, lastEntry.getValue().upperBound);
}
@Override // com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public void add(Range<C> range) {
Preconditions.checkNotNull(range);
if (range.isEmpty()) {
return;
}
Cut<C> cut = range.lowerBound;
Cut<C> cut2 = range.upperBound;
Map.Entry<Cut<C>, Range<C>> lowerEntry = this.rangesByLowerBound.lowerEntry(cut);
if (lowerEntry != null) {
Range<C> value = lowerEntry.getValue();
if (value.upperBound.compareTo(cut) >= 0) {
if (value.upperBound.compareTo(cut2) >= 0) {
cut2 = value.upperBound;
}
cut = value.lowerBound;
}
}
Map.Entry<Cut<C>, Range<C>> floorEntry = this.rangesByLowerBound.floorEntry(cut2);
if (floorEntry != null) {
Range<C> value2 = floorEntry.getValue();
if (value2.upperBound.compareTo(cut2) >= 0) {
cut2 = value2.upperBound;
}
}
this.rangesByLowerBound.subMap(cut, cut2).clear();
replaceRangeWithSameLowerBound(Range.create(cut, cut2));
}
@Override // com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public void remove(Range<C> range) {
Preconditions.checkNotNull(range);
if (range.isEmpty()) {
return;
}
Map.Entry<Cut<C>, Range<C>> lowerEntry = this.rangesByLowerBound.lowerEntry(range.lowerBound);
if (lowerEntry != null) {
Range<C> value = lowerEntry.getValue();
if (value.upperBound.compareTo(range.lowerBound) >= 0) {
if (range.hasUpperBound() && value.upperBound.compareTo(range.upperBound) >= 0) {
replaceRangeWithSameLowerBound(Range.create(range.upperBound, value.upperBound));
}
replaceRangeWithSameLowerBound(Range.create(value.lowerBound, range.lowerBound));
}
}
Map.Entry<Cut<C>, Range<C>> floorEntry = this.rangesByLowerBound.floorEntry(range.upperBound);
if (floorEntry != null) {
Range<C> value2 = floorEntry.getValue();
if (range.hasUpperBound() && value2.upperBound.compareTo(range.upperBound) >= 0) {
replaceRangeWithSameLowerBound(Range.create(range.upperBound, value2.upperBound));
}
}
this.rangesByLowerBound.subMap(range.lowerBound, range.upperBound).clear();
}
private void replaceRangeWithSameLowerBound(Range<C> range) {
if (range.isEmpty()) {
this.rangesByLowerBound.remove(range.lowerBound);
} else {
this.rangesByLowerBound.put(range.lowerBound, range);
}
}
@Override // com.google.common.collect.RangeSet
public RangeSet<C> complement() {
RangeSet<C> rangeSet = this.complement;
if (rangeSet != null) {
return rangeSet;
}
Complement complement = new Complement(this);
this.complement = complement;
return complement;
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static final class RangesByUpperBound<C extends Comparable<?>> extends AbstractNavigableMap<Cut<C>, Range<C>> {
private final NavigableMap<Cut<C>, Range<C>> rangesByLowerBound;
private final Range<Cut<C>> upperBoundWindow;
RangesByUpperBound(NavigableMap<Cut<C>, Range<C>> navigableMap) {
this.rangesByLowerBound = navigableMap;
this.upperBoundWindow = Range.all();
}
private RangesByUpperBound(NavigableMap<Cut<C>, Range<C>> navigableMap, Range<Cut<C>> range) {
this.rangesByLowerBound = navigableMap;
this.upperBoundWindow = range;
}
private NavigableMap<Cut<C>, Range<C>> subMap(Range<Cut<C>> range) {
if (range.isConnected(this.upperBoundWindow)) {
return new RangesByUpperBound(this.rangesByLowerBound, range.intersection(this.upperBoundWindow));
}
return ImmutableSortedMap.of();
}
@Override // java.util.NavigableMap
public final NavigableMap<Cut<C>, Range<C>> subMap(Cut<C> cut, boolean z, Cut<C> cut2, boolean z2) {
return subMap(Range.range(cut, BoundType.forBoolean(z), cut2, BoundType.forBoolean(z2)));
}
@Override // java.util.NavigableMap
public final NavigableMap<Cut<C>, Range<C>> headMap(Cut<C> cut, boolean z) {
return subMap(Range.upTo(cut, BoundType.forBoolean(z)));
}
@Override // java.util.NavigableMap
public final NavigableMap<Cut<C>, Range<C>> tailMap(Cut<C> cut, boolean z) {
return subMap(Range.downTo(cut, BoundType.forBoolean(z)));
}
@Override // java.util.SortedMap
public final Comparator<? super Cut<C>> comparator() {
return Ordering.natural();
}
@Override // java.util.AbstractMap, java.util.Map
public final boolean containsKey(Object obj) {
return get(obj) != null;
}
@Override // com.google.common.collect.AbstractNavigableMap, java.util.AbstractMap, java.util.Map
public final Range<C> get(Object obj) {
Map.Entry<Cut<C>, Range<C>> lowerEntry;
if (obj instanceof Cut) {
try {
Cut<C> cut = (Cut) obj;
if (this.upperBoundWindow.contains(cut) && (lowerEntry = this.rangesByLowerBound.lowerEntry(cut)) != null && lowerEntry.getValue().upperBound.equals(cut)) {
return lowerEntry.getValue();
}
} catch (ClassCastException unused) {
}
}
return null;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.Maps.IteratorBasedAbstractMap
public final Iterator<Map.Entry<Cut<C>, Range<C>>> entryIterator() {
Iterator<Range<C>> it;
if (!this.upperBoundWindow.hasLowerBound()) {
it = this.rangesByLowerBound.values().iterator();
} else {
Map.Entry lowerEntry = this.rangesByLowerBound.lowerEntry(this.upperBoundWindow.lowerEndpoint());
if (lowerEntry == null) {
it = this.rangesByLowerBound.values().iterator();
} else if (this.upperBoundWindow.lowerBound.isLessThan(((Range) lowerEntry.getValue()).upperBound)) {
it = this.rangesByLowerBound.tailMap(lowerEntry.getKey(), true).values().iterator();
} else {
it = this.rangesByLowerBound.tailMap(this.upperBoundWindow.lowerEndpoint(), true).values().iterator();
}
}
return new AbstractIterator<Map.Entry<Cut<C>, Range<C>>>(this, it) { // from class: com.google.common.collect.TreeRangeSet.RangesByUpperBound.1
final RangesByUpperBound this$0;
final Iterator val$backingItr;
{
this.this$0 = this;
this.val$backingItr = it;
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.collect.AbstractIterator
public Map.Entry<Cut<C>, Range<C>> computeNext() {
if (!this.val$backingItr.hasNext()) {
return (Map.Entry) endOfData();
}
Range range = (Range) this.val$backingItr.next();
if (this.this$0.upperBoundWindow.upperBound.isLessThan(range.upperBound)) {
return (Map.Entry) endOfData();
}
return Maps.immutableEntry(range.upperBound, range);
}
};
}
@Override // com.google.common.collect.AbstractNavigableMap
final Iterator<Map.Entry<Cut<C>, Range<C>>> descendingEntryIterator() {
Collection<Range<C>> values;
if (this.upperBoundWindow.hasUpperBound()) {
values = this.rangesByLowerBound.headMap(this.upperBoundWindow.upperEndpoint(), false).descendingMap().values();
} else {
values = this.rangesByLowerBound.descendingMap().values();
}
PeekingIterator peekingIterator = Iterators.peekingIterator(values.iterator());
if (peekingIterator.hasNext() && this.upperBoundWindow.upperBound.isLessThan(((Range) peekingIterator.peek()).upperBound)) {
peekingIterator.next();
}
return new AbstractIterator<Map.Entry<Cut<C>, Range<C>>>(this, peekingIterator) { // from class: com.google.common.collect.TreeRangeSet.RangesByUpperBound.2
final RangesByUpperBound this$0;
final PeekingIterator val$backingItr;
{
this.this$0 = this;
this.val$backingItr = peekingIterator;
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.collect.AbstractIterator
public Map.Entry<Cut<C>, Range<C>> computeNext() {
if (!this.val$backingItr.hasNext()) {
return (Map.Entry) endOfData();
}
Range range = (Range) this.val$backingItr.next();
if (this.this$0.upperBoundWindow.lowerBound.isLessThan(range.upperBound)) {
return Maps.immutableEntry(range.upperBound, range);
}
return (Map.Entry) endOfData();
}
};
}
@Override // com.google.common.collect.Maps.IteratorBasedAbstractMap, java.util.AbstractMap, java.util.Map
public final int size() {
if (this.upperBoundWindow.equals(Range.all())) {
return this.rangesByLowerBound.size();
}
return Iterators.size(entryIterator());
}
@Override // java.util.AbstractMap, java.util.Map
public final boolean isEmpty() {
if (this.upperBoundWindow.equals(Range.all())) {
return this.rangesByLowerBound.isEmpty();
}
return !entryIterator().hasNext();
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static final class ComplementRangesByLowerBound<C extends Comparable<?>> extends AbstractNavigableMap<Cut<C>, Range<C>> {
private final Range<Cut<C>> complementLowerBoundWindow;
private final NavigableMap<Cut<C>, Range<C>> positiveRangesByLowerBound;
private final NavigableMap<Cut<C>, Range<C>> positiveRangesByUpperBound;
ComplementRangesByLowerBound(NavigableMap<Cut<C>, Range<C>> navigableMap) {
this(navigableMap, Range.all());
}
private ComplementRangesByLowerBound(NavigableMap<Cut<C>, Range<C>> navigableMap, Range<Cut<C>> range) {
this.positiveRangesByLowerBound = navigableMap;
this.positiveRangesByUpperBound = new RangesByUpperBound(navigableMap);
this.complementLowerBoundWindow = range;
}
private NavigableMap<Cut<C>, Range<C>> subMap(Range<Cut<C>> range) {
if (!this.complementLowerBoundWindow.isConnected(range)) {
return ImmutableSortedMap.of();
}
return new ComplementRangesByLowerBound(this.positiveRangesByLowerBound, range.intersection(this.complementLowerBoundWindow));
}
@Override // java.util.NavigableMap
public final NavigableMap<Cut<C>, Range<C>> subMap(Cut<C> cut, boolean z, Cut<C> cut2, boolean z2) {
return subMap(Range.range(cut, BoundType.forBoolean(z), cut2, BoundType.forBoolean(z2)));
}
@Override // java.util.NavigableMap
public final NavigableMap<Cut<C>, Range<C>> headMap(Cut<C> cut, boolean z) {
return subMap(Range.upTo(cut, BoundType.forBoolean(z)));
}
@Override // java.util.NavigableMap
public final NavigableMap<Cut<C>, Range<C>> tailMap(Cut<C> cut, boolean z) {
return subMap(Range.downTo(cut, BoundType.forBoolean(z)));
}
@Override // java.util.SortedMap
public final Comparator<? super Cut<C>> comparator() {
return Ordering.natural();
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.Maps.IteratorBasedAbstractMap
public final Iterator<Map.Entry<Cut<C>, Range<C>>> entryIterator() {
Collection<Range<C>> values;
Cut cut;
if (this.complementLowerBoundWindow.hasLowerBound()) {
values = this.positiveRangesByUpperBound.tailMap(this.complementLowerBoundWindow.lowerEndpoint(), this.complementLowerBoundWindow.lowerBoundType() == BoundType.CLOSED).values();
} else {
values = this.positiveRangesByUpperBound.values();
}
PeekingIterator peekingIterator = Iterators.peekingIterator(values.iterator());
if (this.complementLowerBoundWindow.contains(Cut.belowAll()) && (!peekingIterator.hasNext() || ((Range) peekingIterator.peek()).lowerBound != Cut.belowAll())) {
cut = Cut.belowAll();
} else if (peekingIterator.hasNext()) {
cut = ((Range) peekingIterator.next()).upperBound;
} else {
return Iterators.emptyIterator();
}
return new AbstractIterator<Map.Entry<Cut<C>, Range<C>>>(this, cut, peekingIterator) { // from class: com.google.common.collect.TreeRangeSet.ComplementRangesByLowerBound.1
Cut<C> nextComplementRangeLowerBound;
final ComplementRangesByLowerBound this$0;
final Cut val$firstComplementRangeLowerBound;
final PeekingIterator val$positiveItr;
{
this.this$0 = this;
this.val$firstComplementRangeLowerBound = cut;
this.val$positiveItr = peekingIterator;
this.nextComplementRangeLowerBound = cut;
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.collect.AbstractIterator
public Map.Entry<Cut<C>, Range<C>> computeNext() {
Range create;
if (this.this$0.complementLowerBoundWindow.upperBound.isLessThan(this.nextComplementRangeLowerBound) || this.nextComplementRangeLowerBound == Cut.aboveAll()) {
return (Map.Entry) endOfData();
}
if (this.val$positiveItr.hasNext()) {
Range range = (Range) this.val$positiveItr.next();
create = Range.create(this.nextComplementRangeLowerBound, range.lowerBound);
this.nextComplementRangeLowerBound = range.upperBound;
} else {
create = Range.create(this.nextComplementRangeLowerBound, Cut.aboveAll());
this.nextComplementRangeLowerBound = Cut.aboveAll();
}
return Maps.immutableEntry(create.lowerBound, create);
}
};
}
@Override // com.google.common.collect.AbstractNavigableMap
final Iterator<Map.Entry<Cut<C>, Range<C>>> descendingEntryIterator() {
Cut<C> aboveAll;
Cut<C> higherKey;
if (this.complementLowerBoundWindow.hasUpperBound()) {
aboveAll = this.complementLowerBoundWindow.upperEndpoint();
} else {
aboveAll = Cut.aboveAll();
}
PeekingIterator peekingIterator = Iterators.peekingIterator(this.positiveRangesByUpperBound.headMap(aboveAll, this.complementLowerBoundWindow.hasUpperBound() && this.complementLowerBoundWindow.upperBoundType() == BoundType.CLOSED).descendingMap().values().iterator());
if (peekingIterator.hasNext()) {
if (((Range) peekingIterator.peek()).upperBound == Cut.aboveAll()) {
higherKey = ((Range) peekingIterator.next()).lowerBound;
} else {
higherKey = this.positiveRangesByLowerBound.higherKey(((Range) peekingIterator.peek()).upperBound);
}
} else {
if (!this.complementLowerBoundWindow.contains(Cut.belowAll()) || this.positiveRangesByLowerBound.containsKey(Cut.belowAll())) {
return Iterators.emptyIterator();
}
higherKey = this.positiveRangesByLowerBound.higherKey(Cut.belowAll());
}
return new AbstractIterator<Map.Entry<Cut<C>, Range<C>>>(this, (Cut) MoreObjects.firstNonNull(higherKey, Cut.aboveAll()), peekingIterator) { // from class: com.google.common.collect.TreeRangeSet.ComplementRangesByLowerBound.2
Cut<C> nextComplementRangeUpperBound;
final ComplementRangesByLowerBound this$0;
final Cut val$firstComplementRangeUpperBound;
final PeekingIterator val$positiveItr;
{
this.this$0 = this;
this.val$firstComplementRangeUpperBound = r2;
this.val$positiveItr = peekingIterator;
this.nextComplementRangeUpperBound = r2;
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.collect.AbstractIterator
public Map.Entry<Cut<C>, Range<C>> computeNext() {
if (this.nextComplementRangeUpperBound == Cut.belowAll()) {
return (Map.Entry) endOfData();
}
if (!this.val$positiveItr.hasNext()) {
if (this.this$0.complementLowerBoundWindow.lowerBound.isLessThan(Cut.belowAll())) {
Range create = Range.create(Cut.belowAll(), this.nextComplementRangeUpperBound);
this.nextComplementRangeUpperBound = Cut.belowAll();
return Maps.immutableEntry(Cut.belowAll(), create);
}
} else {
Range range = (Range) this.val$positiveItr.next();
Range create2 = Range.create(range.upperBound, this.nextComplementRangeUpperBound);
this.nextComplementRangeUpperBound = range.lowerBound;
if (this.this$0.complementLowerBoundWindow.lowerBound.isLessThan(create2.lowerBound)) {
return Maps.immutableEntry(create2.lowerBound, create2);
}
}
return (Map.Entry) endOfData();
}
};
}
@Override // com.google.common.collect.Maps.IteratorBasedAbstractMap, java.util.AbstractMap, java.util.Map
public final int size() {
return Iterators.size(entryIterator());
}
@Override // com.google.common.collect.AbstractNavigableMap, java.util.AbstractMap, java.util.Map
public final Range<C> get(Object obj) {
if (!(obj instanceof Cut)) {
return null;
}
try {
Cut<C> cut = (Cut) obj;
Map.Entry<Cut<C>, Range<C>> firstEntry = tailMap((Cut) cut, true).firstEntry();
if (firstEntry == null || !firstEntry.getKey().equals(cut)) {
return null;
}
return firstEntry.getValue();
} catch (ClassCastException unused) {
return null;
}
}
@Override // java.util.AbstractMap, java.util.Map
public final boolean containsKey(Object obj) {
return get(obj) != null;
}
}
/* loaded from: classes2.dex */
final class Complement extends TreeRangeSet<C> {
final TreeRangeSet this$0;
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
Complement(TreeRangeSet treeRangeSet) {
super(new ComplementRangesByLowerBound(treeRangeSet.rangesByLowerBound));
this.this$0 = treeRangeSet;
}
@Override // com.google.common.collect.TreeRangeSet, com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public final void add(Range<C> range) {
this.this$0.remove(range);
}
@Override // com.google.common.collect.TreeRangeSet, com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public final void remove(Range<C> range) {
this.this$0.add(range);
}
@Override // com.google.common.collect.TreeRangeSet, com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public final boolean contains(C c) {
return !this.this$0.contains(c);
}
@Override // com.google.common.collect.TreeRangeSet, com.google.common.collect.RangeSet
public final RangeSet<C> complement() {
return this.this$0;
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static final class SubRangeSetRangesByLowerBound<C extends Comparable<?>> extends AbstractNavigableMap<Cut<C>, Range<C>> {
private final Range<Cut<C>> lowerBoundWindow;
private final NavigableMap<Cut<C>, Range<C>> rangesByLowerBound;
private final NavigableMap<Cut<C>, Range<C>> rangesByUpperBound;
private final Range<C> restriction;
private SubRangeSetRangesByLowerBound(Range<Cut<C>> range, Range<C> range2, NavigableMap<Cut<C>, Range<C>> navigableMap) {
this.lowerBoundWindow = (Range) Preconditions.checkNotNull(range);
this.restriction = (Range) Preconditions.checkNotNull(range2);
this.rangesByLowerBound = (NavigableMap) Preconditions.checkNotNull(navigableMap);
this.rangesByUpperBound = new RangesByUpperBound(navigableMap);
}
private NavigableMap<Cut<C>, Range<C>> subMap(Range<Cut<C>> range) {
if (!range.isConnected(this.lowerBoundWindow)) {
return ImmutableSortedMap.of();
}
return new SubRangeSetRangesByLowerBound(this.lowerBoundWindow.intersection(range), this.restriction, this.rangesByLowerBound);
}
@Override // java.util.NavigableMap
public final NavigableMap<Cut<C>, Range<C>> subMap(Cut<C> cut, boolean z, Cut<C> cut2, boolean z2) {
return subMap(Range.range(cut, BoundType.forBoolean(z), cut2, BoundType.forBoolean(z2)));
}
@Override // java.util.NavigableMap
public final NavigableMap<Cut<C>, Range<C>> headMap(Cut<C> cut, boolean z) {
return subMap(Range.upTo(cut, BoundType.forBoolean(z)));
}
@Override // java.util.NavigableMap
public final NavigableMap<Cut<C>, Range<C>> tailMap(Cut<C> cut, boolean z) {
return subMap(Range.downTo(cut, BoundType.forBoolean(z)));
}
@Override // java.util.SortedMap
public final Comparator<? super Cut<C>> comparator() {
return Ordering.natural();
}
@Override // java.util.AbstractMap, java.util.Map
public final boolean containsKey(Object obj) {
return get(obj) != null;
}
@Override // com.google.common.collect.AbstractNavigableMap, java.util.AbstractMap, java.util.Map
public final Range<C> get(Object obj) {
if (!(obj instanceof Cut)) {
return null;
}
try {
Cut<C> cut = (Cut) obj;
if (this.lowerBoundWindow.contains(cut) && cut.compareTo(this.restriction.lowerBound) >= 0 && cut.compareTo(this.restriction.upperBound) < 0) {
if (cut.equals(this.restriction.lowerBound)) {
Range range = (Range) Maps.valueOrNull(this.rangesByLowerBound.floorEntry(cut));
if (range == null || range.upperBound.compareTo((Cut) this.restriction.lowerBound) <= 0) {
return null;
}
return range.intersection(this.restriction);
}
Range range2 = (Range) this.rangesByLowerBound.get(cut);
if (range2 != null) {
return range2.intersection(this.restriction);
}
return null;
}
return null;
} catch (ClassCastException unused) {
return null;
}
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.Maps.IteratorBasedAbstractMap
public final Iterator<Map.Entry<Cut<C>, Range<C>>> entryIterator() {
Iterator<Range<C>> it;
if (this.restriction.isEmpty()) {
return Iterators.emptyIterator();
}
if (this.lowerBoundWindow.upperBound.isLessThan(this.restriction.lowerBound)) {
return Iterators.emptyIterator();
}
if (this.lowerBoundWindow.lowerBound.isLessThan(this.restriction.lowerBound)) {
it = this.rangesByUpperBound.tailMap(this.restriction.lowerBound, false).values().iterator();
} else {
it = this.rangesByLowerBound.tailMap(this.lowerBoundWindow.lowerBound.endpoint(), this.lowerBoundWindow.lowerBoundType() == BoundType.CLOSED).values().iterator();
}
return new AbstractIterator<Map.Entry<Cut<C>, Range<C>>>(this, it, (Cut) Ordering.natural().min(this.lowerBoundWindow.upperBound, Cut.belowValue(this.restriction.upperBound))) { // from class: com.google.common.collect.TreeRangeSet.SubRangeSetRangesByLowerBound.1
final SubRangeSetRangesByLowerBound this$0;
final Iterator val$completeRangeItr;
final Cut val$upperBoundOnLowerBounds;
{
this.this$0 = this;
this.val$completeRangeItr = it;
this.val$upperBoundOnLowerBounds = r3;
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.collect.AbstractIterator
public Map.Entry<Cut<C>, Range<C>> computeNext() {
if (!this.val$completeRangeItr.hasNext()) {
return (Map.Entry) endOfData();
}
Range range = (Range) this.val$completeRangeItr.next();
if (!this.val$upperBoundOnLowerBounds.isLessThan(range.lowerBound)) {
Range intersection = range.intersection(this.this$0.restriction);
return Maps.immutableEntry(intersection.lowerBound, intersection);
}
return (Map.Entry) endOfData();
}
};
}
@Override // com.google.common.collect.AbstractNavigableMap
final Iterator<Map.Entry<Cut<C>, Range<C>>> descendingEntryIterator() {
if (this.restriction.isEmpty()) {
return Iterators.emptyIterator();
}
Cut cut = (Cut) Ordering.natural().min(this.lowerBoundWindow.upperBound, Cut.belowValue(this.restriction.upperBound));
return new AbstractIterator<Map.Entry<Cut<C>, Range<C>>>(this, this.rangesByLowerBound.headMap(cut.endpoint(), cut.typeAsUpperBound() == BoundType.CLOSED).descendingMap().values().iterator()) { // from class: com.google.common.collect.TreeRangeSet.SubRangeSetRangesByLowerBound.2
final SubRangeSetRangesByLowerBound this$0;
final Iterator val$completeRangeItr;
{
this.this$0 = this;
this.val$completeRangeItr = r2;
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.collect.AbstractIterator
public Map.Entry<Cut<C>, Range<C>> computeNext() {
if (!this.val$completeRangeItr.hasNext()) {
return (Map.Entry) endOfData();
}
Range range = (Range) this.val$completeRangeItr.next();
if (this.this$0.restriction.lowerBound.compareTo((Cut) range.upperBound) < 0) {
Range intersection = range.intersection(this.this$0.restriction);
if (this.this$0.lowerBoundWindow.contains(intersection.lowerBound)) {
return Maps.immutableEntry(intersection.lowerBound, intersection);
}
return (Map.Entry) endOfData();
}
return (Map.Entry) endOfData();
}
};
}
@Override // com.google.common.collect.Maps.IteratorBasedAbstractMap, java.util.AbstractMap, java.util.Map
public final int size() {
return Iterators.size(entryIterator());
}
}
@Override // com.google.common.collect.RangeSet
public RangeSet<C> subRangeSet(Range<C> range) {
return range.equals(Range.all()) ? this : new SubRangeSet(this, range);
}
/* loaded from: classes2.dex */
final class SubRangeSet extends TreeRangeSet<C> {
private final Range<C> restriction;
final TreeRangeSet this$0;
/* JADX WARN: Illegal instructions before constructor call */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
SubRangeSet(com.google.common.collect.TreeRangeSet r4, com.google.common.collect.Range<C> r5) {
/*
r3 = this;
r3.this$0 = r4
com.google.common.collect.TreeRangeSet$SubRangeSetRangesByLowerBound r0 = new com.google.common.collect.TreeRangeSet$SubRangeSetRangesByLowerBound
com.google.common.collect.Range r1 = com.google.common.collect.Range.all()
java.util.NavigableMap<com.google.common.collect.Cut<C extends java.lang.Comparable<?>>, com.google.common.collect.Range<C extends java.lang.Comparable<?>>> r4 = r4.rangesByLowerBound
r2 = 0
r0.<init>(r1, r5, r4)
r3.<init>(r0)
r3.restriction = r5
return
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.common.collect.TreeRangeSet.SubRangeSet.<init>(com.google.common.collect.TreeRangeSet, com.google.common.collect.Range):void");
}
@Override // com.google.common.collect.TreeRangeSet, com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public final boolean encloses(Range<C> range) {
Range rangeEnclosing;
return (this.restriction.isEmpty() || !this.restriction.encloses(range) || (rangeEnclosing = this.this$0.rangeEnclosing(range)) == null || rangeEnclosing.intersection(this.restriction).isEmpty()) ? false : true;
}
@Override // com.google.common.collect.TreeRangeSet, com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public final Range<C> rangeContaining(C c) {
Range<C> rangeContaining;
if (this.restriction.contains(c) && (rangeContaining = this.this$0.rangeContaining(c)) != null) {
return rangeContaining.intersection(this.restriction);
}
return null;
}
@Override // com.google.common.collect.TreeRangeSet, com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public final void add(Range<C> range) {
Preconditions.checkArgument(this.restriction.encloses(range), "Cannot add range %s to subRangeSet(%s)", range, this.restriction);
this.this$0.add(range);
}
@Override // com.google.common.collect.TreeRangeSet, com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public final void remove(Range<C> range) {
if (range.isConnected(this.restriction)) {
this.this$0.remove(range.intersection(this.restriction));
}
}
@Override // com.google.common.collect.TreeRangeSet, com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public final boolean contains(C c) {
return this.restriction.contains(c) && this.this$0.contains(c);
}
@Override // com.google.common.collect.TreeRangeSet, com.google.common.collect.AbstractRangeSet, com.google.common.collect.RangeSet
public final void clear() {
this.this$0.remove(this.restriction);
}
@Override // com.google.common.collect.TreeRangeSet, com.google.common.collect.RangeSet
public final RangeSet<C> subRangeSet(Range<C> range) {
if (range.encloses(this.restriction)) {
return this;
}
if (range.isConnected(this.restriction)) {
return new SubRangeSet(this, this.restriction.intersection(range));
}
return ImmutableRangeSet.of();
}
}
}