Interval #

An Interval class is used to create data objects that specify a range of values. Therefore, a base data class must be specified to define the type of the elements. Intervals can be only defined the numeric and chronological data classes as well for string classes with a total order predicate. How to create an interval predicate class for numeric or chronological classes is described here.

After the definition of a custom lower and upper bounded atomic class, it is possible to define a custom Interval class using that custom atomic class. This can be done in the model.xml file like shown below:


    <IntervalClass name="customIntervalClass">
        <ElementClass name="customIntegerIntervalClass"/>

To create this class during runtime, the following java code has to be used:

    IntervalClass intervalClass = (IntervalClass) ModelFactory.getDefaultModel().getIntervalSystemClass();
    IntervalClass customIntervalClass = (IntervalClass) intervalClass.createSubclass("customIntervalClass");
Please consider that the definition of the Atomic class, here customIntegerIntervalClass, has to be made before the Interval class is created. Otherwise, an exception would be thrown. In addition, it should be noted that for an interval class using the setAbstract(false) method call, the class must be set to non-abstract. Otherwise, it cannot be instantiated.

To create an object of this example class, the following java code has to be used:

    IntervalObject intervalObject = (IntervalObject) ModelFactory.getDefaultModel().createObject("customIntervalClass");

    IntegerObject lowerBound = (IntegerObject) ModelFactory.getDefaultModel().getClass("customIntegerIntervalClass").newObject();
    IntegerObject upperBound = (IntegerObject) ModelFactory.getDefaultModel().getClass("customIntegerIntervalClass").newObject();

    intervalObject.setBounds(lowerBound, upperBound);

The XML representation of the interval object depicted above is as follows:


    <cdol:Int c="customIntervalClass" id="testInterval">
        <cdol:LowerBound v="50" c="customIntegerIntervalClass"/>
        <cdol:UpperBound v="100" c="customIntegerIntervalClass"/>

The use of intervals on string classes with a total order predicate is analogous. For example, the XML definition is:


    <IntervalClass name="WeekdaysInterval">
        <ElementClass name="Weekdays"/>

However, it is not necessary to create explicit instance interval predicates here. The example refers to the total order Weekdays used in the wiki.