Examples on collection operators

One important aspect of OCL worth noting is that it expands lists of lists to just a list. An example in plain English: Thing.allinstances.Details – this will come back as a set of details that are all the details from all the Things. If OCL had not expanded lists automatically, one could have expected a set of sets containing the details per thing. But this is not the case. The automatic expansion of lists of lists is sometimes referred to as the flattening of a collection – referring to the reduction of topology in the result.

Some OCL examples:

Examples Results
Bag{'5','1','2','2','3','4'}->ascommalist 5, 1, 2, 2, 3, 4
Bag{'5','1','2','2','3','4'}- >union(Bag{'1','2','2','3','6'})->ascommalist 5, 1, 2, 2, 3, 4, 6
Bag{'5','1','2','2','3','4'}- >union(Bag{'1','2','2','3','6'})->asset- >ascommalist 5, 1, 2, 3, 4, 6
Bag{'5','1','2','2','3','4'}- >union(Bag{'1','2','2','3','6'})->asset- >orderby(a|a)->ascommalist 1, 2, 3, 4, 5, 6
Bag{'5','1','2','2','3','4'}- >intersection(Bag{'1','2','2','3','6'})- >orderby(a|a)->ascommalist 1, 2, 2, 3
Bag{'5','1','2','2','3','4'}- >Difference(Bag{'1','2','2','3','6'})->orderby(a|a)- >ascommalist 4, 5
Bag{'5','1','2','2','3','4'}- >SymmetricDifference(Bag{'1','2','2','3','6'})- >orderby(a|a)->ascommalist 4, 5, 6

If you are in the context of a simple type like string, double, int, Datetime, or Boolean, MDriven will expose the simple operations that are available in the .net Framework. Test this in the OCL-Editor:

New Column OCL.png

In this case, it is a string that is the result – and we can do string operations like compare, indexof, split, etc.

The numeric types float, double, decimal, and int are sort of apples of the same tree and MDriven exposes ways to go from all numeric types to decimal. The operator is called toDecimal.

This page was edited 75 days ago on 09/19/2024. What links here