Guava: Support building `ImmutableRangeSet`s using overlapping ranges

Created on 16 Jan 2018  路  2Comments  路  Source: google/guava

In the ImmutableRangeSet.Builder source code we have this comment:

https://github.com/google/guava/blob/ce73003d8420a091fd36ca2c7c23deb6437e4fe1/guava/src/com/google/common/collect/ImmutableRangeSet.java#L725

That sounds like a neat improvement onto itself. But the ImmutableRangeSet collector introduced in #2750 is also defined in terms of ImmutableRangeSet.Builder:

https://github.com/google/guava/blob/ce73003d8420a091fd36ca2c7c23deb6437e4fe1/guava/src/com/google/common/collect/CollectCollectors.java#L106-L113

So as it stands one can only use toImmutableRangeSet() to collect a stream of non-overlapping ranges; otherwise an IllegalArgumentException is thrown. This is somewhat unintuitive from an API point of view. Maybe the introduction of the collector increases the utility of the builder sufficiently to justify spending time on adding support for overlapping ranges?

P3 package=collect status=research type=enhancement

Most helpful comment

If I understand right, we have at least two separate questions:

  1. Should the collector be based on add or union?
  2. Should the builder expose a union method?

All 2 comments

If I understand right, we have at least two separate questions:

  1. Should the collector be based on add or union?
  2. Should the builder expose a union method?

@kevinb9n exactly! I guess I should have summarized this more clearly myself.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

epkugelmass picture epkugelmass  路  4Comments

philgebhardt picture philgebhardt  路  3Comments

thecoop picture thecoop  路  4Comments

oliviercailloux picture oliviercailloux  路  4Comments

gissuebot picture gissuebot  路  5Comments