Recipe 0.0. Creating a domain of definition
Problem
You want to create a new domain of definition for any type.
Definitions
A domain of definition corresponds to the set of all permitted values (the range) of a specific object type.
Solution
In the JPL, each domain of definition has to implement the interface DomainOfDefinition:
// the domain of definition of all odd integers public class OddIntegerDoD implements private DomainOfDefinition<Integer> { public static OddIntegerDoD newInstance() { return new OddIntegerDoD(); } public boolean contains(Integer t) { return t % 2 == 1; } } // a new instance OddIntegerDoD dod = OddIntegerDoD.newInstance(); Assert.assertTrue(dod.contains(3));
Discussion
Domains of definitions may be integrated in Condition as new object to be tested with its specific operator OperatorBelongsToDoD.
See Also
See also the recipe about the simple domain of definition interval and about conditions.