Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

OCLSnippets

Revision as of 03:09, 18 June 2007 by Bjoern.sundin.bergauer.ch (Talk | contribs) (New page: A collection of workable OCL statements. If you use a statement not listed below, please enhance this list for the benefit of the community. == Set Operations == Test for empty collect...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

A collection of workable OCL statements. If you use a statement not listed below, please enhance this list for the benefit of the community.


Set Operations

Test for empty collection where 'self' is the class being checked and 'children' is a Set, List or Collection in this class

self.children->isEmpty()

Test for not empty collection where 'self' is the class being checked and 'children' is a Set, List or Collection in this class

self.children->notEmpty()


String Operations

Test for String with zero length where 'self' is the class being checked and 'name' is a not nullable String variable in this class

self.name.size() > 0

Note from Christian W. Damus: If the 'name' attribute can have a null value, then when it is null, self.name.size() evaluates to OclInvalid, and OclInvalid is not comparable with integers, resulting in OclInvalid again. In checking this constraint, the system will interpret OclInvalid as a failure (boolean false).


Class Operations

Unique text over all instances expressions where 'MyObject' is the Class and 'name' is an String variable in MyObject

Expression 1

MyObject.allInstances()->isUnique(name)

Expression 2

MyObject.allInstances()->select(m : MyObject | m <> self and m.name = self.name)->isEmpty()

Back to the top