diff options
Diffstat (limited to 'android/guava/src/com/google/common/collect/Range.java')
-rw-r--r-- | android/guava/src/com/google/common/collect/Range.java | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/android/guava/src/com/google/common/collect/Range.java b/android/guava/src/com/google/common/collect/Range.java index 2f7e88dc6..5300b772c 100644 --- a/android/guava/src/com/google/common/collect/Range.java +++ b/android/guava/src/com/google/common/collect/Range.java @@ -91,6 +91,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableDecl; * <h3>Other notes</h3> * * <ul> + * <li>All ranges are shallow-immutable. * <li>Instances of this type are obtained using the static factory methods in this class. * <li>Ranges are <i>convex</i>: whenever two values are contained, all values in between them * must also be contained. More formally, for any {@code c1 <= c2 <= c3} of type {@code C}, @@ -576,6 +577,22 @@ public final class Range<C extends Comparable> extends RangeGwtSerializationDepe * @since 27.0 */ public Range<C> gap(Range<C> otherRange) { + /* + * For an explanation of the basic principle behind this check, see + * https://stackoverflow.com/a/35754308/28465 + * + * In that explanation's notation, our `overlap` check would be `x1 < y2 && y1 < x2`. We've + * flipped one part of the check so that we're using "less than" in both cases (rather than a + * mix of "less than" and "greater than"). We've also switched to "strictly less than" rather + * than "less than or equal to" because of *handwave* the difference between "endpoints of + * inclusive ranges" and "Cuts." + */ + if (lowerBound.compareTo(otherRange.upperBound) < 0 + && otherRange.lowerBound.compareTo(upperBound) < 0) { + throw new IllegalArgumentException( + "Ranges have a nonempty intersection: " + this + ", " + otherRange); + } + boolean isThisFirst = this.lowerBound.compareTo(otherRange.lowerBound) < 0; Range<C> firstRange = isThisFirst ? this : otherRange; Range<C> secondRange = isThisFirst ? otherRange : this; |