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

259 lines
11 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.Preconditions;
import java.io.Serializable;
import java.lang.Comparable;
import java.util.Collection;
import java.util.Iterator;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public final class RegularContiguousSet<C extends Comparable> extends ContiguousSet<C> {
private static final long serialVersionUID = 0;
private final Range<C> range;
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public final boolean isEmpty() {
return false;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.ImmutableCollection
public final boolean isPartialView() {
return false;
}
@Override // com.google.common.collect.ImmutableSortedSet, java.util.NavigableSet
public final /* bridge */ /* synthetic */ Iterator descendingIterator() {
return descendingIterator();
}
@Override // com.google.common.collect.ImmutableSortedSet, com.google.common.collect.ImmutableSet, com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set, java.util.NavigableSet, com.google.common.collect.SortedIterable
public final /* bridge */ /* synthetic */ Iterator iterator() {
return iterator();
}
/* JADX INFO: Access modifiers changed from: package-private */
public RegularContiguousSet(Range<C> range, DiscreteDomain<C> discreteDomain) {
super(discreteDomain);
this.range = range;
}
private ContiguousSet<C> intersectionInCurrentDomain(Range<C> range) {
if (this.range.isConnected(range)) {
return ContiguousSet.create(this.range.intersection(range), this.domain);
}
return new EmptyContiguousSet(this.domain);
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.ContiguousSet, com.google.common.collect.ImmutableSortedSet
public final ContiguousSet<C> headSetImpl(C c, boolean z) {
return intersectionInCurrentDomain(Range.upTo(c, BoundType.forBoolean(z)));
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.ContiguousSet, com.google.common.collect.ImmutableSortedSet
public final ContiguousSet<C> subSetImpl(C c, boolean z, C c2, boolean z2) {
if (c.compareTo(c2) == 0 && !z && !z2) {
return new EmptyContiguousSet(this.domain);
}
return intersectionInCurrentDomain(Range.range(c, BoundType.forBoolean(z), c2, BoundType.forBoolean(z2)));
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.ContiguousSet, com.google.common.collect.ImmutableSortedSet
public final ContiguousSet<C> tailSetImpl(C c, boolean z) {
return intersectionInCurrentDomain(Range.downTo(c, BoundType.forBoolean(z)));
}
/* JADX INFO: Access modifiers changed from: package-private */
/* JADX WARN: Multi-variable type inference failed */
@Override // com.google.common.collect.ImmutableSortedSet
public final int indexOf(Object obj) {
if (contains(obj)) {
return (int) this.domain.distance(first(), (Comparable) obj);
}
return -1;
}
@Override // com.google.common.collect.ImmutableSortedSet, com.google.common.collect.ImmutableSet, com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set, java.util.NavigableSet, com.google.common.collect.SortedIterable
public final UnmodifiableIterator<C> iterator() {
return new AbstractSequentialIterator<C>(this, first()) { // from class: com.google.common.collect.RegularContiguousSet.1
final C last;
final RegularContiguousSet this$0;
{
this.this$0 = this;
this.last = (C) this.last();
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.collect.AbstractSequentialIterator
public C computeNext(C c) {
if (RegularContiguousSet.equalsOrThrow(c, this.last)) {
return null;
}
return this.this$0.domain.next(c);
}
};
}
@Override // com.google.common.collect.ImmutableSortedSet, java.util.NavigableSet
public final UnmodifiableIterator<C> descendingIterator() {
return new AbstractSequentialIterator<C>(this, last()) { // from class: com.google.common.collect.RegularContiguousSet.2
final C first;
final RegularContiguousSet this$0;
{
this.this$0 = this;
this.first = (C) this.first();
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.collect.AbstractSequentialIterator
public C computeNext(C c) {
if (RegularContiguousSet.equalsOrThrow(c, this.first)) {
return null;
}
return this.this$0.domain.previous(c);
}
};
}
/* JADX INFO: Access modifiers changed from: private */
public static boolean equalsOrThrow(Comparable<?> comparable, Comparable<?> comparable2) {
return comparable2 != null && Range.compareOrThrow(comparable, comparable2) == 0;
}
@Override // com.google.common.collect.ImmutableSortedSet, java.util.SortedSet
public final C first() {
return this.range.lowerBound.leastValueAbove(this.domain);
}
@Override // com.google.common.collect.ImmutableSortedSet, java.util.SortedSet
public final C last() {
return this.range.upperBound.greatestValueBelow(this.domain);
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.ImmutableSet
public final ImmutableList<C> createAsList() {
if (this.domain.supportsFastOffset) {
return new ImmutableAsList<C>(this) { // from class: com.google.common.collect.RegularContiguousSet.3
final RegularContiguousSet this$0;
{
this.this$0 = this;
}
/* JADX WARN: Multi-variable type inference failed */
@Override // java.util.List
public C get(int i) {
Preconditions.checkElementIndex(i, size());
return (C) this.this$0.domain.offset(this.this$0.first(), i);
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.ImmutableAsList
public ImmutableSortedSet<C> delegateCollection() {
return this.this$0;
}
};
}
return super.createAsList();
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public final int size() {
long distance = this.domain.distance(first(), last());
if (distance >= 2147483647L) {
return Integer.MAX_VALUE;
}
return ((int) distance) + 1;
}
/* JADX WARN: Multi-variable type inference failed */
@Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.util.Set
public final boolean contains(Object obj) {
if (obj == null) {
return false;
}
try {
return this.range.contains((Comparable) obj);
} catch (ClassCastException unused) {
return false;
}
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public final boolean containsAll(Collection<?> collection) {
return Collections2.containsAllImpl(this, collection);
}
@Override // com.google.common.collect.ContiguousSet
public final ContiguousSet<C> intersection(ContiguousSet<C> contiguousSet) {
Preconditions.checkNotNull(contiguousSet);
Preconditions.checkArgument(this.domain.equals(contiguousSet.domain));
if (contiguousSet.isEmpty()) {
return contiguousSet;
}
Comparable comparable = (Comparable) Ordering.natural().max(first(), contiguousSet.first());
Comparable comparable2 = (Comparable) Ordering.natural().min(last(), contiguousSet.last());
if (comparable.compareTo(comparable2) <= 0) {
return ContiguousSet.create(Range.closed(comparable, comparable2), this.domain);
}
return new EmptyContiguousSet(this.domain);
}
@Override // com.google.common.collect.ContiguousSet
public final Range<C> range() {
BoundType boundType = BoundType.CLOSED;
return range(boundType, boundType);
}
@Override // com.google.common.collect.ContiguousSet
public final Range<C> range(BoundType boundType, BoundType boundType2) {
return Range.create(this.range.lowerBound.withLowerBoundType(boundType, this.domain), this.range.upperBound.withUpperBoundType(boundType2, this.domain));
}
@Override // com.google.common.collect.ImmutableSet, java.util.Collection, java.util.Set
public final boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof RegularContiguousSet) {
RegularContiguousSet regularContiguousSet = (RegularContiguousSet) obj;
if (this.domain.equals(regularContiguousSet.domain)) {
return first().equals(regularContiguousSet.first()) && last().equals(regularContiguousSet.last());
}
}
return super.equals(obj);
}
@Override // com.google.common.collect.ImmutableSet, java.util.Collection, java.util.Set
public final int hashCode() {
return Sets.hashCodeImpl(this);
}
/* loaded from: classes2.dex */
static final class SerializedForm<C extends Comparable> implements Serializable {
final DiscreteDomain<C> domain;
final Range<C> range;
private SerializedForm(Range<C> range, DiscreteDomain<C> discreteDomain) {
this.range = range;
this.domain = discreteDomain;
}
private Object readResolve() {
return new RegularContiguousSet(this.range, this.domain);
}
}
@Override // com.google.common.collect.ImmutableSortedSet, com.google.common.collect.ImmutableSet, com.google.common.collect.ImmutableCollection
final Object writeReplace() {
return new SerializedForm(this.range, this.domain);
}
}