Closed GoogleCodeExporter closed 9 years ago
This is 13.0.1
Original comment by lopez.ju...@gmail.com
on 21 Sep 2012 at 12:23
It sounds like you're thinking of this as "if two ranges contain the same sets
of elements in the discrete domain, they're equal". This just isn't the case,
though, and the methods (including equals and encloses) make that pretty clear
I think. Part of the reason for that is that a Range isn't aware of the
discrete domain. The two ranges in your example will behave differently for
certain operations, so they aren't equal.
ContiguousSet has the behavior that it sounds like you want. A ContiguousSet is
aware of the DiscreteDomain and as such knows exactly what elements in the
domain it contains. So the following should hold:
ContiguousSet.create(Range.closed(1L, 2L), DiscreteDomains.longs()).containsAll(
ContiguousSet.create(Range.open(1L, 3L), DiscreteDomains.longs())) == true
ContigousSet.create(Range.closed(a, b), domain).equals(
ContiguousSet.create(Range.closedOpen(a, c), domain)) == true
Original comment by cgdec...@gmail.com
on 21 Sep 2012 at 1:18
You had me worried that our docs don't cover this, but it looks like they do :)
Range.equals says:
"Returns true if object is a range having the same endpoints and bound types as
this range. Note that discrete ranges such as (1..4) and [2..3] are not equal
to one another, despite the fact that they each contain precisely the same set
of values. Similarly, empty ranges are not equal unless they have exactly the
same representation, so [3..3), (3..3], (4..4] are all unequal."
http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect
/Range.html#equals(java.lang.Object)
Is there anything else that it would be helpful to include?
Original comment by cpov...@google.com
on 21 Sep 2012 at 1:18
Original comment by cpov...@google.com
on 21 Sep 2012 at 1:19
Thanks. My bad.
Original comment by lopez.ju...@gmail.com
on 21 Sep 2012 at 1:23
Also, Range.canonical(DiscreteDomain) will convert Ranges.closed(a, b) and
Ranges.closedOpen(a, c) to the same output -- and those two *will* be equal
according to Range.equals().
Original comment by wasserman.louis
on 21 Sep 2012 at 2:22
I see. Interesting. Thanks, this is really helpful.
Original comment by lopez.ju...@gmail.com
on 21 Sep 2012 at 2:33
Yep. As you might guess, Range.canonical(DiscreteDomain) is what you use to
test if two ranges are "really" the same (in that domain), since a Range by
itself doesn't know anything about the domain.
Original comment by wasserman.louis
on 21 Sep 2012 at 2:39
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:13
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:08
Original issue reported on code.google.com by
lopez.ju...@gmail.com
on 21 Sep 2012 at 12:22