Union #

The Union class is a special data class that is used to enhance the expressiveness of the data model. Its purpose is not the instantiation of corresponding data objects, but the usage of several data objects with different data classes as possible attribute values. Such a union can be used in one attribute as in aggregates or as base class like in collections. For example, a set that should contain both, String and integer objects. This is only possible when using a union class, combining. It is not possible to instantiate this base class.

Defining a Union class #

In the following, it is presented how to use the UnionClass. First, an instantiable subclass of the union class needs to be created. There, it needs to be defined, which data classes can be used within this union class.

The class has to be defined in the model.xml file:

<UnionClass name="instantiableUnionClass">
  <ElementClass name="Integer"/>
  <ElementClass name="String"/>

To create this class in the code, the following java code must be used:

UnionClass unionClass = ModelFactory.getDefaultModel().getUnionSystemClass();
UnionClass instantiableUnionClass = (UnionClass) unionClass.createSubclass("instantiableUnionClass");

The usage of this union class within other data classes must be specified within these classes. For the example, described above, this can be performed in the model file as follows:

<SetClass name="customSetClass">
    <ElementClass name="instantiableUnionClass"/>

To perform this in the Java code, the following code must be used:

SetClass setClass = (SetClass) ModelFactory.getDefaultModel().getSetSystemClass();
SetClass customSetClass = (SetClass) setClass.createSubclass("customSetClass");

Now, an object of this set class can be created in the casebase. This can look as follows:

<cdol:C c="customSetClass" id="unionSetObject">
  <cdol:A c="Integer" v="1" id="unionIntegerObject"/>
  <cdol:A c="String" id="unionStringObject"/>

To create such an object in Java, the integer and String objects can be created as described here. Afterwards, the following code can be used:

SetObject setObject = (SetObject) ModelFactory.getDefaultModel().createObject("customSetClass");

When trying to add another object than the specified ones to the objects using the union class, an exception will be thrown.

Similarity calculation between union objects #

Depending on the object classes used, the similarity calculation between two objects based on union classes can be different. If objects of two same data classes are compared, e.g. integer with integer, the default defined similarity measures are used. If, on the other hand, a similarity calculation is performed between two different objects, such as a string with an integer, a similarity measure is searched for that can be used for the lowest common superclass. So far, only the standard measures ObjectEquals and TableDataClass are provided for this purpose.