You use isEmpty() in OCL to test whether a collection contains no elements; it is for modelers writing conditions, constraints, and expressions in MDriven Designer.
Syntax
collection->isEmpty()
isEmpty() returns a Boolean value:
| Collection state | Result |
|---|---|
| The collection has no elements. | true
|
| The collection has one or more elements. | false
|
Use isEmpty on a collection
A collection is a group of objects or values, such as the objects reached through an association or a collection created with Set. Use ->isEmpty() when you need to determine whether that group has no members.
For example, if a Car has a collection-valued association named Wheels, this expression is true when the car has no related wheels:
self.Wheels->isEmpty()
If Wheels contains one or more wheel objects, the same expression returns false.
Example: test for no matching objects
You can combine isEmpty() with a collection operation to express a condition about matching objects. For example, this expression tests whether no wheel in self.Wheels has the value 'Spare':
self.Wheels->select(w | w.Type = 'Spare')->isEmpty()
The expression returns true when the selection produces no wheels. It returns false when at least one selected wheel exists.
Do not use isEmpty on a value type
Do not apply ->isEmpty() directly to a value type, such as a single string, number, Boolean value, or object reference. MDriven converts that value to a collection containing the value as its only item. That collection is not empty, so the result is always false.
For example, do not use:
self.RegistrationNumber->isEmpty()
RegistrationNumber is a single value, not a collection. If you need to work with the number of characters in a string, use length instead. Use isEmpty() only when the expression before -> is a collection.
Related operation
notEmpty() is the inverse of isEmpty(). Use it when you want to test whether a collection contains at least one element.
