yangxu998 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Finding the relationship between two ranges #654

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Could you please add methods to check if 2 ranges intersect or are continuous? 
The current methods provide no convenient way to perform these checks.

intersects would look like this:
public boolean intersects(Range<C> other) {
  Cut<C> intersectionLower = Ordering.natural().max(lowerBound, other.lowerBound);
  Cut<C> intersectionUpper = Ordering.natural().min(upperBound, other.upperBound);
  return intersectionLower.compareTo(intersectionUpper) <= 0;
}

isContinuous would look like this:
public boolean isContinuous(Range<C> other) {
  return upperBound.equals(other.lowerBound);
}

Original issue reported on code.google.com by emond.pa...@gmail.com on 8 Jul 2011 at 1:48

GoogleCodeExporter commented 9 years ago
It turns out there are at least, like, 11 different relationships two ranges 
can have, and we're thinking about how to properly address the important ones.  
I will try to paste more detail when we get closer to actually working on it.

Original comment by kevinb@google.com on 13 Jul 2011 at 6:27

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 13 Jul 2011 at 7:00

GoogleCodeExporter commented 9 years ago
Does 
http://docs.guava-libraries.googlecode.com/git-history/v10.0/javadoc/com/google/
common/collect/Range.html#isConnected(com.google.common.collect.Range) do what 
you need?

Original comment by wasserman.louis on 29 Sep 2011 at 10:07

GoogleCodeExporter commented 9 years ago
Yes, that does what we need. Thanks!

Original comment by emond.pa...@gmail.com on 30 Sep 2011 at 6:22

GoogleCodeExporter commented 9 years ago
Do we want to keep this issue open in case people need other range relationship 
tests?

Original comment by wasserman.louis on 10 Oct 2011 at 2:38

GoogleCodeExporter commented 9 years ago
Marking as fixed.

Original comment by wasserman.louis on 16 Oct 2011 at 11:39

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09