OCLOperators value
(Created page with "Returns the the non-null value of a simple nullable type. {| class="wikitable" !Expression !Result |- |int? with the value null |0 |} {{Edited|July|12|2024}}") |
No edit summary |
||
(8 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
<message>Write the content here to display this box</message> | |||
Returns the the non-null value of a simple nullable type. | Returns the the non-null value of a simple nullable type. | ||
{| class="wikitable" | {| class="wikitable" | ||
Line 7: | Line 8: | ||
|0 | |0 | ||
|} | |} | ||
{{Edited|July|12|2024}} | {{Edited|July|12|2024}}The value of the current nullable object is returned if it has been assigned a valid underlying value - otherwise, 0 is returned. | ||
Some expressions may require a non-null value and yet your attribute is a nullable type. A scenario like this is catered for in the MDriven OCL expressions. | |||
'''.Value''' is available for all number types including Integer, Decimal, Double, and Int64. | |||
For example: | |||
[[File:getting-value-for-nullable-type.png|alt=getting value for nullable type|frameless|202x202px]] | |||
To calculate the Total Price of all products use: | |||
Product.allinstances.Price->sum.Value | |||
or: | |||
Product.allinstances->collect(i|i.Price.Value)->sum | |||
This will ensure a value is always returned by the expression, either when there are no product instances or the product price is not set for all instances. |
Latest revision as of 05:31, 24 June 2024
Returns the the non-null value of a simple nullable type.
Expression | Result |
---|---|
int? with the value null | 0 |
The value of the current nullable object is returned if it has been assigned a valid underlying value - otherwise, 0 is returned.
Some expressions may require a non-null value and yet your attribute is a nullable type. A scenario like this is catered for in the MDriven OCL expressions.
.Value is available for all number types including Integer, Decimal, Double, and Int64.
For example:
To calculate the Total Price of all products use:
Product.allinstances.Price->sum.Value
or:
Product.allinstances->collect(i|i.Price.Value)->sum
This will ensure a value is always returned by the expression, either when there are no product instances or the product price is not set for all instances.
This page was edited 7 days ago on 06/24/2024. What links here