OCLOperators allInstances
(Created page with "It is a common operator. To find all available you can open the OCL-Editor and type in a class: Your model is central to all expression you will handle. We will use this mode...") |
No edit summary |
||
Line 4: | Line 4: | ||
[[File:Allinstances operator.png|frameless|355x355px]] | [[File:Allinstances operator.png|frameless|355x355px]] | ||
{| | {| | ||
! | !Operators | ||
! | !Description | ||
|- | |- | ||
| | |Thing.allinstances | ||
| | |Gives you a list of all Things | ||
|- | |- | ||
| | |Things.allinstances->select(someInt>3) | ||
| | |Only things with someInt bigger than 3 | ||
|- | |- | ||
| | |Thing.allinstances->select( (someInt>3) and (someInt<6)) | ||
| | |Only things with someInt bigger than 3 but less than 6. Notice the extra parenthesis to or the Boolean expressions together | ||
|- | |||
|<nowiki>Things.allinstances->select(x|x.someInt>3)</nowiki> | |||
|<nowiki>Here we introduce the loop variable x. We separate the definition of x from the usage of x with the pipe sign “|”. Loop variables are optional but if names are unique – but you will need to use them to give precision or to if you want to perform operations on the loop context itself.</nowiki> | |||
|- | |||
|Things.allinstances.Details | |||
|Gives a list of all detail objects that are connected to a Thing. The Detail objects that float around without a Thing will not be in the list | |||
|- | |||
|Things.allinstances.Details.Attribute1 | |||
|A list of nullable strings from the contents from the details attribute1. Note that OCL is null-tolerant – you do not need to check if the Details exists of not – the language handles null checks for you | |||
|- | |||
|SubClassThing1.allinstances.Details | |||
|Inherited features of classes are directly accessible | |||
|- | |||
|<nowiki>Thing.allInstances- >select(x|x.safeCast(SubClassThing1). OnlyAvailableInSubClass='Hello')</nowiki> | |||
|Filtering on Specialization is done with an operator SafeCast. This is null safe so for all objects that do not fit the profile the expression returns false | |||
|} | |} |
Revision as of 17:49, 8 August 2017
It is a common operator. To find all available you can open the OCL-Editor and type in a class:
Your model is central to all expression you will handle. We will use this model to for the examples:
Operators | Description |
---|---|
Thing.allinstances | Gives you a list of all Things |
Things.allinstances->select(someInt>3) | Only things with someInt bigger than 3 |
Thing.allinstances->select( (someInt>3) and (someInt<6)) | Only things with someInt bigger than 3 but less than 6. Notice the extra parenthesis to or the Boolean expressions together |
Things.allinstances->select(x|x.someInt>3) | Here we introduce the loop variable x. We separate the definition of x from the usage of x with the pipe sign “|”. Loop variables are optional but if names are unique – but you will need to use them to give precision or to if you want to perform operations on the loop context itself. |
Things.allinstances.Details | Gives a list of all detail objects that are connected to a Thing. The Detail objects that float around without a Thing will not be in the list |
Things.allinstances.Details.Attribute1 | A list of nullable strings from the contents from the details attribute1. Note that OCL is null-tolerant – you do not need to check if the Details exists of not – the language handles null checks for you |
SubClassThing1.allinstances.Details | Inherited features of classes are directly accessible |
Thing.allInstances- >select(x|x.safeCast(SubClassThing1). OnlyAvailableInSubClass='Hello') | Filtering on Specialization is done with an operator SafeCast. This is null safe so for all objects that do not fit the profile the expression returns false |
This page was edited more than 11 months ago on 02/10/2024. What links here