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: classes2.dex */ public final class Range extends RangeGwtSerializationDependencies implements Predicate, Serializable { private static final Range ALL = new Range<>(Cut.belowAll(), Cut.aboveAll()); private static final long serialVersionUID = 0; final Cut lowerBound; final Cut upperBound; /* loaded from: classes2.dex */ static class LowerBoundFn implements Function { static final LowerBoundFn INSTANCE = new LowerBoundFn(); LowerBoundFn() { } @Override // com.google.common.base.Function public Cut apply(Range range) { return range.lowerBound; } } /* loaded from: classes2.dex */ static class UpperBoundFn implements Function { static final UpperBoundFn INSTANCE = new UpperBoundFn(); UpperBoundFn() { } @Override // com.google.common.base.Function public Cut apply(Range range) { return range.upperBound; } } /* JADX INFO: Access modifiers changed from: package-private */ public static > Function, Cut> lowerBoundFn() { return LowerBoundFn.INSTANCE; } /* JADX INFO: Access modifiers changed from: package-private */ public static > Function, Cut> upperBoundFn() { return UpperBoundFn.INSTANCE; } /* JADX INFO: Access modifiers changed from: package-private */ public static > Ordering> rangeLexOrdering() { return (Ordering>) RangeLexOrdering.INSTANCE; } /* JADX INFO: Access modifiers changed from: package-private */ public static > Range create(Cut cut, Cut cut2) { return new Range<>(cut, cut2); } public static > Range open(C c, C c2) { return create(Cut.aboveValue(c), Cut.belowValue(c2)); } public static > Range closed(C c, C c2) { return create(Cut.belowValue(c), Cut.aboveValue(c2)); } public static > Range closedOpen(C c, C c2) { return create(Cut.belowValue(c), Cut.belowValue(c2)); } public static > Range openClosed(C c, C c2) { return create(Cut.aboveValue(c), Cut.aboveValue(c2)); } public static > Range range(C c, BoundType boundType, C c2, BoundType boundType2) { Preconditions.checkNotNull(boundType); Preconditions.checkNotNull(boundType2); return create(boundType == BoundType.OPEN ? Cut.aboveValue(c) : Cut.belowValue(c), boundType2 == BoundType.OPEN ? Cut.belowValue(c2) : Cut.aboveValue(c2)); } public static > Range lessThan(C c) { return create(Cut.belowAll(), Cut.belowValue(c)); } public static > Range atMost(C c) { return create(Cut.belowAll(), Cut.aboveValue(c)); } /* renamed from: com.google.common.collect.Range$1, reason: invalid class name */ /* loaded from: classes2.dex */ static /* synthetic */ class AnonymousClass1 { static final int[] $SwitchMap$com$google$common$collect$BoundType; static { int[] iArr = new int[BoundType.values().length]; $SwitchMap$com$google$common$collect$BoundType = iArr; try { iArr[BoundType.OPEN.ordinal()] = 1; } catch (NoSuchFieldError unused) { } try { $SwitchMap$com$google$common$collect$BoundType[BoundType.CLOSED.ordinal()] = 2; } catch (NoSuchFieldError unused2) { } } } public static > Range upTo(C c, BoundType boundType) { int i = AnonymousClass1.$SwitchMap$com$google$common$collect$BoundType[boundType.ordinal()]; if (i == 1) { return lessThan(c); } if (i == 2) { return atMost(c); } throw new AssertionError(); } public static > Range greaterThan(C c) { return create(Cut.aboveValue(c), Cut.aboveAll()); } public static > Range atLeast(C c) { return create(Cut.belowValue(c), Cut.aboveAll()); } public static > Range downTo(C c, BoundType boundType) { int i = AnonymousClass1.$SwitchMap$com$google$common$collect$BoundType[boundType.ordinal()]; if (i == 1) { return greaterThan(c); } if (i == 2) { return atLeast(c); } throw new AssertionError(); } public static > Range singleton(C c) { return closed(c, c); } public static > Range encloseAll(Iterable iterable) { Preconditions.checkNotNull(iterable); if (iterable instanceof SortedSet) { SortedSet cast = cast(iterable); Comparator comparator = cast.comparator(); if (Ordering.natural().equals(comparator) || comparator == null) { return closed((Comparable) cast.first(), (Comparable) cast.last()); } } Iterator it = iterable.iterator(); Comparable comparable = (Comparable) Preconditions.checkNotNull(it.next()); Comparable comparable2 = comparable; while (it.hasNext()) { Comparable comparable3 = (Comparable) Preconditions.checkNotNull(it.next()); comparable = (Comparable) Ordering.natural().min(comparable, comparable3); comparable2 = (Comparable) Ordering.natural().max(comparable2, comparable3); } return closed(comparable, comparable2); } private Range(Cut cut, Cut cut2) { this.lowerBound = (Cut) Preconditions.checkNotNull(cut); this.upperBound = (Cut) Preconditions.checkNotNull(cut2); if (cut.compareTo((Cut) cut2) > 0 || cut == Cut.aboveAll() || cut2 == Cut.belowAll()) { String valueOf = String.valueOf(toString(cut, cut2)); throw new IllegalArgumentException(valueOf.length() != 0 ? "Invalid range: ".concat(valueOf) : new String("Invalid range: ")); } } public final boolean hasLowerBound() { return this.lowerBound != Cut.belowAll(); } public final C lowerEndpoint() { return this.lowerBound.endpoint(); } public final BoundType lowerBoundType() { return this.lowerBound.typeAsLowerBound(); } public final boolean hasUpperBound() { return this.upperBound != Cut.aboveAll(); } public final C upperEndpoint() { return this.upperBound.endpoint(); } public final BoundType upperBoundType() { return this.upperBound.typeAsUpperBound(); } public final boolean isEmpty() { return this.lowerBound.equals(this.upperBound); } public final boolean contains(C c) { Preconditions.checkNotNull(c); return this.lowerBound.isLessThan(c) && !this.upperBound.isLessThan(c); } @Override // com.google.common.base.Predicate @Deprecated public final boolean apply(C c) { return contains(c); } /* JADX WARN: Multi-variable type inference failed */ public final boolean containsAll(Iterable iterable) { if (Iterables.isEmpty(iterable)) { return true; } if (iterable instanceof SortedSet) { SortedSet cast = cast(iterable); Comparator comparator = cast.comparator(); if (Ordering.natural().equals(comparator) || comparator == null) { return contains((Comparable) cast.first()) && contains((Comparable) cast.last()); } } Iterator it = iterable.iterator(); while (it.hasNext()) { if (!contains(it.next())) { return false; } } return true; } public final boolean encloses(Range range) { return this.lowerBound.compareTo((Cut) range.lowerBound) <= 0 && this.upperBound.compareTo((Cut) range.upperBound) >= 0; } public final boolean isConnected(Range range) { return this.lowerBound.compareTo((Cut) range.upperBound) <= 0 && range.lowerBound.compareTo((Cut) this.upperBound) <= 0; } public final Range intersection(Range 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 final Range gap(Range range) { if (this.lowerBound.compareTo((Cut) range.upperBound) < 0 && range.lowerBound.compareTo((Cut) this.upperBound) < 0) { String valueOf = String.valueOf(this); String valueOf2 = String.valueOf(range); StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 39 + String.valueOf(valueOf2).length()); sb.append("Ranges have a nonempty intersection: "); sb.append(valueOf); sb.append(", "); sb.append(valueOf2); throw new IllegalArgumentException(sb.toString()); } boolean z = this.lowerBound.compareTo((Cut) range.lowerBound) < 0; Range range2 = z ? this : range; if (!z) { range = this; } return create(range2.upperBound, range.lowerBound); } public final Range span(Range 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 final Range canonical(DiscreteDomain discreteDomain) { Preconditions.checkNotNull(discreteDomain); Cut canonical = this.lowerBound.canonical(discreteDomain); Cut canonical2 = this.upperBound.canonical(discreteDomain); return (canonical == this.lowerBound && canonical2 == this.upperBound) ? this : create(canonical, canonical2); } @Override // com.google.common.base.Predicate public final 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 final int hashCode() { return (this.lowerBound.hashCode() * 31) + this.upperBound.hashCode(); } public final String toString() { return toString(this.lowerBound, this.upperBound); } private static String toString(Cut cut, Cut cut2) { StringBuilder sb = new StringBuilder(16); cut.describeAsLowerBound(sb); sb.append(".."); cut2.describeAsUpperBound(sb); return sb.toString(); } private static SortedSet cast(Iterable iterable) { return (SortedSet) iterable; } final Object readResolve() { return equals(ALL) ? all() : this; } /* JADX INFO: Access modifiers changed from: package-private */ public static int compareOrThrow(Comparable comparable, Comparable comparable2) { return comparable.compareTo(comparable2); } /* loaded from: classes2.dex */ static class RangeLexOrdering extends Ordering> implements Serializable { static final Ordering> INSTANCE = new RangeLexOrdering(); private static final long serialVersionUID = 0; private RangeLexOrdering() { } @Override // com.google.common.collect.Ordering, java.util.Comparator public int compare(Range range, Range range2) { return ComparisonChain.start().compare(range.lowerBound, range2.lowerBound).compare(range.upperBound, range2.upperBound).result(); } } public static > Range all() { return (Range) ALL; } }