Interval

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 for data classes with totally ordered instances. How to create such an Atomic class 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"/>
</IntervalClass>

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

IntervalClass intervalClass = (IntervalClass) ModelFactory.getDefaultModel().getClass(IntervalClass.CLASS_NAME);
IntervalClass costumIntervalClass = (IntervalClass) intervalClass.createSubclass("customIntervalClass");
costumIntervalClass.setElementClass(ModelFactory.getDefaultModel().getClass("customIntegerIntervalClass"));
intervalClass.finishEditing();

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.

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

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