312 lines
10 KiB
Java
312 lines
10 KiB
Java
package com.google.common.collect;
|
|
|
|
import com.google.common.base.Function;
|
|
import com.google.common.base.Preconditions;
|
|
import com.google.common.base.Predicate;
|
|
import java.io.Serializable;
|
|
import java.lang.Comparable;
|
|
import java.util.Comparator;
|
|
import java.util.Iterator;
|
|
import java.util.SortedSet;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class Range<C extends Comparable> extends RangeGwtSerializationDependencies implements Predicate<C>, Serializable {
|
|
private static final long serialVersionUID = 0;
|
|
final Cut<C> lowerBound;
|
|
final Cut<C> upperBound;
|
|
private static final Function<Range, Cut> LOWER_BOUND_FN = new Function<Range, Cut>() { // from class: com.google.common.collect.Range.1
|
|
@Override // com.google.common.base.Function
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public Cut apply(Range range) {
|
|
return range.lowerBound;
|
|
}
|
|
};
|
|
private static final Function<Range, Cut> UPPER_BOUND_FN = new Function<Range, Cut>() { // from class: com.google.common.collect.Range.2
|
|
@Override // com.google.common.base.Function
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public Cut apply(Range range) {
|
|
return range.upperBound;
|
|
}
|
|
};
|
|
private static final Range<Comparable> ALL = new Range<>(Cut.g(), Cut.f());
|
|
|
|
/* renamed from: com.google.common.collect.Range$3, reason: invalid class name */
|
|
static /* synthetic */ class AnonymousClass3 {
|
|
static final /* synthetic */ int[] a = new int[BoundType.values().length];
|
|
|
|
static {
|
|
try {
|
|
a[BoundType.OPEN.ordinal()] = 1;
|
|
} catch (NoSuchFieldError unused) {
|
|
}
|
|
try {
|
|
a[BoundType.CLOSED.ordinal()] = 2;
|
|
} catch (NoSuchFieldError unused2) {
|
|
}
|
|
}
|
|
}
|
|
|
|
private static class RangeLexOrdering extends Ordering<Range<?>> implements Serializable {
|
|
static final Ordering<Range<?>> a = new RangeLexOrdering();
|
|
|
|
private RangeLexOrdering() {
|
|
}
|
|
|
|
@Override // com.google.common.collect.Ordering, java.util.Comparator
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public int compare(Range<?> range, Range<?> range2) {
|
|
return ComparisonChain.e().a(range.lowerBound, range2.lowerBound).a(range.upperBound, range2.upperBound).a();
|
|
}
|
|
}
|
|
|
|
private Range(Cut<C> cut, Cut<C> cut2) {
|
|
Preconditions.a(cut);
|
|
this.lowerBound = cut;
|
|
Preconditions.a(cut2);
|
|
this.upperBound = cut2;
|
|
if (cut.compareTo((Cut) cut2) > 0 || cut == Cut.f() || cut2 == Cut.g()) {
|
|
throw new IllegalArgumentException("Invalid range: " + toString(cut, cut2));
|
|
}
|
|
}
|
|
|
|
public static <C extends Comparable<?>> Range<C> all() {
|
|
return (Range<C>) ALL;
|
|
}
|
|
|
|
public static <C extends Comparable<?>> Range<C> atLeast(C c) {
|
|
return create(Cut.c(c), Cut.f());
|
|
}
|
|
|
|
public static <C extends Comparable<?>> Range<C> atMost(C c) {
|
|
return create(Cut.g(), Cut.b(c));
|
|
}
|
|
|
|
private static <T> SortedSet<T> cast(Iterable<T> iterable) {
|
|
return (SortedSet) iterable;
|
|
}
|
|
|
|
public static <C extends Comparable<?>> Range<C> closed(C c, C c2) {
|
|
return create(Cut.c(c), Cut.b(c2));
|
|
}
|
|
|
|
public static <C extends Comparable<?>> Range<C> closedOpen(C c, C c2) {
|
|
return create(Cut.c(c), Cut.c(c2));
|
|
}
|
|
|
|
static int compareOrThrow(Comparable comparable, Comparable comparable2) {
|
|
return comparable.compareTo(comparable2);
|
|
}
|
|
|
|
static <C extends Comparable<?>> Range<C> create(Cut<C> cut, Cut<C> cut2) {
|
|
return new Range<>(cut, cut2);
|
|
}
|
|
|
|
public static <C extends Comparable<?>> Range<C> downTo(C c, BoundType boundType) {
|
|
int i = AnonymousClass3.a[boundType.ordinal()];
|
|
if (i == 1) {
|
|
return greaterThan(c);
|
|
}
|
|
if (i == 2) {
|
|
return atLeast(c);
|
|
}
|
|
throw new AssertionError();
|
|
}
|
|
|
|
public static <C extends Comparable<?>> Range<C> encloseAll(Iterable<C> iterable) {
|
|
Preconditions.a(iterable);
|
|
if (iterable instanceof ContiguousSet) {
|
|
return ((ContiguousSet) iterable).range();
|
|
}
|
|
Iterator<C> it = iterable.iterator();
|
|
C next = it.next();
|
|
Preconditions.a(next);
|
|
C c = next;
|
|
Comparable comparable = c;
|
|
while (it.hasNext()) {
|
|
C next2 = it.next();
|
|
Preconditions.a(next2);
|
|
C c2 = next2;
|
|
c = (Comparable) Ordering.c().b(c, c2);
|
|
comparable = (Comparable) Ordering.c().a(comparable, c2);
|
|
}
|
|
return closed(c, comparable);
|
|
}
|
|
|
|
public static <C extends Comparable<?>> Range<C> greaterThan(C c) {
|
|
return create(Cut.b(c), Cut.f());
|
|
}
|
|
|
|
public static <C extends Comparable<?>> Range<C> lessThan(C c) {
|
|
return create(Cut.g(), Cut.c(c));
|
|
}
|
|
|
|
static <C extends Comparable<?>> Function<Range<C>, Cut<C>> lowerBoundFn() {
|
|
return LOWER_BOUND_FN;
|
|
}
|
|
|
|
public static <C extends Comparable<?>> Range<C> open(C c, C c2) {
|
|
return create(Cut.b(c), Cut.c(c2));
|
|
}
|
|
|
|
public static <C extends Comparable<?>> Range<C> openClosed(C c, C c2) {
|
|
return create(Cut.b(c), Cut.b(c2));
|
|
}
|
|
|
|
public static <C extends Comparable<?>> Range<C> range(C c, BoundType boundType, C c2, BoundType boundType2) {
|
|
Preconditions.a(boundType);
|
|
Preconditions.a(boundType2);
|
|
return create(boundType == BoundType.OPEN ? Cut.b(c) : Cut.c(c), boundType2 == BoundType.OPEN ? Cut.c(c2) : Cut.b(c2));
|
|
}
|
|
|
|
static <C extends Comparable<?>> Ordering<Range<C>> rangeLexOrdering() {
|
|
return (Ordering<Range<C>>) RangeLexOrdering.a;
|
|
}
|
|
|
|
public static <C extends Comparable<?>> Range<C> singleton(C c) {
|
|
return closed(c, c);
|
|
}
|
|
|
|
public static <C extends Comparable<?>> Range<C> upTo(C c, BoundType boundType) {
|
|
int i = AnonymousClass3.a[boundType.ordinal()];
|
|
if (i == 1) {
|
|
return lessThan(c);
|
|
}
|
|
if (i == 2) {
|
|
return atMost(c);
|
|
}
|
|
throw new AssertionError();
|
|
}
|
|
|
|
static <C extends Comparable<?>> Function<Range<C>, Cut<C>> upperBoundFn() {
|
|
return UPPER_BOUND_FN;
|
|
}
|
|
|
|
public Range<C> canonical(DiscreteDomain<C> discreteDomain) {
|
|
Preconditions.a(discreteDomain);
|
|
Cut<C> a = this.lowerBound.a(discreteDomain);
|
|
Cut<C> a2 = this.upperBound.a(discreteDomain);
|
|
return (a == this.lowerBound && a2 == this.upperBound) ? this : create(a, a2);
|
|
}
|
|
|
|
public boolean contains(C c) {
|
|
Preconditions.a(c);
|
|
return this.lowerBound.a((Cut<C>) c) && !this.upperBound.a((Cut<C>) c);
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public boolean containsAll(Iterable<? extends C> iterable) {
|
|
if (Iterables.d(iterable)) {
|
|
return true;
|
|
}
|
|
if (iterable instanceof SortedSet) {
|
|
SortedSet cast = cast(iterable);
|
|
Comparator comparator = cast.comparator();
|
|
if (Ordering.c().equals(comparator) || comparator == null) {
|
|
return contains((Comparable) cast.first()) && contains((Comparable) cast.last());
|
|
}
|
|
}
|
|
Iterator<? extends C> it = iterable.iterator();
|
|
while (it.hasNext()) {
|
|
if (!contains(it.next())) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public boolean encloses(Range<C> range) {
|
|
return this.lowerBound.compareTo((Cut) range.lowerBound) <= 0 && this.upperBound.compareTo((Cut) range.upperBound) >= 0;
|
|
}
|
|
|
|
@Override // com.google.common.base.Predicate
|
|
public boolean equals(Object obj) {
|
|
if (!(obj instanceof Range)) {
|
|
return false;
|
|
}
|
|
Range range = (Range) obj;
|
|
return this.lowerBound.equals(range.lowerBound) && this.upperBound.equals(range.upperBound);
|
|
}
|
|
|
|
public boolean hasLowerBound() {
|
|
return this.lowerBound != Cut.g();
|
|
}
|
|
|
|
public boolean hasUpperBound() {
|
|
return this.upperBound != Cut.f();
|
|
}
|
|
|
|
public int hashCode() {
|
|
return (this.lowerBound.hashCode() * 31) + this.upperBound.hashCode();
|
|
}
|
|
|
|
public Range<C> intersection(Range<C> range) {
|
|
int compareTo = this.lowerBound.compareTo((Cut) range.lowerBound);
|
|
int compareTo2 = this.upperBound.compareTo((Cut) range.upperBound);
|
|
if (compareTo >= 0 && compareTo2 <= 0) {
|
|
return this;
|
|
}
|
|
if (compareTo > 0 || compareTo2 < 0) {
|
|
return create(compareTo >= 0 ? this.lowerBound : range.lowerBound, compareTo2 <= 0 ? this.upperBound : range.upperBound);
|
|
}
|
|
return range;
|
|
}
|
|
|
|
public boolean isConnected(Range<C> range) {
|
|
return this.lowerBound.compareTo((Cut) range.upperBound) <= 0 && range.lowerBound.compareTo((Cut) this.upperBound) <= 0;
|
|
}
|
|
|
|
public boolean isEmpty() {
|
|
return this.lowerBound.equals(this.upperBound);
|
|
}
|
|
|
|
public BoundType lowerBoundType() {
|
|
return this.lowerBound.d();
|
|
}
|
|
|
|
public C lowerEndpoint() {
|
|
return this.lowerBound.c();
|
|
}
|
|
|
|
Object readResolve() {
|
|
return equals(ALL) ? all() : this;
|
|
}
|
|
|
|
public Range<C> span(Range<C> range) {
|
|
int compareTo = this.lowerBound.compareTo((Cut) range.lowerBound);
|
|
int compareTo2 = this.upperBound.compareTo((Cut) range.upperBound);
|
|
if (compareTo <= 0 && compareTo2 >= 0) {
|
|
return this;
|
|
}
|
|
if (compareTo < 0 || compareTo2 > 0) {
|
|
return create(compareTo <= 0 ? this.lowerBound : range.lowerBound, compareTo2 >= 0 ? this.upperBound : range.upperBound);
|
|
}
|
|
return range;
|
|
}
|
|
|
|
public String toString() {
|
|
return toString(this.lowerBound, this.upperBound);
|
|
}
|
|
|
|
public BoundType upperBoundType() {
|
|
return this.upperBound.e();
|
|
}
|
|
|
|
public C upperEndpoint() {
|
|
return this.upperBound.c();
|
|
}
|
|
|
|
private static String toString(Cut<?> cut, Cut<?> cut2) {
|
|
StringBuilder sb = new StringBuilder(16);
|
|
cut.a(sb);
|
|
sb.append("..");
|
|
cut2.b(sb);
|
|
return sb.toString();
|
|
}
|
|
|
|
@Override // com.google.common.base.Predicate
|
|
@Deprecated
|
|
public boolean apply(C c) {
|
|
return contains(c);
|
|
}
|
|
}
|