Java Reference
In-Depth Information
objects not in the original collection (it is not a subcollection). The collect oper-
ation does this using the same syntax as the select and reject expressions:
collection.collect( v | expression-with-v )
collect()
iterates over the target collection and evaluates the given expres-
sion on each element. In contrast to select, the evaluation
result
is collected in
a list. When the iteration is finished, the list with all results is returned. For exam-
ple, if the
name
property of the objects in the collection
elements
is a String, a
list of Strings is returned:
elements.collect(e | e.name)
// returns a list of Strings
Navigation through many objects is common, so a shorthand notation for
collect()
makes the expressions more readable. This is just as in OCL, so
instead of using:
self.employee.collect(e | e.birthdate)
You can simply write this:
self.employee.birthdate
In general, when a property is applied to a collection of Objects, it automat-
ically is interpreted as a
collect()
over the members of the collection with the
specified property.
forAll
Often a Boolean expression must be evaluated for all elements in a collection.
The
forAll()
operation enables you to specify a Boolean expression that must
be
true
for all objects in a collection for the operation to return
true
:
collection.forAll( v | boolean-expression-with-v )
The result of
forAll()
is
true
if
boolean-expression-with-v
is
true
for all the elements contained in the collection. If
boolean-expression-
with-v
is
false
for one or more of the elements in the collection, the expres-
sion evaluates to
false
.
Search WWH ::
Custom Search