Java Reference
In-Depth Information
means that xcollect can return nested collections such as {1, {2, 3}}, which
collect would otherwise return as {1, 2, 3}.
As for the collection types xcollect operates on and returns, Sets and
Bags result in a Bag , while OrderedSets and Sequences result in a Sequence.
In both cases, duplicates are possible.
You can think of the collectselect imperative iterate expression as a sin-
gle loop combination of collect and select, where null values are removed from
the result. The remaining iterators are self-explanatory.
The type of objects contained within the results of these iterators depends on
the use of its conditional, if specified. When a Type is specified as the conditional,
it is evaluated using the Boolean oclIsKind(Type) and returns a sequence
casted to the specified Type.
Shorthand notation is available for these imperative expressions, as
described in the following examples. Notice that the shorthand is also available
to operations, as shown in the last two examples.
-- An example of collectselect
self .elements-> collectselect (i; a=i.name | a.startsWith('A'));
-- An equivalent collectselect using shorthand notation
self .elements->name[a | a.startsWith('A')];
-- An equivalent collectselect shorthand without a target variable
self .elements->name[startsWith('A')];
-- An example of xcollect
self .elements-> xcollect (a | a.name);
-- An equivalent xcollect using shorthand notation
self .elements->name;
-- An example of xselect
self .elements-> xselect (Topic);
-- An equivalent xselect using shorthand notation
self .elements[Topic];
-- An example of collectselect shorthand with an operation
main () {
inModel.rootObjects()[Map]. map toRequirementsModel();
}
-- An example of collectselectOne shorthand using '!'
main () {
inModel.rootObjects()![Map]. map toRequirementsModel();
}
Search WWH ::




Custom Search