OCLOperators casetruefalse
(Adding message template to the top of the page)
No edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{message|Write the content here to display this box}}
<message>Write the content here to display this box</message>
This is a new compact form to write:
This is a new compact form to write:
  if somebool then
  if somebool then
Line 9: Line 9:
  somebool.casetruefalse(someexpressionwithtypeX,someOtherexpressionwithtypeX)
  somebool.casetruefalse(someexpressionwithtypeX,someOtherexpressionwithtypeX)


===== Usage in EAL =====
==== Usage in EAL ====
If you want to execute methods in a case/switch-like statement.
If you want to execute methods in a case/switch-like statement.


Line 20: Line 20:
  )
  )


===== Usage in OCL =====
==== Usage in OCL ====
If you want to derive a string based on a list of conditions and have an else-statement if none of the expressions were True:
If you want to derive a string based on a list of conditions and have an else-statement if none of the expressions were True:
  (self.oclIsInState(#New).caseTrueFalse('New/Ordering', String.nullValue)+
  (self.oclIsInState(#New).caseTrueFalse('New/Ordering', String.nullValue)+
Line 28: Line 28:
The collect construct at the end can when the result, and if null, do the "else" statement. '''Note'''! Parenthesis around the string concatenation.
The collect construct at the end can when the result, and if null, do the "else" statement. '''Note'''! Parenthesis around the string concatenation.


See also [[OCLOperators_whentrue]]
'''See also:''' [[Documentation:OCLOperators whentrue|OCLOperators_whentrue]]
[[Category:OCLOperators]]
[[Category:OCLOperators]]
{{Edited|July|12|2024}}
{{Edited|July|12|2025}}

Latest revision as of 05:20, 13 February 2025

This page was created by Hans.karlsen@mdriven.net on 2021-12-03. Last edited by Stephanie@mdriven.net on 2025-02-13.

This is a new compact form to write:

if somebool then
  someexpressionwithtypeX
else
  someOtherexpressionwithtypeX
endif

This operator enables you to write the same thing as:

somebool.casetruefalse(someexpressionwithtypeX,someOtherexpressionwithtypeX)

Usage in EAL

If you want to execute methods in a case/switch-like statement.

This makes a switch-like construct look like this:

let x=SomeObject.SomeEnum in
(
  (x=#Enum1).casetruefalse(SomeObject.DoYourThing1,DoNothing);
  (x=#Enum2).casetruefalse(SomeObject.DoYourThing2,DoNothing);
  (x=#Enum3).casetruefalse(SomeObject.DoYourThing3,DoNothing)
)

Usage in OCL

If you want to derive a string based on a list of conditions and have an else-statement if none of the expressions were True:

(self.oclIsInState(#New).caseTrueFalse('New/Ordering', String.nullValue)+
 self.oclIsInState(#Waiting).caseTrueFalse('Waiting', String.nullValue)+
 self.oclIsInState(#Ordered).caseTrueFalse('Ordered', String.nullValue))->
collect(s| s.notNull.caseTrueFalse(s, self.State))->first

The collect construct at the end can when the result, and if null, do the "else" statement. Note! Parenthesis around the string concatenation.

See also: OCLOperators_whentrue