OCLOperators value
(Replacing message template with parser tag)
No edit summary
Line 8: 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 MDriven OCL expressions.
 
For example
 
[[File:getting-value-for-nullable-type.png|alt=getting value for nullable type|frameless]]
 
To calculate the Total Price of all products
 
<code>Product.allinstances.Price->sum.Value</code>or
 
<code>Product.allinstances->collect(i|i.Price.Value)->sum</code>
 
This will ensure a value is always returned by the expression either when there are no product instances or product price is not set for all instances

Revision as of 13:38, 19 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 MDriven OCL expressions.

For example

getting value for nullable type

To calculate the Total Price of all products

Product.allinstances.Price->sum.Valueor

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 product price is not set for all instances

This page was edited 88 days ago on 06/24/2024. What links here