This operator returns both meta information about a class's constraints and if it's currently broken.
The return value is a collection of <a href="/Documentation:Tuple" title="Documentation:Tuple" data-bs-title="Documentation:Tuple">Tuple</a> containing the following:
- Name
- Description
- IsDeleteConstraint: True/False
- ErrorLevel: #Information, #Warning or #Error
- Broken: Evaluated and <a href="/BestPractices:Subscribed" title="BestPractices:Subscribed" data-bs-title="BestPractices:Subscribed">Subscribed</a> state of the constraint
Examples[<a href="/index.php?title=Documentation:OCLOperators_constraints&veaction=edit§ion=1" class="mw-editsection-visualeditor" title="Edit section: Examples" data-bs-title="Documentation:OCLOperators_constraints">edit</a> | <a href="/index.php?title=Documentation:OCLOperators_constraints&action=edit§ion=1" title="Edit section: Examples" data-bs-title="Documentation:OCLOperators_constraints">edit source</a>]
To check if any constraint with error level Error is broken:
self.constraints->select(c|(c.ErrorLevel = #Error) and c.Broken)->isEmpty -- Returns True if no errors
Returning a collection of Descriptions of broken Warning constraints:
self.constraints->select(c|(c.ErrorLevel = #Warning) and c.Broken)->collect(c|c.Description)
Please Note[<a href="/index.php?title=Documentation:OCLOperators_constraints&veaction=edit§ion=2" class="mw-editsection-visualeditor" title="Edit section: Please Note" data-bs-title="Documentation:OCLOperators_constraints">edit</a> | <a href="/index.php?title=Documentation:OCLOperators_constraints&action=edit§ion=2" title="Edit section: Please Note" data-bs-title="Documentation:OCLOperators_constraints">edit source</a>]
This operator earlier resulted in an array of booleans with the constraint result. To get the same functionality now, add .broken=false to the end of the previous expression.
Like this, used with <a href="/Documentation:OCLOperators_forAll" title="Documentation:OCLOperators forAll" data-bs-title="Documentation:OCLOperators_forAll">forAll</a>:
self.constraints->forAll(c|c.broken=false)
See also: <a href="/Training:Constraints" title="Training:Constraints" data-bs-title="Training:Constraints">Constraints</a>, <a href="/Documentation:OCLOperators_brokenConstraints" title="Documentation:OCLOperators brokenConstraints" data-bs-title="Documentation:OCLOperators_brokenConstraints">OCLOperators_brokenConstraints</a>