Java Reference
In-Depth Information
name := name + '_' + digit;
} else {
name := name + digit;
} endif ;
pos := pos + 1;
};
return name.toUpperCase();
}
switch
The switch imperative expression evaluates condition-based alternatives. It is
popular when dealing with enumeration types, as shown in the following exam-
ple. Note that the more familiar case syntax is also available, in addition to
what's shown here.
query mindmap::Topic::getPriority() : String {
var pri : String := null ;
switch {
( self .priority = Priority::HIGH) ? pri := 'High';
( self .priority = Priority::MEDIUM) ? pri := 'Medium';
( self .priority = Priority::LOW) ? pri := 'Low';
else ? assert fatal ( false )
with log ('Priority unsupported', self );
};
return pri;
}
In the example, the priority is evaluated against the enumeration literal, with
a String returned for each match. If no matches are found, the else statement
invokes a fatal assertion to terminate execution and log the appropriate message.
13.5.3 Imperative Iterate Expressions
A set of six imperative iterate expressions are available: xcollect , collect
One , collectselect , collectselectOne , xselect , and selectOne . Each
of these iterates over the source collection to populate the target using iterator
variables, a body, and a condition expression. These are similar to their OCL
counterparts but can be interrupted using break, continue, raise, and return
expressions. Perhaps the most important difference is that null values are not
included in the result set.
The xcollect imperative iterate expression is similar to its collect
counterpart, but with the important distinction that it does not flatten the result.
This makes it more comparable to the OCL collectNested() operation. This
Search WWH ::




Custom Search