Casting multiple-cardinality elements to single-cardinality elements
You can use the asSingle method to cast multiple-cardinality elements to single-cardinality elements.
To cast a multiple-cardinality element to a single-cardinality element, you must use the asSingle method because there is no method in the BOM that compares two multiple-cardinality elements.
For example, you cannot write the following condition:
definitions set myItems to all items; if myItems is myArray …
If you write this condition, you get the following error: "Invalid variable 'object [MULTIPLE]' for expected type 'object [SINGLE]", because no method verbalized <object> is <object> is declared.
To use multiple-cardinality elements with methods that use single-cardinality elements, you can use the asSingle method:
-
In the BOM you declare two static methods:
Collection domains:
public static object asSingle(java.util.Collection arg domain 0,* class object) property noTypeConversion "true";Arrays:
public static object asSingle(java.lang.Object[] arg);These methods cast a multiple-cardinality argument into a single one (arrays or collection domains). The method overriding mechanism selects only one method to verbalize.
You can now compare multiple-cardinality elements in a rule:
definitions set myItems to all items; if myItems as single is myArray as single …