Java Reference
In-Depth Information
var
topics :
Sequence
(Topic) :=
self
.elements->select(
oclIsTypeOf
(Topic)->collect(
oclAsType
(Topic));
-- using shorthand, the following is equivalent:
var
topics :
Sequence
(Topic) :=
self
.elements[
oclIsTypeOf
(Topic)].
oclAsType
(Topic);
13.5.2 Imperative Operations
QVTO provides a number of imperative operations, including
forEach
,
forOne
,
while
, and
switch
. Additionally, imperative versions of OCL are
available. This section describes each and provides examples of their use.
forEach
The
forEach
imperative loop expression executes the loop for all the elements
in the collection for which the conditional expression holds. QVTO currently
does not support this expression.
forOne
The
forOne
imperative loop expression executes the loop for only the first ele-
ment in the collection that satisfies the conditional expression. QVTO currently
does not support this expression.
while
The
while
control expression iterates on an expression until its condition is
false
. You can terminate a
while
using a break, or you can direct execution to
the beginning of the next iteration at any point using the continue expression.
Following is an example of a
while
loop used to create a table name from a class
name:
/**
* Replaces camel case with underscore, e.g. firstName -> FIRST_NAME
*/
query String
::toColumnName() :
String
{
var
name :
String
:= '';
var
digit :
String
:= '';
var
pos :
Integer
:= 1;
while
(pos <=
self
.size()) {
digit :=
self
.substring(pos, pos);
if
digit.toLowerCase() <> digit
then
{
Search WWH ::
Custom Search