3 ms·
An alternative approach is Guava's Range class: Range.closed(1,5) == [1,5] Range.open(1,5) == (1,5) Range.openClosed(1,5) == (1,5] Range.closedOpe
by tomfitz 9y ago
An alternative approach is Guava's Range class:
Range.closed(1,5) == [1,5]
Range.open(1,5) == (1,5)
Range.openClosed(1,5) == (1,5]
Range.closedOpen(1,5) == [1,5)
Range.greaterThan(1) == (1,infinity)
Range.atLeast(1) == [1,infinity)
That class always strikes me as having high power-to-weight. It has methods like encloses(anotherRange), contains(aValue), and others.
https://google.github.io/guava/releases/19.0/api/docs/com/google/common/collect/Range.html https://google.github.io/guava/releases/19.0/api/docs/com/go...
- saghm 9y agoShould the second "closed" be "closed Open" (with the corresponding change to the rest of the line)?
- tomfitz 9y agoFixed, thanks.
- derefr 9y agoWhat does a Guava two-Integer-element array literal look like?
- tomfitz 9y agoSorry, I didn't explain myself well. Range.closed(1,5) is the syntax used to refer to what a mathematician would call [1,5]. Guava is just a Java library. In Java 9, a two-Integer-element list literal will be List.of(9000, 9001).
- nathan_f77 9y agoToo verbose for me. I always prefer short syntactic sugar.