OCLOperators allInstances
No edit summary
(Automatically adding template at the end of the page.)
 
(13 intermediate revisions by 5 users not shown)
Line 1: Line 1:
It is a common operator. To find all available you can open the OCL-Editor and type in a class:
=== allInstances () : Set{T} ===
 
Returns a Set containing all of the existing instances of the current classifier (along with instances of all its inherited classifiers).
Your model is central to all expression you will handle. We will use this model to for the examples:
{| class="wikitable"
!Expression
!Result
|-
|let a : String = 'a', b : String = 'b', c : Integer = 2 in String.allInstances()
|Set{'a','b'}
|}
Your model is central to all expressions you will handle. We will use this model for the examples:


[[File:Allinstances operator.png|frameless|355x355px]]
[[File:Allinstances operator.png|frameless|355x355px]]
Line 9: Line 16:
|-
|-
|'''Thing.allinstances'''
|'''Thing.allinstances'''
|Gives you a list of all Things
|Gives you a list of all things
|-
|-
|'''Things.allinstances->select(someInt>3)'''
|'''Things.allinstances->select(someInt>3)'''
Line 21: Line 28:
|-
|-
|'''Things.allinstances.Details'''
|'''Things.allinstances.Details'''
|Gives a list of all detail objects that are connected to a Thing. The Detail objects that float around without a Thing will not be in the list
|Gives a list of all Detail objects that are connected to a Thing. The Detail objects that float around without a Thing will not be on the list
|-
|-
|'''Things.allinstances.Details.Attribute1'''
|'''Things.allinstances.Details.Attribute1'''
|A list of nullable strings from the contents from the details attribute1. Note that OCL is null-tolerant – you do not need to check if the Details exists of not – the language handles null checks for you
|A list of nullable strings from the contents of the details attribute1. Note that OCL is null-tolerant – you do not need to check if the Details exist or not – the language handles null checks for you.
|-
|-
|'''SubClassThing1.allinstances.Details'''
|'''SubClassThing1.allinstances.Details'''
Line 32: Line 39:
|Filtering on Specialization is done with an operator SafeCast. This is null safe so for all objects that do not fit the profile the expression returns false
|Filtering on Specialization is done with an operator SafeCast. This is null safe so for all objects that do not fit the profile the expression returns false
|}
|}
To find all available you can open the OCL-Editor and type in a class:
This was a description of the <code>allinstances</code> operator. It is a common operator. To find all available operators, you can open the OCL Editor and type in a class. See: [[OCLOperators]]
 
[[Category:OCL General Operators]]
[[File:Ocl-editor 1.png|frameless|348x348px]]
{{Edited|July|12|2024}}
 
The operations listed do this:
{| class="wikitable"
!Operators
!Description
|-
|Allinstances
|All the objects of the class
|-
|allinstancesAtTime
|All the currently loaded instances
|-
|AllStates
|Meta information about available states in state machines the class may contain
|-
|allSubClasses
|Meta information on all the sub classes this class has
|-
|AllSuperTypes
|Meta information on all the super classes – in inheritance order the class has
|-
|associationEnds
|Meta information on all the associationEnds
|-
|Asstring
|The string representation of the class – the asString operation is available on everything
|-
|Attributes
|Meta information about what attributes the class has
|-
|Contraints
|Meta information on what constraints the class has
|-
|Emptylist
|Returns an empty list typed to hold objects of the class
|-
|IsDirtyMember
|
|-
|isNull
|
|-
|nullValue
|A typed null value
|-
|objectFromExternalId
|An external identity will be resolved to the object
|-
|oclAsType
|The type of the class
|-
|oclIsKindOf
|This is to if a class is a subclass or a the class itself and not unrelated
|-
|oclIsTypeOf
|Returns true if
|-
|oclSingleton
|Classes that implements the Singleton pattern – by setting IsSingleton=true – will return the singleton instance with this operator
|-
|OclType
|
|-
|safeCast
|
|-
|SuperTypes
|
|-
|TaggedValue
|Meta information on tagged values set in the class
|-
|TaggedValueOnFeature
|Meta information on Tagged values set on a named feature in the class
|-
|Typename
|The type name as a string
|-
|ViewModels
|A tuple with the ViewModels for this class a members
|}

Latest revision as of 15:40, 10 February 2024

allInstances () : Set{T}

Returns a Set containing all of the existing instances of the current classifier (along with instances of all its inherited classifiers).

Expression Result
let a : String = 'a', b : String = 'b', c : Integer = 2 in String.allInstances() Set{'a','b'}

Your model is central to all expressions you will handle. We will use this model for the examples:

Allinstances operator.png

Operators Description
Thing.allinstances Gives you a list of all things
Things.allinstances->select(someInt>3) Only things with someInt bigger than 3
Thing.allinstances->select( (someInt>3) and (someInt<6)) Only things with someInt bigger than 3 but less than 6. Notice the extra parenthesis to or the Boolean expressions together
Things.allinstances->select(x|x.someInt>3) Here we introduce the loop variable x. We separate the definition of x from the usage of x with the pipe sign “|”. Loop variables are optional but if names are unique – but you will need to use them to give precision or to if you want to perform operations on the loop context itself.
Things.allinstances.Details Gives a list of all Detail objects that are connected to a Thing. The Detail objects that float around without a Thing will not be on the list
Things.allinstances.Details.Attribute1 A list of nullable strings from the contents of the details attribute1. Note that OCL is null-tolerant – you do not need to check if the Details exist or not – the language handles null checks for you.
SubClassThing1.allinstances.Details Inherited features of classes are directly accessible
Thing.allInstances- >select(x|x.safeCast(SubClassThing1). OnlyAvailableInSubClass='Hello') Filtering on Specialization is done with an operator SafeCast. This is null safe so for all objects that do not fit the profile the expression returns false

This was a description of the allinstances operator. It is a common operator. To find all available operators, you can open the OCL Editor and type in a class. See: OCLOperators

This page was edited 101 days ago on 02/10/2024. What links here