You use not in OCL expressions to invert a Boolean condition, especially when a nullable Boolean attribute controls a condition such as editing.
Use not to invert a condition
The not operator returns the opposite of a Boolean condition:
| Expression | Result |
|---|---|
not true
|
false
|
not false
|
true
|
For a Boolean attribute, write the attribute itself when you mean that it is enabled or set, and prefix it with not when you mean that it is not set.
self.Agreement.Facilitator.DisableEditing
not self.Agreement.Facilitator.DisableEditingIn this example, the first expression tests whether editing is disabled. The second expression tests whether editing is not disabled.
Avoid equality comparisons with nullable Booleans
A nullable Boolean has three possible states: true, false, and null (no value assigned). Do not routinely use = true or = false to test such an attribute.
In particular, do not use the following expression when the intent is to allow editing:
self.Agreement.Facilitator.DisableEditing = falseWhen DisableEditing is null, this comparison is true. That makes a missing value behave as though the attribute were explicitly false.
Use the direct Boolean form instead:
| Intent | Preferred expression |
|---|---|
| Continue only when editing is disabled | self.Agreement.Facilitator.DisableEditing
|
| Continue only when editing is not disabled | not self.Agreement.Facilitator.DisableEditing
|
For example, this condition requires a valid-to date, requires that the item has not been added to the journal search, and requires that editing is not disabled:
self.ValidTo.notNull and
self.AddedToJournalSearch.isNull and
not self.Agreement.Facilitator.DisableEditingTest for a missing value explicitly
Use isNull when your rule specifically needs to know that a value is not assigned. Use notNull when it specifically requires a value.
For example:
self.ValidTo.notNull and
self.AddedToJournalSearch.isNullThese null tests express a different intent from negating a Boolean condition. Use them for absence or presence checks; use not to invert a Boolean condition.
