OCL Collection Operators
(Created page with "Once you have a collection of objects, there are certain operators applicable to them.")
 
No edit summary
Line 1: Line 1:
Once you have a collection of objects, there are certain operators applicable to them.
Once you have a collection of objects, there are certain operators applicable to them.  
 
See this page for [[examples on collection operators|examples on collection 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"
!Operators
!Description
|-
|'''[[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 count|->count]]'''
|Count how many meet a certain criteria
|-
|[[OCLOperators dictionary|'''->dictionary''']]
|Efficiently looks up values
|-
|'''[[OCLOperators difference|->difference]]'''
|The difference between 2 collections
|-
|'''[[OCLOperators excluding|->excluding]]'''
|The collection except for this single object
|-
|'''[[OCLOperators exists|->exists]]'''
|Returns true if at least one element in ''self'' validates the condition ''expr'', false otherwise.
|-
|'''[[OCLOperators filterOnType|->filterOnType]]'''
|Only keep the ones of a certain type
|-
|'''[[OCLOperators first|->first]]'''
|Return the first object
|-
|'''[[OCLOperators forAll|->forAll]]'''
|Returns true if all the elements contained in ''self'' validate the condition ''expr'', false otherwise.
|-
|'''[[OCLOperators groupBy|->groupBy]]'''
|Build a 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 notEmpty|->]][[OCLOperators notEmpty|notEmpty]]'''
|Returns true if ''self'' contains at least one element, false otherwise.
|-
|'''[[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 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 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 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
|}

Revision as of 07:41, 21 April 2023

This page was created by Stephanie@mdriven.net on 2023-04-12. Last edited by Stephanie@mdriven.net on 2025-03-10.

Once you have a collection of objects, there are certain operators applicable to them.

See this page for examples on collection operators.

Again, you can use the OCL-Editor to see what they are:

Collection of objects operators.png

Operators Description
->append Add another object last
->asBag Returns a Bag containing all elements of self.
->asSequence Returns a Sequence containing all elements of self. Element ordering is preserved when possible.
->asSet Returns a Set containing all elements of self.
->at Get the objects at X where the first index is 1
->at0 Get the objects at X where the first index is 0
->collect Returns a collection containing the result of applying expr on all elements contained in self.
->count Count how many meet a certain criteria
->dictionary Efficiently looks up values
->difference The difference between 2 collections
->excluding The collection except for this single object
->exists Returns true if at least one element in self validates the condition expr, false otherwise.
->filterOnType Only keep the ones of a certain type
->first Return the first object
->forAll Returns true if all the elements contained in self validate the condition expr, false otherwise.
->groupBy Build a collection of tuples grouped by some aspect
->includes Does the collection include the object
->includesAll Does the collection include the whole other collection
->including Returns the list with the element in the parameter included.
->IndexOf The 1 based index of an object in the collection possibly -1 if not existing
->indexOf0 The 0 based index of an object in the collection possibly -1 if not existing
->intersection The intersection of two collections
->isEmpty Returns true if the collection is empty
->notEmpty Returns true if self contains at least one element, false otherwise.
->reject Returns a collection with all elements of self except for those who validate the OclExpression expr.
->select Returns a collection with all elements of self that validate the OclExpression expr.
->size Returns the number of elements contained in self.
->sum Returns the sum of all elements contained in self if they support the '+' operation.
->last Returns the last object in the collection
->orderBy Sorts the collection on one or more properties
->orderDescending Sort the from biggest to smallest
->orderGeneric Sorts the list of properties with interchangeable sort order: (expr1, OclSortDirection::ascending, expr2, OclSortDirection::descending...)
->prepend Returns an OrderedSet containing object followed by all elements of self.
->subsequence Returns a smaller collection from a start to stop
->symmetricDifference The symmetric difference between the collections; ie all the objects in collection1 or collection2 but not in both
->union The set of objects in collection1 and objects in collection2

Pages in category "OCL Collection Operators"

The following 41 pages are in this category, out of 41 total.

MDriven Chat

How would you like to chat today?

Setting up your conversation…

This may take a few moments