Recipe 0.1. Creating Interval
Problem
You want to create an interval of numbers.
Definitions
Here lie some definitions for interval:
An interval is a set of reals with the property that any number that lies between two numbers is included in the set.
An interval is said to be opened ("[]"), closed ("][")or semi-opened ("[[" or "]]") depending on the possible inclusion of bounds. For example, the set of all numbers x satisfying 0 ≤ x < 1 is a semi-opened interval [0, 1[ which contains 0 and not 1, as well as all numbers between them.
In the JPL, all intervals by default are semi-opened.
Solution
Here is a code that build a default interval:
// default interval: [a, b[ Interval interval = new Interval.Builder(245.56, 310).build(); Assert.assertTrue(interval.contains(263));
It is also possible to include or exclude boundaries:
// interval: ]a, b] Interval interval = new Interval.Builder(0, 10) .excludeLowerBound().includeUpperBound().build(); Assert.assertFalse(interval.contains(0));
Discussion
See Also
See also the recipe about creating domain of definition.