|
|
(45 intermediate revisions by 4 users not shown) |
Line 1: |
Line 1: |
| == General operators ==
| | OCL operators define constraints and operations on objects in an object-oriented programming language like Java, C++, or C#. They are also used in OCL expressions to specify constraints on objects or perform operations on object properties. |
| To find all available you can open the OCL-Editor and type in a class:
| |
|
| |
|
| [[File:Ocl-editor 1.png|frameless|433x433px|link=https://wiki.mdriven.net/index.php/File:Ocl-editor_1.png]]
| | For example, let's say we have a class called "Person" with properties like: "name," "age," and "gender." We can use OCL operators to define constraints on the properties of the "Person" class. Here are some examples: |
| {| class="wikitable"
| | # To define a constraint that ensures that the "age" property of a "Person" object is greater than or equal to 18, we can use the greater than or equal to (>=) operator as follows: <code>context Person: self.age >= 18</code> |
| !Operators
| | # To define a constraint that ensures that the "gender" property of a "Person" object is either "Male" or "Female," we can use the OR (||) operator as follows: <code>context Person: self.gender = 'Male' or self.gender = 'Female'</code> |
| !Description
| | # To define a constraint that ensures that the "name" property of a "Person" object starts with an uppercase letter, we can use the dot notation (.) and the regular expression operator (matches) as follows: <code>context Person: self.name.matches('^[A-Z]')</code> |
| |-
| | In addition to defining constraints, OCL operators can also perform operations on object properties. For example, we can use the sum() operator to calculate the sum of all the elements in a collection property of a "Person" object as follows: <code>context Person: self.salary.sum() < 100000</code> |
| |'''[[Allinstances operator|Allinstances]]'''
| |
| |All the objects of the class
| |
| |-
| |
| |'''[[OCLOperators allInstancesAtTime|allinstancesAtTime]]'''
| |
| |All the currently loaded instances
| |
| |-
| |
| |[[OCLOperators allLoadedObjects|allLoadedObjects]]
| |
| |All objects currently in memory, exckluding deleted objects
| |
| |-
| |
| |'''[[OCLOperators allStates|allStates]]'''
| |
| |Meta information about available states in state machines the class may contain
| |
| |-
| |
| |'''[[OCLOperators allSubClasses|allSubClasses]]'''
| |
| |Meta information on all the sub classes this class has
| |
| |-
| |
| |'''[[OCLOperators allSuperTypes|allSuperTypes]]'''
| |
| |Meta information on all the super classes – in inheritance order the class has
| |
| |-
| |
| |[[OCLOperators ASCII|ASCII]]
| |
| |
| |
| |-
| |
| |'''[[OCLOperators associationEnds|associationEnds]]'''
| |
| |Returns a collection of strings with association names for the class
| |
| |-
| |
| |[[OCLOperators associationEndsWithType|associationEndsWithType]]
| |
| |Returns a collection of strings with association names and type information for the class
| |
| |-
| |
| |'''[[OCLOperators asString|asString]]'''
| |
| |The string representation of the class – the asString operation is available on everything
| |
| |-
| |
| |[[OCLOperators AsTaJson|asTaJson]]
| |
| |Returns ajson string defined by the ViewModel
| |
| |-
| |
| |[[OCLOperators atTime|atTime]]
| |
| |
| |
| |-
| |
| |'''[[OCLOperators attributes|Attributes]]'''
| |
| |Meta information about what attributes the class has
| |
| |-
| |
| |[[OCLOperators BigEndianUnicode|BigEndianUnicode]]
| |
| |
| |
| |-
| |
| |[[OCLOperators brokenConstraints|brokenConstraints]]
| |
| |Returns a collection of the names of broken constraints for the class and object.
| |
| |-
| |
| |[[OCLOperators canAccess|canAccess]]
| |
| |Check viewmodels Access expression for root
| |
| |-
| |
| |'''[[OCLOperators constraints|Contraints]]'''
| |
| |Meta information on what constraints the class has
| |
| |-
| |
| |[[OCLOperators count|count]]
| |
| |Returns how many times ''object'' is in the collection ''self''.
| |
| |-
| |
| |[[OCLOperators Default|Default]]
| |
| |
| |
| |-
| |
| |[[OCLOperators Empty|Empty]]
| |
| |
| |
| |-
| |
| |'''[[OCLOperators emptyList|emptylist]]'''
| |
| |Returns an empty list typed to hold objects of the class
| |
| |-
| |
| |[[OCLOperators existing|existing]]
| |
| |
| |
| |-
| |
| |[[OCLOperators externalId|externalId]]
| |
| |Returns the external ID for the object operated on.
| |
| |-
| |
| |[[OCLOperators format|format]]
| |
| |
| |
| |-
| |
| |[[OCLOperators IsDirty|IsDirty]]
| |
| |
| |
| |-
| |
| |[[OCLOperators IsNew|IsNew]]
| |
| |IsNew operator returns true if the object has never been saved to the database.
| |
| |-
| |
| |'''isDirtyMember'''
| |
| |
| |
| |-
| |
| |'''isNull'''
| |
| |
| |
| |-
| |
| |'''[[OCLOperators nullValue|nullValue]]'''
| |
| |A typed null value
| |
| |-
| |
| |'''[[OCLOperators objectfromExternalId|objectFromExternalId]]'''
| |
| |An external identity will be resolved to the object
| |
| |-
| |
| |'''[[OCLOperators oclAsType|oclAsType]]'''
| |
| |The type of the class
| |
| |- | |
| |[[OCLOperators oclGetStates|oclGetStates]]
| |
| |
| |
| |-
| |
| |'''[[oclIsInvalid]]''' | |
| |Returns true if ''self'' is equal to *invalid*.
| |
| |-
| |
| |'''[[OCLOperators oclIsKindOf|oclIsKindOf]]'''
| |
| |This is to if a class is a subclass or a the class itself and not unrelated
| |
| |-
| |
| |'''[[OCLOperators oclIsTypeOf|oclIsTypeOf]]'''
| |
| |Returns true if
| |
| |-
| |
| |[[OCLOperators OnCreate|OnCreate]]
| |
| |
| |
| |-
| |
| |[[OCLOperators OnUpdate|OnUpdate]]
| |
| |
| |
| |-
| |
| |[[oclIsUndefined]]
| |
| |Returns true if ''self'' is equal to invalid or null.
| |
| |-
| |
| |'''[[OCLOperators OclType|OclType]]'''
| |
| |
| |
| |-
| |
| |[[OCLOperators random|random]]
| |
| |
| |
| |-
| |
| |'''[[OCLOperators safeCast|safeCast]]'''
| |
| |
| |
| |-
| |
| |[[OCLOperators Sqlpassthrough|sqlpassthrough]]
| |
| |Calls a stored procedure
| |
| |-
| |
| |[[OCLOperators sqlpassthroughobjects|sqlpassthroughobjects]]
| |
| |Return a primary key of SomeClass. This can be combined with other Ocl-PS via ->intersection or union.
| |
| |-
| |
| |'''[[OCLOperators superTypes|superTypes]]'''
| |
| |Returns the set of all direct supertypes of the type.
| |
| |-
| |
| |'''[[OCLOperators taggedValue|TaggedValue]]'''
| |
| |Meta information on tagged values set in the class
| |
| |-
| |
| |'''[[OCLOperators taggedValueOnFeature|TaggedValueOnFeature]]'''
| |
| |Meta information on Tagged values set on a named feature in the class
| |
| |-
| |
| |'''[[OCLOperators typename|Typename]]'''
| |
| |The type name as a string
| |
| |-
| |
| |'''[[OCLOperators ViewModels|ViewModels]]'''
| |
| |A tuple with the ViewModels for this class a members
| |
| |}
| |
|
| |
|
| == Collection operators ==
| | OCL operators make it easy to write correct and maintainable object-oriented programs. |
| Once you have a collection of objects there are certain operators that are applicable to it.
| |
|
| |
|
| See this page for [[examples on collection operators]]
| | == Examples of OCL Operators == |
| | |
| Again you can use the OCL-Editor to see what they are:
| |
| | |
| [[File:Collection of objects operators.png|frameless|453x453px|link=https://wiki.mdriven.net/index.php/File:Collection_of_objects_operators.png]]
| |
| {| class="wikitable" | | {| class="wikitable" |
| !Operators
| | |'''Type''' |
| !Description
| | |'''Description''' |
| |-
| |
| |'''[[OCLOperators any|->any]]''' | |
| |Returns any element contained in ''self'' that validates the condition ''expr'', null otherwise. | |
| |-
| |
| |'''[[OCLOperators append|->append]]'''
| |
| |Add another object last
| |
| |-
| |
| |'''[[OCLOperators asBag|->asBag]]'''
| |
| |Returns a Bag containing all elements of ''self''.
| |
| |-
| |
| |'''[[OCLOperators asSequence|->asSequence]]'''
| |
| |Returns a Sequence containing all elements of ''self''. Element ordering is preserved when possible.
| |
| |-
| |
| |'''[[OCLOperators asSet|->asSet]]'''
| |
| |Returns a Set containing all elements of ''self''.
| |
| |-
| |
| |'''[[OCLOperators at|->at]]'''
| |
| |Get the objects at X where the first index is 1
| |
| |-
| |
| |'''[[OCLOperators at0|->at0]]'''
| |
| |Get the objects at X where the first index is 0
| |
| |-
| |
| |'''[[OCLOperators collect|->collect]]'''
| |
| |Returns a collection containing the result of applying ''expr'' on all elements contained in ''self''.
| |
| |-
| |
| |'''[[OCLOperators collectNested|->]]'''[[OCLOperators collectNested|collectNested]]
| |
| |Returns a collection containing all the elements contained in ''self'' on which we applied the OclExpression ''expr''.
| |
| |-
| |
| |'''[[OCLOperators count|->count]]'''
| |
| |Count how many meet a certain criteria
| |
| |-
| |
| |'''[[OCLOperators excludes|->]]'''[[OCLOperators excludes|excludes]]
| |
| |Returns true if ''object'' is not contained in ''self'', false otherwise.
| |
| |-
| |
| |'''[[OCLOperators excludesAll|->]]'''[[OCLOperators excludesAll|excludesAll]]
| |
| |Returns true if no element of *c2* is contained in ''self'', false otherwise.
| |
| |-
| |
| |[[OCLOperators dictionary|'''->dictionary''']]
| |
| |Efficiently looks up values
| |
| |- | | |- |
| |'''[[OCLOperators difference|->difference]]''' | | |[https://wiki.mdriven.net/index.php/Category:OCL_General_Operators General Operators] |
| |The difference between 2 collections | | |used to manipulate and query objects |
| |- | | |- |
| |'''[[OCLOperators excluding|->excluding]]''' | | |[https://wiki.mdriven.net/index.php/Category:OCL_Collection_Operators Collection Operators] |
| |The collection except this single object
| | |operators applicable to a collection of objects |
| |-
| |
| |'''[[OCLOperators exists|->exists]]'''
| |
| |Returns true if at least one element in ''self'' validates the condition ''expr'', false otherwise.
| |
| |-
| |
| | [[OCLOperatorsFlatten|->flatten]]
| |
| |Returns a collection containing all elements of ''self'' recursively flattened.
| |
| |-
| |
| |'''[[OCLOperators filterOnType|->filterOnType]]'''
| |
| |Only keep the ones of a certain type
| |
| |-
| |
| |'''[[OCLOperators first|->first]]'''
| |
| |Return the first object
| |
| |-
| |
| |'''[[OCLOperators forAll|->forAll]]'''
| |
| |Returns true if the all the elements contained in ''self'' validate the condition ''expr'', false otherwise.
| |
| |-
| |
| |'''[[OCLOperators groupBy|->groupBy]]'''
| |
| |Build collection of tuples grouped by some aspect
| |
| |-
| |
| |'''[[OCLOperators includes|->includes]]'''
| |
| |Does the collection include the object
| |
| |-
| |
| |'''[[OCLOperators includesAll|->includesAll]]'''
| |
| |Does the collection include the whole other collection
| |
| |-
| |
| |'''[[OCLOperators including|->including]]'''
| |
| |Returns the list with the element in the parameter included.
| |
| |-
| |
| |'''[[OCLOperators indexOf|->IndexOf]]'''
| |
| |The 1 based index of an object in the collection possibly -1 if not existing
| |
| |-
| |
| |'''[[OCLOperators indexOf0|->indexOf0]]'''
| |
| |The 0 based index of an object in the collection possibly -1 if not existing
| |
| |-
| |
| |'''[[OCLOperators intersection|->intersection]]'''
| |
| |The intersection of two collections
| |
| |-
| |
| |'''[[OCLOperators isEmpty|->isEmpty]]'''
| |
| |Returns true if the collection is empty
| |
| |-
| |
| |'''[[OCLOperators isUnique|->]]'''[[OCLOperators isUnique|isUnique]]
| |
| |Returns true if all elements contained in ''self'' evaluate to a distinct value for ''expr''.
| |
| |-
| |
| |'''[[OCLOperators notEmpty|->]]'''[[OCLOperators notEmpty|notEmpty]]
| |
| |Returns true if ''self'' contains at least one element, false otherwise.
| |
| |-
| |
| |'''[[OCLOperators one|->]]'''[[OCLOperators one|one]]
| |
| |Returns true if there is only one element contained in ''self'' that validates the condition ''expr'', false otherwise.
| |
| |-
| |
| |'''[[OCLOperators product|->]]'''[[OCLOperators product|product]]
| |
| |Returns a Set of Tuples which represents the Cartesian product of ''self'' with *c2*.
| |
| |-
| |
| |'''[[OCLOperators reject|->]]'''[[OCLOperators reject|reject]]
| |
| |Returns a collection with all elements of ''self'' except for those who validate the OclExpression ''expr''.
| |
| |-
| |
| |'''[[OCLOperators select|->]]'''[[OCLOperators select|select]]
| |
| |Returns a collection with all elements of ''self'' that validate the OclExpression ''expr''.
| |
| |-
| |
| |'''[[OCLOperators size|->]]'''[[OCLOperators size|size]]
| |
| |Returns the number of elements contained in ''self''.
| |
| |-
| |
| |'''[[OCLOperators sortedBY|->]]'''[[OCLOperators sortedBY|sortedBy]]
| |
| |Returns a sorted collection containing all elements from ''self'' sorted in accordance with the OclExpression ''expr''.
| |
| |-
| |
| |'''[[OCLOperators sum|->]]'''[[OCLOperators sum|sum]]
| |
| |Returns the sum of all elements contained in ''self'' if they support the '+' operation.
| |
| |-
| |
| |'''[[OCLOperators last|->last]]'''
| |
| |Returns the last object in the collection
| |
| |-
| |
| |'''[[OCLOperators notEmpty|->notEmpty]]'''
| |
| |Returns true of the collection is not empty
| |
| |-
| |
| |'''[[OCLOperators orderBy|->orderBy]]'''
| |
| |Sorts the collection on one or more properties
| |
| |-
| |
| |'''[[OCLOperators orderDescending|->orderDescending]]'''
| |
| |Sort the from biggest to smallest
| |
| |-
| |
| |'''[[OCLOperators orderGeneric|->orderGeneric]]'''
| |
| |Sorts the list of properties with interchangeable sort order: (expr1, OclSortDirection::ascending, expr2, OclSortDirection::descending...)
| |
| |-
| |
| |'''[[OCLOperators prepend|->prepend]]'''
| |
| |Returns an OrderedSet containing ''object'' followed by all elements of ''self''.
| |
| |-
| |
| |'''[[OCLOperators reject|->reject]]'''
| |
| |Returns the objects not matching the criteria
| |
| |-
| |
| |'''[[OCLOperators select|->select]]'''
| |
| |Returns the objects matching the criteria
| |
| |-
| |
| |'''[[OCLOperators size|->size]]'''
| |
| |Returns the number of elements in the collection
| |
| |-
| |
| |'''[[OCLOperators subSequence|->subsequence]]'''
| |
| |Returns a smaller collection from a start to stop
| |
| |-
| |
| |'''[[OCLOperators symmetricDifference|->symmetricDifference]]'''
| |
| |The symmetric difference between the collections; ie all the objects in collection1 or collection2 but not in both
| |
| |-
| |
| |'''[[OCLOperators union|->union]]'''
| |
| |The set of objects in collection1 and objects in collection2
| |
| |}
| |
| | |
| == String operators ==
| |
| {| class="wikitable"
| |
| !Operators
| |
| !Description
| |
| |-
| |
| |[[Escape codes]]
| |
| |Escape (special) characters used in OCL
| |
| |-
| |
| |[[OCLOperators StringToAnsiBase64|StringToAnsiBase64]]
| |
| |Convert a string to an ANSI (1252) and as a base64 string
| |
| |-
| |
| |[[OCLOperators StringToEncodedBase64|StringToEncodedBase64]]
| |
| |Convert a string to a specific encoding and as a base64 string. For example Western Eauropean (ISO) Codepage 28591
| |
| |-
| |
| |[[OCLOperators Size () : Integer|size () : Integer]]
| |
| |Returns the number of characters composing ''self''.
| |
| |-
| |
| |[[OCLOperators subString|subString]]
| |
| |Returns the substring of the string operated on. The substring starts at parameter 1 and ends at parameter 2. The counting is 1-based.
| |
| |-
| |
| |[[OCLOperators ToInteger () : Integer|toInteger () : Integer]]
| |
| |Returns ''self'' with all characters converted to lowercase.
| |
| |-
| |
| |[[OCLOperators ToLower () : String|toLower () : String]]
| |
| |Returns ''self'' with all characters converted to lowercase.
| |
| |-
| |
| |[[OCLOperators ToReal () : Real|toReal () : Real]]
| |
| |Returns a Real of value equal to ''self''<nowiki>, or |invalid| if </nowiki>''self'' does not represent a real.
| |
| |-
| |
| |[[OCLOperators ToUpper () : String|toUpper () : String]]
| |
| |Returns self with all characters converted to uppercase.
| |
| |}
| |
| | |
| == Number operators ==
| |
| In addition to the basic math functions (+, -, /, \*) are a number of advanced functions. Take note that *Number* denotes both *Integer* and *Real*, and they're substitutive unless otherwise specified.
| |
| {| class="wikitable"
| |
| !Operators
| |
| !Description
| |
| |-
| |
| |[[OCLOperators Number::abs () : Number|Number::abs () : Number]]
| |
| |Returns the absolute value of ''self'', ''self'' if it is already a positive number.
| |
| |-
| |
| |[[OCLOperators Number::floor () : Integer|Number::floor () : Integer]]
| |
| |Returns the integer part of self if it is a Real, self if it is an Integer.
| |
| |-
| |
| |[[OCLOperators Number::max ( r : Number ) : Number|Number::max ( r : Number ) : Number]]
| |
| |Returns the greatest number between self and *r*.
| |
| |-
| |
| |[[OCLOperators Number::min ( r : Number ) : Number|Number::min ( r : Number ) : Number]]
| |
| |Returns the lowest number between ''self'' and *r*.
| |
| |-
| |
| |[[OCLOperators Number::round () : Integer|Number::round () : Integer]]
| |
| |Returns the nearest integer to ''self'' if it is a Real, ''self'' if it is an Integer. | |
| |-
| |
| |[[OCLOperators Integer::div ( i : Integer ) : Integer|Integer::div ( i : Integer ) : Integer]]
| |
| |Returns the integer quotient of the division of ''self'' by *i*.
| |
| |-
| |
| |[[OCLOperators Integer::mod ( i : Integer ) : Integer|Integer::mod ( i : Integer ) : Integer]]
| |
| |Returns the integer remainder of the division of ''self'' by *i*.
| |
| |}
| |
| == Set operators ==
| |
| In addition to the basic math functions (+, -, /, \*) are a number of advanced functions. Take note that *Number* denotes both *Integer* and *Real*, and they're substitutive unless otherwise specified.
| |
| {| class="wikitable"
| |
| !Operators
| |
| !Description
| |
| |-
| |
| |= ( set : Set(T) ) : Boolean
| |
| |Returns true if self contains the same objects as *set*.
| |
| |-
| |
| |[[OCLOperators Intersection ( bag : Bag(T) ) : Set(T)|intersection ( bag : Bag(T) ) : Set(T)]]
| |
| |Returns a Bag containing all elements of self that are also contained in *bag*.
| |
| |-
| |
| |[[OCLOperators Intersection ( set : Set(T) ) : Set(T)|intersection ( set : Set(T) ) : Set(T)]]
| |
| |Returns a Set containing all elements of self that are also contained in *set*.
| |
| |-
| |
| |[[OCLOperators SymmetricDifference ( set : Set(T) ) : Set(T)|symmetricDifference ( set : Set(T) ) : Set(T)]]
| |
| |Returns a Set containing all of the elements of ''self'' and *set* that are not present in both.
| |
| |-
| |
| |[[OCLOperators Union ( bag : Bag(T) ) : Bag(T)|union ( bag : Bag(T) ) : Bag(T)]]
| |
| |Returns a Bag containing all elements of ''self'' and all elements of *bag*.
| |
| |-
| |
| |[[OCLOperators Union ( set : Set(T) ) : Set(T)|union ( set : Set(T) ) : Set(T)]]
| |
| |Returns a Set containing all elements of ''self'' and all elements of *set*.
| |
| |}
| |
| == Boolean operators ==
| |
| {| class="wikitable"
| |
| !Operators
| |
| !Description
| |
| |- | | |- |
| |And | | | [https://wiki.mdriven.net/index.php/Category:OCL_String_Operators String Operators] |
| | | | |used to manipulate and compare string values |
| |- | | |- |
| |Implies | | |[https://wiki.mdriven.net/index.php/Category:OCL_Number_Operators Number Operators] |
| | | | |used to perform arithmetic and comparison operations on numeric values |
| |- | | |- |
| |Or | | |[https://wiki.mdriven.net/index.php/Category:OCL_Boolean_Operators Boolean Operators] |
| | | | |used to evaluate and compare Boolean expressions |
| |- | | |- |
| |Not | | |[https://wiki.mdriven.net/index.php/Category:OCL_ViewModel_Operators ViewModel Operators](on selfVM variable) |
| | | | |used to manipulate and interact with data in a ViewModel class of an application. |
| |- | | |- |
| |Xor
| |
| |
| |
| |} | | |} |
| == Viewmodel operators (on selfVM variable) ==
| |
| See page [[SelfVM]]
| |
|
| |
|
| [[Category:OCL]] | | [[Category:OCL]] |
| [[Category:Beginner]] | | [[Category:Beginner]] |
| [[Category:OCLOperators]] | | [[Category:OCLOperators]] |