The > operator lets you write OCL conditions that are true only when one comparable value is strictly greater than another; use it in constraints, validations, and conditional expressions.
Syntax
leftValue > rightValueThe expression returns a Boolean value:
| Condition | Result |
|---|---|
leftValue is greater than rightValue
|
true
|
leftValue is equal to or less than rightValue
|
false
|
Both operands must be comparable. The operator is defined as > ( object : T ) : Boolean: it returns true when the value on the left is comparable to, and greater than, the value on the right. See Documentation:Mathematical symbols for the mathematical-operator definitions.
Compare an attribute with a value
For a Department with an EmployeeCount attribute, require that the department has at least one employee:
self.EmployeeCount > 0EmployeeCount
|
Expression result | Meaning |
|---|---|---|
0
|
false
|
The department has no employees. |
1
|
true
|
The department has more than zero employees. |
12
|
true
|
The department has more than zero employees. |
Use in an invariant
An invariant is a condition that instances of a class must satisfy. Put the comparison in the context of the class whose attribute you are checking:
context Department inv:
self.EmployeeCount > 0This invariant evaluates to true for a department with one or more employees and false for a department whose EmployeeCount is zero.
Strict comparison
> is a strict comparison: equal values do not satisfy it. For example:
self.EmployeeCount > 5EmployeeCount
|
Result |
|---|---|
5
|
false
|
6
|
true
|
If the boundary value must also be accepted, use greater than or equal to (>=) instead. For example, self.EmployeeCount >= 5 returns true when EmployeeCount is exactly 5.
Combine comparisons
Use and when both conditions must be true. This example accepts a department only when its employee count is greater than zero and its budget is greater than zero:
(self.EmployeeCount > 0) and (self.Budget > 0)Use or when either condition is sufficient. For example:
(self.EmployeeCount > 10) or self.IsStrategicThis expression is true when the department has more than ten employees, when IsStrategic is true, or when both conditions are true.
