OCLOperators casetruefalse
Hans Karlsen (talk | contribs) No edit summary |
(Automatically adding template at the end of the page.) |
||
(8 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
This is a new compact form to write : | This is a new compact form to write: | ||
if somebool then | if somebool then | ||
someexpressionwithtypeX | someexpressionwithtypeX | ||
Line 5: | Line 5: | ||
someOtherexpressionwithtypeX | someOtherexpressionwithtypeX | ||
endif | endif | ||
This operator enables you to write the same thing as | This operator enables you to write the same thing as: | ||
somebool. | somebool.casetruefalse(someexpressionwithtypeX,someOtherexpressionwithtypeX) | ||
This makes a switch like construct look like this: | |||
===== 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 | let x=SomeObject.SomeEnum in | ||
( | ( | ||
(x=#Enum1). | (x=#Enum1).casetruefalse(SomeObject.DoYourThing1,DoNothing); | ||
(x=#Enum2). | (x=#Enum2).casetruefalse(SomeObject.DoYourThing2,DoNothing); | ||
(x=#Enum3). | (x=#Enum3).casetruefalse(SomeObject.DoYourThing3,DoNothing) | ||
) | ) | ||
See also [[ | |||
===== 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]] | |||
[[Category:OCLOperators]] | |||
{{Edited|July|12|2024}} |
Latest revision as of 15:41, 10 February 2024
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
This page was edited more than 11 months ago on 02/10/2024. What links here