Java Reference
In-Depth Information
elements-> select ( oclIsTypeOf (mindmap::Topic))
The select operation has a shorthand notation that uses square brackets, as
shown here. This expression is equivalent to the previous one.
elements[ oclIsTypeOf (mindmap::Topic)]
collect
The collect() operation comes from OCL and allows for the creation of one
collection from another, typically of different element types. The resulting col-
lection is flattened; collectNested() and QVT's xcollect() can be used
when nested collections are required. collect() is commonly used to gather
the elements of a class into a new collection, as illustrated here:
topics-> collect (t | t.name);
Here, topics represents a collection of Topic elements, which have a name
attribute of type String. Therefore, the result of this collect() operation is a
collection of Strings representing the name attribute values of each Topic element
in topics. This can be written without the iterator variable as simply this:
topics-> collect (name);
Collect() also has a shorthand notation, where a dot ( . ) can be used in
lieu of the ->collect() syntax. This makes the previous statement even more
simply stated as follows:
topics.name;
It's common to find select() and collect() used together to obtain a
collection of commonly typed elements from a reference that can contain multi-
ple subtypes. For example, consider the elements reference in the Map class
that is of type MapElement. Two subtypes exist: Topic and Reference. To obtain
just the Topic elements, use the following expression:
Search WWH ::




Custom Search