You can use the greater than or equal to operator in OCL expressions when a value must meet or exceed a minimum; this page is for MDriven Designer users writing Boolean conditions and constraints.
Syntax
leftValue >= rightValueThe >= operator is a comparison operator. It returns true when the value on the left is greater than or equal to the value on the right. Otherwise, it returns false.
Both values must be comparable. The operator is inclusive: a value equal to the limit satisfies the expression.
Compare a minimum value
Assume that the Department class has an EmployeeCount attribute. To require at least five employees, use:
self.EmployeeCount >= 5| EmployeeCount | Expression result | Meaning |
|---|---|---|
| 4 | false
|
The department has fewer than five employees. |
| 5 | true
|
The department meets the minimum exactly. |
| 8 | true
|
The department exceeds the minimum. |
For example, you can write the same rule as an invariant in the context of Department:
context Department inv: self.EmployeeCount >= 5Assume the Department class has an attribute called EmployeeCount.
self.EmployeeCount >= 5The number of employees in the department must be at least 5. If EmployeeCount is 5 or more, the expression returns true. If it is less than 5, the expression returns false.
You can also use >= with dates and other comparable types. Another example with Dates
self.CreatedDate >= DateTime('2024-01-01T00:00:00')Using greater than or equal to on a collection
Combine minimum requirements
Use >= with and when more than one condition must be true. For example, a person must be at least 18 and have the required gender value:
(self.age >= 18) and (self.gender = 'Male')The first condition is true when age is 18 or greater. The complete expression is true only when both conditions are true.
You can use >= within collection operations to check multiple instances.
Department.allInstances->exists(d | d.EmployeeCount >= 10)The number of employees in the department must be at least 10. If EmployeeCount is 10 or more, the expression returns true. If it is less than 5, the expression returns false
Choose the correct comparison
| Requirement | Operator | Example |
|---|---|---|
| The value must be at least the limit. | >=
|
self.EmployeeCount >= 5
|
| The value must be greater than the limit. | >
|
self.EmployeeCount > 5
|
| The value must be at most the limit. | <=
|
self.EmployeeCount <= 10
|
| The value must be less than the limit. | <
|
self.EmployeeCount < 10
|
