如何从 Guava 范围 class 中获取正确的字符串

How to get proper string from Guava range class

例如,我执行以下操作:

RangeSet<Long> rangeSet = TreeRangeSet.create();;
rangeSet.add(Range.closed(20L,29L).canonical(DiscreteDomain.longs())); 
rangeSet.add(Range.closed(10L,19L).canonical(DiscreteDomain.longs()));
rangeSet.add(Range.closed(50L,59L).canonical(DiscreteDomain.longs()));
System.out.println(rangeSet);

我得到以下输出:

[[0‥30), [50‥60)]

正如我所见,30 不在范围内,因为它已关闭打开,60 不在范围内,因为它也已关闭打开。

如何从范围 class 中获取以下字符串?

[0‥30) contains numbers from 0 to 29
[50‥60) contains numbers from 50 to 59
ContiguousSet<Long> set =
    ContiguousSet.create(range, DiscreteDomain.longs());

那你就可以使用

set.first()

set.last()

获取您想要的值。