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

Difference between revisions of "Acceleo/OCL Operations Reference"

m (Ocl operations for type *Classifier*)
(OCL operation reference)
Line 15: Line 15:
 
| Set{'a','b'}
 
| Set{'a','b'}
 
|}
 
|}
 +
  
 
== Ocl operations for type *OclAny* ==
 
== Ocl operations for type *OclAny* ==
  
 
=== oclAsType ( typespec : Classifier ) : T ===
 
=== oclAsType ( typespec : Classifier ) : T ===
  Returns *self* statically typed as typespec if it is an instance of this type. *Note* that this does not alter the
+
Returns *self* statically typed as typespec if it is an instance of this type. *Note* that this does not alter the runtime value of *self*, it only enables access to subtype operations. This operation allows users to cast '''self''' to another type.
  runtime value of *self*, it only enables access to subtype operations. This operation allows users to cast *self*
+
 
  to another type.
+
{| border="1" cellpadding="5" cellspacing="0"
 +
|-
 +
! style="background: #BCBCBC;" align="center"| Expression
 +
! style="background: #BCBCBC;" align="center"| Result
 +
|-
 +
| aPerson.oclAsType(Employee)
 +
| an object of Employee type
 +
|}
  
  +-------------------------------------------------------------+-----------------------------+
 
  | Expression                                                  | Result                      |
 
  +=============================================================+=============================+
 
  | aPerson.oclAsType(Employee)                                | an object of Employee type  |
 
  +-------------------------------------------------------------+-----------------------------+
 
  
 
=== oclIsInvalid () : Boolean ===
 
=== oclIsInvalid () : Boolean ===
  Returns **true** if *self* is equal to *invalid*.
+
Returns '''true''' if '''self''' is equal to *invalid*.
  
  +--------------------------------------------------------------+--------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                                                  | Result |
+
|-
  +==============================================================+========+
+
! style="background: #BCBCBC;" align="center"| Expression
  | let anObject : String = null in anObject.oclIsUndefined()   | false |
+
! style="background: #BCBCBC;" align="center"| Result
  +--------------------------------------------------------------+--------+
+
|-
  | let anObject : String = invalid in anObject.oclIsUndefined() | true   |
+
| let anObject : String = null in anObject.oclIsUndefined()
  +--------------------------------------------------------------+--------+
+
| false
  | let anObject : String = 'null' in anObject.oclIsUndefined() | false |
+
|-
  +--------------------------------------------------------------+--------+
+
| let anObject : String = invalid in anObject.oclIsUndefined()
 +
| true
 +
|-
 +
| let anObject : String = 'null' in anObject.oclIsUndefined()
 +
| false
 +
|}
  
  
 
=== oclIsKindOf( Classifier typespec ) : Boolean ===
 
=== oclIsKindOf( Classifier typespec ) : Boolean ===
  Returns **true** if the type of *self* corresponds to the type or supertype of typespec, **false** otherwise. This
+
Returns **true** if the type of '''self''' corresponds to the type or supertype of typespec, '''false''' otherwise. This operation allows users to check the class hierarchy of '''self''' much like would an '''instanceof''' Java.
  operation allows users to check the class hierarchy of *self* much like would an *instanceof* Java.
+
  
  +----------------------------------+--------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                      | Result |
+
|-
  +==================================+========+
+
! style="background: #BCBCBC;" align="center"| Expression
  | anEmployee.oclIsKindOf(Employee) | true   |
+
! style="background: #BCBCBC;" align="center"| Result
  +----------------------------------+--------+
+
|-
  | anEmployee.oclIsKindOf(Person)   | true   |
+
| anEmployee.oclIsKindOf(Employee)
  +----------------------------------+--------+
+
| true
  | aCat.oclIsKindOf(Person)         | false |
+
|-
  +----------------------------------+--------+
+
| anEmployee.oclIsKindOf(Person)
 +
| true
 +
|-
 +
| aCat.oclIsKindOf(Person)
 +
| false
 +
|}
  
  
 
=== oclIsTypeOf( typespec : Classifier ) : Boolean ===
 
=== oclIsTypeOf( typespec : Classifier ) : Boolean ===
  Returns **true** if the type of *self* is the same as typespec, or **false** otherwise. This operation allows users
+
Returns '''true''' if the type of '''self''' is the same as typespec, or **false** otherwise. This operation allows users to check the exact class type of '''self'''.
  to check the exact class type of *self*.
+
 
+
  +----------------------------------+--------+
+
  | Expression                      | Result |
+
  +==================================+========+
+
  | anEmployee.oclIsTypeOf(Employee) | true  |
+
  +----------------------------------+--------+
+
  | anEmployee.oclIsTypeOf(Person)  | false  |
+
  +----------------------------------+--------+
+
  | aCat.oclIsTypeOf(Person)        | false  |
+
  +----------------------------------+--------+
+
  
 +
{| border="1" cellpadding="5" cellspacing="0"
 +
|-
 +
! style="background: #BCBCBC;" align="center"| Expression
 +
! style="background: #BCBCBC;" align="center"| Result
 +
|-
 +
| anEmployee.oclIsTypeOf(Employee)
 +
| true
 +
|-
 +
| anEmployee.oclIsTypeOf(Person)
 +
| false
 +
|-
 +
| aCat.oclIsTypeOf(Person)
 +
| false
 +
|}
  
=== oclIsUndefined () : Boolean ===
 
  Returns **true** if *self* is equal to *invalid* or *null*.
 
  
  +--------------------------------------------------------------+--------+
+
=== oclIsUndefined () : Boolean ===
  | Expression                                                  | Result |
+
Returns **true** if *self* is equal to *invalid* or *null*.
  +==============================================================+========+
+
  | let anObject : String = null in anObject.oclIsUndefined()    | true   |
+
  +--------------------------------------------------------------+--------+
+
  | let anObject : String = invalid in anObject.oclIsUndefined() | true  |
+
  +--------------------------------------------------------------+--------+
+
  | let anObject : String = 'null' in anObject.oclIsUndefined()  | false  |
+
  +--------------------------------------------------------------+--------+
+
  
 +
{| border="1" cellpadding="5" cellspacing="0"
 +
|-
 +
! style="background: #BCBCBC;" align="center"| Expression
 +
! style="background: #BCBCBC;" align="center"| Result
 +
|-
 +
| let anObject : String = null in anObject.oclIsUndefined()
 +
| true
 +
|-
 +
| let anObject : String = invalid in anObject.oclIsUndefined()
 +
| true
 +
|-
 +
| let anObject : String = 'null' in anObject.oclIsUndefined()
 +
| false
 +
|}
  
  
 
=== <> ( object : OclAny ) : Boolean ===
 
=== <> ( object : OclAny ) : Boolean ===
  Returns **true** if *self* is a different object from *object*.
+
Returns **true** if *self* is a different object from *object*.
  
  +--------------------------------------------------+--------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                                      | Result |
+
|-
  +==================================================+========+
+
! style="background: #BCBCBC;" align="center"| Expression
  | let a : String = 'a', b : String = 'a' in a <> b | false |
+
! style="background: #BCBCBC;" align="center"| Result
  +--------------------------------------------------+--------+
+
|-
  | let a : Integer = 2, b : Real = 2.0 in a <> b   | false |
+
| let a : String = 'a', b : String = 'a' in a <> b
  +--------------------------------------------------+--------+
+
| false
  | let a : Integer = -2, b : Integer = 2 in a <> b | true   |
+
|-
  +--------------------------------------------------+--------+
+
| let a : Integer = 2, b : Real = 2.0 in a <> b
 +
| false
 +
|-
 +
| let a : Integer = -2, b : Integer = 2 in a <> b
 +
| true
 +
|}
  
  
 
=== = ( object : OclAny) : Boolean ===
 
=== = ( object : OclAny) : Boolean ===
  Returns **true** if *self* is equal to *object*.
+
Returns **true** if *self* is equal to *object*.
  
 
+
{| border="1" cellpadding="5" cellspacing="0"
  +--------------------------------------------------+--------+
+
|-
  | Expression                                       | Result |
+
! style="background: #BCBCBC;" align="center"| Expression
  +==================================================+========+
+
! style="background: #BCBCBC;" align="center"| Result
  | let a : String = 'a', b : String = 'a' in a = b | true   |
+
|-
  +--------------------------------------------------+--------+
+
| let a : String = 'a', b : String = 'a' in a = b
  | let a : Integer = 2, b : Real = 2.0 in a = b     | true   |
+
| true
  +--------------------------------------------------+--------+
+
|-
  | let a : Integer = -2, b : Integer = 2 in a = b   | false |
+
| let a : Integer = 2, b : Real = 2.0 in a = b
  +--------------------------------------------------+--------+
+
| true
 +
|-
 +
| let a : Integer = -2, b : Integer = 2 in a = b
 +
| false
 +
|}
  
  
 
=== < ( object : T ) : Boolean ===
 
=== < ( object : T ) : Boolean ===
  Returns **true** if *self* is comparable to *object* and less than *object*.
+
Returns **true** if *self* is comparable to *object* and less than *object*.
  
  +--------------------------------------------------------------+--------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                                                  | Result |
+
|-
  +==============================================================+========+
+
! style="background: #BCBCBC;" align="center"| Expression
  | let a : Integer = 1, b : Integer = 2 in a < b               | true   |
+
! style="background: #BCBCBC;" align="center"| Result
  +--------------------------------------------------------------+--------+
+
|-
  | let a : Real = 1.5, b : Integer = 2 in a < b                 | true   |
+
| let a : Integer = 1, b : Integer = 2 in a < b
  +--------------------------------------------------------------+--------+
+
| true
  |let a : String = 'Anteater', b : String = 'Aardvark' in a < b | false |
+
|-
  +--------------------------------------------------------------+--------+
+
| let a : Real = 1.5, b : Integer = 2 in a < b
 +
| true
 +
|-
 +
| let a : String = 'Anteater', b : String = 'Aardvark' in a < b
 +
| false
 +
|}
  
  
 
=== > ( object : T ) : Boolean ===
 
=== > ( object : T ) : Boolean ===
  Returns **true** if *self* is comparable to *object* and greater than *object*.
+
Returns **true** if *self* is comparable to *object* and greater than *object*.
  
  +--------------------------------------------------------------+--------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                                                  | Result |
+
|-
  +==============================================================+========+
+
! style="background: #BCBCBC;" align="center"| Expression
  | let a : Integer = 1, b : Integer = 2 in a > b               | false |
+
! style="background: #BCBCBC;" align="center"| Result
  +--------------------------------------------------------------+--------+
+
|-
  | let a : Real = 1.5, b : Integer = 2 in a > b                 | false |
+
| let a : Integer = 1, b : Integer = 2 in a > b
  +--------------------------------------------------------------+--------+
+
| false
  |let a : String = 'Anteater', b : String = 'Aardvark' in a > b | true   |
+
|-
  +--------------------------------------------------------------+--------+
+
| let a : Real = 1.5, b : Integer = 2 in a > b
 +
| false
 +
|-
 +
| let a : String = 'Anteater', b : String = 'Aardvark' in a > b
 +
| true
 +
|}
  
  
 
=== <= ( object : T ) : Boolean ===
 
=== <= ( object : T ) : Boolean ===
  Returns **true** if *self* is comparable to *object* and less than or equal to *object*.
+
Returns **true** if *self* is comparable to *object* and less than or equal to *object*.
  
  +---------------------------------------------------------------+--------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                                                    | Result |
+
|-
  +===============================================================+========+
+
! style="background: #BCBCBC;" align="center"| Expression
  | let a : Integer = 1, b : Integer = 2 in a <= b               | true   |
+
! style="background: #BCBCBC;" align="center"| Result
  +---------------------------------------------------------------+--------+
+
|-
  | let a : Real = 1.5, b : Integer = 2 in a <= b                 | true   |
+
| let a : Integer = 1, b : Integer = 2 in a <= b
  +---------------------------------------------------------------+--------+
+
| true
  |let a : String = 'Anteater', b : String = 'Aardvark' in a <= b | false |
+
|-
  +---------------------------------------------------------------+--------+
+
| let a : Real = 1.5, b : Integer = 2 in a <= b
 +
| true
 +
|-
 +
| let a : String = 'Anteater', b : String = 'Aardvark' in a <= b
 +
| false
 +
|}
  
  
 
=== >= ( object : T ) : Boolean ===
 
=== >= ( object : T ) : Boolean ===
  Returns **true** if *self* is comparable to *object* and greater than or equal to *object*.
+
Returns **true** if *self* is comparable to *object* and greater than or equal to *object*.
  
  +---------------------------------------------------------------+--------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                                                    | Result |
+
|-
  +===============================================================+========+
+
! style="background: #BCBCBC;" align="center"| Expression
  | let a : Integer = 1, b : Integer = 2 in a >= b               | false |
+
! style="background: #BCBCBC;" align="center"| Result
  +---------------------------------------------------------------+--------+
+
|-
  | let a : Real = 1.5, b : Integer = 2 in a >= b                 | false |
+
| let a : Integer = 1, b : Integer = 2 in a >= b
  +---------------------------------------------------------------+--------+
+
| false
  |let a : String = 'Anteater', b : String = 'Aardvark' in a >= b | true   |
+
|-
  +---------------------------------------------------------------+--------+
+
| let a : Real = 1.5, b : Integer = 2 in a >= b
 +
| false
 +
|-
 +
| let a : String = 'Anteater', b : String = 'Aardvark' in a >= b
 +
| true
 +
|}
  
  
Line 179: Line 228:
  
 
=== concat ( s : String ) : String ===
 
=== concat ( s : String ) : String ===
  Returns a string containing *self* followed by *s*.
+
Returns a string containing *self* followed by *s*.
  
  +-------------------------------------------------------------------+--------------------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                                                        | Result            |
+
|-
  +===================================================================+====================+
+
! style="background: #BCBCBC;" align="center"| Expression
  | 'concat'.concat(' ').concat('operation')                         | 'concat operation' |
+
! style="background: #BCBCBC;" align="center"| Result
  +-------------------------------------------------------------------+--------------------+
+
|-
 +
| 'concat'.concat(' ').concat('operation')
 +
| 'concat operation'
 +
|}
  
  
 
=== size () : Integer ===
 
=== size () : Integer ===
  Returns the number of characters composing *self*.
+
Returns the number of characters composing *self*.
  
  +-------------------------------------------------------------+--------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                                                  | Result |
+
|-
  +=============================================================+========+
+
! style="background: #BCBCBC;" align="center"| Expression
  | 'size operation'.size()                                     | 14     |
+
! style="background: #BCBCBC;" align="center"| Result
  +-------------------------------------------------------------+--------+
+
|-
 +
| 'size operation'.size()
 +
| 14
 +
|}
  
  
 
=== substring ( lower : Integer, upper : Integer ) : String ===
 
=== substring ( lower : Integer, upper : Integer ) : String ===
  Returns a string containing all characters from *self* starting from index *lower* up to index *upper* included.
+
Returns a string containing all characters from *self* starting from index *lower* up to index *upper* included. Both *lower* and *upper* parameters should be contained between *1* and *self.size()* included. *lower* cannot be greater than *upper*.
  Both *lower* and *upper* parameters should be contained between *1* and *self.size()* included. *lower* cannot be
+
  greater than *upper*.
+
  
  +---------------------------------------------------------------+----------------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                                                    | Result        |
+
|-
  +===============================================================+================+
+
! style="background: #BCBCBC;" align="center"| Expression
  | 'substring operation'.substring(11, 19)                       | 'operation'   |
+
! style="background: #BCBCBC;" align="center"| Result
  +---------------------------------------------------------------+----------------+
+
|-
  | 'substring operation'.substring(1, 1)                         | 's'           |
+
| 'substring operation'.substring(11, 19)
  +---------------------------------------------------------------+----------------+
+
| 'operation'
  | 'substring operation'.substring(0, 1)                         | |invalid|     |
+
|-
  +---------------------------------------------------------------+----------------+
+
| 'substring operation'.substring(1, 1)
 +
| 's'
 +
|-
 +
| 'substring operation'.substring(0, 1)
 +
| '''''invalid'''''
 +
|}
  
  
 
=== toInteger () : Integer ===
 
=== toInteger () : Integer ===
  Returns an Integer of value equal to *self*, or |invalid| if *self* does not represent an integer.
+
Returns an Integer of value equal to *self*, or |invalid| if *self* does not represent an integer.
  
  +---------------------------------------------------------------+----------------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                                                    | Result        |
+
|-
  +===============================================================+================+
+
! style="background: #BCBCBC;" align="center"| Expression
  | '3.0'.toInteger()                                             | |invalid|     |
+
! style="background: #BCBCBC;" align="center"| Result
  +---------------------------------------------------------------+----------------+
+
|-
  | '4'.toInteger()                                               | 4             |
+
| '3.0'.toInteger()
  +---------------------------------------------------------------+----------------+
+
| '''''invalid'''''
  | 'toInteger'.toInteger()                                       | |invalid|     |
+
|-
  +---------------------------------------------------------------+----------------+
+
| '4'.toInteger()
 +
| 4
 +
|-
 +
| 'toInteger'.toInteger()
 +
| '''''invalid'''''
 +
|}
  
  
 
=== toLower () : String ===
 
=== toLower () : String ===
  Returns *self* with all characters converted to lowercase.
+
Returns *self* with all characters converted to lowercase.
  
  +------------------------------------------------------------+-------------------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                                                | Result            |
+
|-
  +============================================================+===================+
+
! style="background: #BCBCBC;" align="center"| Expression
  | 'LoWeR OpErAtIoN'.toLower()                               | 'lower operation' |
+
! style="background: #BCBCBC;" align="center"| Result
  +------------------------------------------------------------+-------------------+
+
|-
 +
| 'LoWeR OpErAtIoN'.toLower()
 +
| 'lower operation'
 +
|}
  
  
 
=== toReal () : Real ===
 
=== toReal () : Real ===
  Returns a Real of value equal to *self*, or |invalid| if *self* does not represent a real.
+
Returns a Real of value equal to *self*, or |invalid| if *self* does not represent a real.
  
  +---------------------------------------------------------------+----------------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                                                    | Result        |
+
|-
  +===============================================================+================+
+
! style="background: #BCBCBC;" align="center"| Expression
  | '3.0'.toReal()                                               | 3.0           |
+
! style="background: #BCBCBC;" align="center"| Result
  +---------------------------------------------------------------+----------------+
+
|-
  | '4'.toReal()                                                 | 4.0           |
+
| '3.0'.toReal()
  +---------------------------------------------------------------+----------------+
+
| 3.0
  | 'toReal'.toReal()                                             | |invalid|     |
+
|-
  +---------------------------------------------------------------+----------------+
+
| '4'.toReal()
 +
| 4.0
 +
|-
 +
| 'toReal'.toReal()
 +
| '''''invalid'''''
 +
|}
  
  
 
=== toUpper () : String ===
 
=== toUpper () : String ===
  Returns *self* with all characters converted to uppercase.
+
Returns *self* with all characters converted to uppercase.
  
  +------------------------------------------------------------+-------------------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                                                | Result            |
+
|-
  +============================================================+===================+
+
! style="background: #BCBCBC;" align="center"| Expression
  | 'UpPeR OpErAtIoN'.toUpper()                               | 'UPPER OPERATION' |
+
! style="background: #BCBCBC;" align="center"| Result
  +------------------------------------------------------------+-------------------+
+
|-
 +
| 'UpPeR OpErAtIoN'.toUpper()
 +
| 'UPPER OPERATION'
 +
|}
  
  
 
== Ocl operations for type *Number* ==
 
== Ocl operations for type *Number* ==
In addition to the basic math functions (+, -, /, \*) are a number of advanced functions. Take note that *Number*
+
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.
denotes both *Integer* and *Real*, and they're substitutive unless otherwise specified.
+
  
 
=== Number::abs () : Number ===
 
=== Number::abs () : Number ===
  Returns the absolute value of *self*, *self* if it is already a positive number.
+
Returns the absolute value of *self*, *self* if it is already a positive number.
  
  +---------------------------------------------------------------+----------------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                                                    | Result        |
+
|-
  +===============================================================+================+
+
! style="background: #BCBCBC;" align="center"| Expression
  | (-2.3).abs()                                                 | 2.3           |
+
! style="background: #BCBCBC;" align="center"| Result
  +---------------------------------------------------------------+----------------+
+
|-
  | -5.abs()                                                     | 5             |
+
| (-2.3).abs()
  +---------------------------------------------------------------+----------------+
+
| 2.3
 +
|-
 +
| -5.abs()
 +
| 5
 +
|}
  
  
 
=== Number::floor () : Integer ===
 
=== Number::floor () : Integer ===
  Returns the integer part of *self* if it is a Real, *self* if it is an Integer.
+
Returns the integer part of *self* if it is a Real, *self* if it is an Integer.
  
  +---------------------------------------------------------------+----------------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                                                    | Result        |
+
|-
  +===============================================================+================+
+
! style="background: #BCBCBC;" align="center"| Expression
  | (2.3).floor()                                                 | 2             |
+
! style="background: #BCBCBC;" align="center"| Result
  +---------------------------------------------------------------+----------------+
+
|-
  | (2.8).floor()                                                 | 2             |
+
| (2.3).floor()
  +---------------------------------------------------------------+----------------+
+
| 2
  | 2.floor()                                                     | 2             |
+
|-
  +---------------------------------------------------------------+----------------+
+
| (2.8).floor()
 +
| 2
 +
|-
 +
| 2.floor()
 +
| 2
 +
|}
  
  
 
=== Number::max ( r : Number ) : Number ===
 
=== Number::max ( r : Number ) : Number ===
  Returns the greatest number between *self* and *r*.
+
Returns the greatest number between *self* and *r*.
  
  +---------------------------------------------------------------+----------------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                                                    | Result        |
+
|-
  +===============================================================+================+
+
! style="background: #BCBCBC;" align="center"| Expression
  | 6.max(3)                                                     | 6             |
+
! style="background: #BCBCBC;" align="center"| Result
  +---------------------------------------------------------------+----------------+
+
|-
  | 6.max(5.2)                                                   | 6.0           |
+
| 6.max(3)
  +---------------------------------------------------------------+----------------+
+
| 6
  | (2.3).max(3)                                                 | 3.0           |
+
|-
  +---------------------------------------------------------------+----------------+
+
| 6.max(5.2)
  | (2.3).max(5.2)                                               | 5.2           |
+
| 6.0
  +---------------------------------------------------------------+----------------+
+
|-
 +
| (2.3).max(3)
 +
| 3.0
 +
|-
 +
| (2.3).max(5.2)
 +
| 5.2
 +
|}
  
  
 
=== Number::min ( r : Number ) : Number ===
 
=== Number::min ( r : Number ) : Number ===
  Returns the lowest number between *self* and *r*.
+
Returns the lowest number between *self* and *r*.
  
  +---------------------------------------------------------------+----------------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                                                    | Result        |
+
|-
  +===============================================================+================+
+
! style="background: #BCBCBC;" align="center"| Expression
  | 6.min(3)                                                     | 6              |
+
! style="background: #BCBCBC;" align="center"| Result
  +---------------------------------------------------------------+----------------+
+
|-
  | 6.min(5.2)                                                   | 5.2           |
+
| 6.min(3)
  +---------------------------------------------------------------+----------------+
+
| 3
  | (2.3).min(3)                                                 | 2.3           |
+
|-
  +---------------------------------------------------------------+----------------+
+
| 6.min(5.2)
  | (2.3).min(5.2)                                               | 2.3           |
+
| 5.2
  +---------------------------------------------------------------+----------------+
+
|-
 +
| (2.3).min(3)
 +
| 2.3
 +
|-
 +
| (2.3).min(5.2)
 +
| 2.3
 +
|}
  
  
 
=== Number::round () : Integer ===
 
=== Number::round () : Integer ===
  Returns the nearest integer to *self* if it is a Real, *self* if it is an Integer.
+
Returns the nearest integer to *self* if it is a Real, *self* if it is an Integer.
  
  +---------------------------------------------------------------+----------------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                                                    | Result        |
+
|-
  +===============================================================+================+
+
! style="background: #BCBCBC;" align="center"| Expression
  | (2.3).round()                                                 | 2             |
+
! style="background: #BCBCBC;" align="center"| Result
  +---------------------------------------------------------------+----------------+
+
|-
  | (2.5).round()                                                 | 3             |
+
| (2.3).round()
  +---------------------------------------------------------------+----------------+
+
| 2
  | (2.8).round()                                                 | 3             |
+
|-
  +---------------------------------------------------------------+----------------+
+
| (2.5).round()
  | 2.round()                                                     | 2             |
+
| 3
  +---------------------------------------------------------------+----------------+
+
|-
 +
| (2.8).round()
 +
| 3
 +
|-
 +
| 2.round()
 +
| 2
 +
|}
  
  
 
=== Integer::div ( i : Integer ) : Integer ===
 
=== Integer::div ( i : Integer ) : Integer ===
  Returns the integer quotient of the division of *self* by *i*.
+
Returns the integer quotient of the division of *self* by *i*.
  
  +---------------------------------------------------------------+----------------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                                                    | Result        |
+
|-
  +===============================================================+================+
+
! style="background: #BCBCBC;" align="center"| Expression
  | 3.div(2)                                                     | 1             |
+
! style="background: #BCBCBC;" align="center"| Result
  +---------------------------------------------------------------+----------------+
+
|-
  | 11.div(3)                                                     | 3             |
+
| 3.div(2)
  +---------------------------------------------------------------+----------------+
+
| 1
 +
|-
 +
| 11.div(3)
 +
| 3
 +
|}
 
    
 
    
  
 
=== Integer::mod ( i : Integer ) : Integer ===
 
=== Integer::mod ( i : Integer ) : Integer ===
  Returns the integer remainder of the division of *self* by *i*.
+
Returns the integer remainder of the division of *self* by *i*.
 
+
 
  +---------------------------------------------------------------+----------------+
+
{| border="1" cellpadding="5" cellspacing="0"
  | Expression                                                    | Result        |
+
|-
  +===============================================================+================+
+
! style="background: #BCBCBC;" align="center"| Expression
  | 3.mod(2)                                                     | 1             |
+
! style="background: #BCBCBC;" align="center"| Result
  +---------------------------------------------------------------+----------------+
+
|-
  | 11.mod(3)                                                     | 2             |
+
| 3.mod(2)
  +---------------------------------------------------------------+----------------+
+
| 1
 +
|-
 +
| 11.mod(3)
 +
| 2
 +
|}
  
  
Line 368: Line 476:
 
Please note that OCL collections can contain the *null* value (null) but not the *invalid* value (|invalid|). Trying to add |invalid| within a new or existing collection will yield |invalid| as a result. OCL proposes four distinct kinds of collections offering all possibilities of ordering/unicity.
 
Please note that OCL collections can contain the *null* value (null) but not the *invalid* value (|invalid|). Trying to add |invalid| within a new or existing collection will yield |invalid| as a result. OCL proposes four distinct kinds of collections offering all possibilities of ordering/unicity.
  
.. list-table::
+
 
:header-rows: 1
+
{| border="1" cellpadding="5" cellspacing="0" align="center"
:stub-columns: 1
+
|-
         
+
! style="background: #BCBCBC;" align="center"| Collection type
* - Collection type
+
! style="background: #BCBCBC;" align="center"| Ordered
  - Ordered
+
! style="background: #BCBCBC;" align="center"| Unique
  - Unique
+
|-
* - Sequence
+
| Sequence
  - true
+
| true
  - false
+
| false
* - OrderedSet
+
|-
  - true
+
| OrderedSet
  - true
+
| true
* - Bag
+
| true
  - false
+
|-
  - false
+
| Bag
* - Set
+
| false
  - false
+
| false
  - true
+
|-
 +
| Set
 +
| false
 +
| true
 +
|-
 +
|}
  
  
 
=== any ( expr : OclExpression ) : T ===
 
=== any ( expr : OclExpression ) : T ===
Returns any element contained in *self* that validates the condition *expr*, null otherwise. Evaluation is shortcut as soon
+
Returns any element contained in *self* that validates the condition *expr*, null otherwise. Evaluation is shortcut as soon as an element validating *expr* is found. Note that the result of this on unordered collections will be random if more than one element validates *expr*.
as an element validating *expr* is found. Note that the result of this on unordered collections will be random if more than
+
 
one element validates *expr*.
+
{| border="1" cellpadding="5" cellspacing="0"
+
|-
+---------------------------------------------------------------+----------------+
+
! style="background: #BCBCBC;" align="center"| Expression
| Expression                                                    | Result        |
+
! style="background: #BCBCBC;" align="center"| Result
+===============================================================+================+
+
|-
| Sequence{1.2, 2.3, 5.2, 0.9}->any(self < 1)                   | 0.9           |
+
| Sequence{1.2, 2.3, 5.2, 0.9}->any(self < 1)
+---------------------------------------------------------------+----------------+
+
| 0.9
| Sequence{1.2, 2.3, 5.2, 0.9}->any(self < 2)                   | 1.2           |
+
|-
+---------------------------------------------------------------+----------------+
+
| Sequence{1.2, 2.3, 5.2, 0.9}->any(self < 2)
 +
| 1.2
 +
|}
  
  
 
=== asBag () : Bag(T) ===
 
=== asBag () : Bag(T) ===
Returns a Bag containing all elements of *self*.
+
Returns a Bag containing all elements of *self*.
+
 
+-------------------------------------------------------+-----------------------+
+
{| border="1" cellpadding="5" cellspacing="0"
| Expression                                            | Result                |
+
|-
+=======================================================+=======================+
+
! style="background: #BCBCBC;" align="center"| Expression
| Sequence{'3', 1, 2.0, '3'}->asBag()                   | Bag{2.0, '3', 1, '3'} |
+
! style="background: #BCBCBC;" align="center"| Result
+-------------------------------------------------------+-----------------------+
+
|-
| Bag{1, 2.0, '3'}->asBag()                             | Bag{2.0, 1, '3'}     |
+
| Sequence{'3', 1, 2.0, '3'}->asBag()
+-------------------------------------------------------+-----------------------+
+
| Bag{2.0, '3', 1, '3'}
| OrderedSet{1, 2.0, '3'}->asBag()                     | Bag{2.0, 1, '3'}     |
+
|-
+-------------------------------------------------------+-----------------------+
+
| Bag{1, 2.0, '3'}->asBag()
| OrderedSet{1, 1, 2.0, '3'}->asBag()                   | Bag{'3', 1, 2.0}     |
+
| Bag{2.0, 1, '3'}
+-------------------------------------------------------+-----------------------+
+
|-
| Set{1, 2.0, '3'}->asBag()                             | Bag{2.0, 1, '3'}     |
+
| OrderedSet{1, 2.0, '3'}->asBag()
+-------------------------------------------------------+-----------------------+
+
| Bag{2.0, 1, '3'}
| Set{1, 1, 2.0, '3'}->asBag()                         | Bag{2.0, '3', 1}     |
+
|-
+-------------------------------------------------------+-----------------------+
+
| OrderedSet{1, 1, 2.0, '3'}->asBag()
 +
| Bag{'3', 1, 2.0}
 +
|-
 +
| Set{1, 2.0, '3'}->asBag()
 +
| Bag{2.0, 1, '3'}
 +
|-
 +
| Set{1, 1, 2.0, '3'}->asBag()
 +
| Bag{2.0, '3', 1}
 +
|}
  
  
 
=== asOrderedSet () : OrderedSet(T) ===
 
=== asOrderedSet () : OrderedSet(T) ===
Returns an OrderedSet containing all elements of *self*. Element ordering is preserved when possible.
+
Returns an OrderedSet containing all elements of *self*. Element ordering is preserved when possible.
+
 
+-------------------------------------------------------+-------------------------+
+
{| border="1" cellpadding="5" cellspacing="0"
| Expression                                            | Result                  |
+
|-
+=======================================================+=========================+
+
! style="background: #BCBCBC;" align="center"| Expression
| Sequence{1, 2.0, '3'}->asOrderedSet()                 | OrderedSet{1, '3', 2.0} |
+
! style="background: #BCBCBC;" align="center"| Result
+-------------------------------------------------------+-------------------------+
+
|-
| Sequence{1, 1, 2.0, '3'}->asOrderedSet()             | OrderedSet{'3', 1, 2.0} |
+
| Sequence{1, 2.0, '3'}->asOrderedSet()
+-------------------------------------------------------+-------------------------+
+
| OrderedSet{1, '3', 2.0}
| Bag{1, 2.0, '3'}->asOrderedSet()                     | OrderedSet{2.0, 1, '3'} |
+
|-
+-------------------------------------------------------+-------------------------+
+
| Sequence{1, 1, 2.0, '3'}->asOrderedSet()
| Bag{1, 1, 2.0, '3'}->asOrderedSet()                   | OrderedSet{1, '3', 2.0} |
+
| OrderedSet{'3', 1, 2.0}
+-------------------------------------------------------+-------------------------+
+
|-
| OrderedSet{1, 2.0, '3'}->asOrderedSet()               | OrderedSet{1, 2.0, '3'} |
+
| Bag{1, 2.0, '3'}->asOrderedSet()
+-------------------------------------------------------+-------------------------+
+
| OrderedSet{2.0, 1, '3'}
| Set{1, 2.0, '3'}->asOrderedSet()                     | OrderedSet{'3', 1, 2.0} |
+
|-
+-------------------------------------------------------+-------------------------+
+
| Bag{1, 1, 2.0, '3'}->asOrderedSet()
 +
| OrderedSet{1, '3', 2.0}
 +
|-
 +
| OrderedSet{1, 2.0, '3'}->asOrderedSet()
 +
| OrderedSet{1, 2.0, '3'}
 +
|-
 +
| Set{1, 2.0, '3'}->asOrderedSet()
 +
| OrderedSet{'3', 1, 2.0}
 +
|}
  
  
 
=== asSequence () : Boolean ===
 
=== asSequence () : Boolean ===
Returns a Sequence containing all elements of *self*. Element ordering is preserved when possible.
+
Returns a Sequence containing all elements of *self*. Element ordering is preserved when possible.
 
 
 
+-------------------------------------------------------+-----------------------+
 
+-------------------------------------------------------+-----------------------+
Line 460: Line 591:
  
 
=== asSet () : Set(T) ===
 
=== asSet () : Set(T) ===
Returns a Set containing all elements of *self*.
+
Returns a Set containing all elements of *self*.
 
 
 
+-------------------------------------------------------+-----------------------+
 
+-------------------------------------------------------+-----------------------+
Line 483: Line 614:
  
 
=== collect ( expr : OclExpression ) : Collection(T2) ===
 
=== collect ( expr : OclExpression ) : Collection(T2) ===
Returns a collection containing the result of applying *expr* on all elements contained in *self*.
+
Returns a collection containing the result of applying *expr* on all elements contained in *self*.
 
 
 
+---------------------------------------------------------------+-----------------------------+
 
+---------------------------------------------------------------+-----------------------------+
Line 493: Line 624:
  
 
=== collectNested ( expr : OclExpression ) : Collection(T2) ===
 
=== collectNested ( expr : OclExpression ) : Collection(T2) ===
Returns a collection containing all the elements contained in *self* on which we applied the OclExpression *expr*.
+
Returns a collection containing all the elements contained in *self* on which we applied the OclExpression *expr*. The results won't be flattened. The type of the resulting collection depends on the type of *self*.
The results won't be flattened. The type of the resulting collection depends on the type of *self*.
+
 
+
For the purpose of these examples we'll assume here that we have a Class *Person* with a reference *children*. Our model contains two persons such as *person1.children = {James, Jane}* and *person2.children = {John}*.
For the purpose of these examples we'll assume here that we have a Class *Person* with a reference *children*. Our
+
model contains two persons such as *person1.children = {James, Jane}* and *person2.children = {John}*.
+
 
 
 
 
Line 508: Line 637:
  
 
=== count ( object : T ) : Integer ===
 
=== count ( object : T ) : Integer ===
  Returns how many times *object* is in the collection *self*.
+
Returns how many times *object* is in the collection *self*.
  
 
   +---------------------------------------------------------------+----------------+
 
   +---------------------------------------------------------------+----------------+
Line 524: Line 653:
  
 
=== excludes ( object : T ) : Boolean ===
 
=== excludes ( object : T ) : Boolean ===
Returns **true** if *object* is not contained in *self*, **false** otherwise.
+
Returns **true** if *object* is not contained in *self*, **false** otherwise.
 
 
 
+---------------------------------------------------------------+----------------+
 
+---------------------------------------------------------------+----------------+
Line 536: Line 665:
  
 
=== excludesAll ( c2 : Collection(T) ) : Boolean ===
 
=== excludesAll ( c2 : Collection(T) ) : Boolean ===
Returns **true** if no element of *c2* is contained in *self*, **false** otherwise.
+
Returns **true** if no element of *c2* is contained in *self*, **false** otherwise.
 
 
 
+---------------------------------------------------------------+----------------+
 
+---------------------------------------------------------------+----------------+
Line 548: Line 677:
  
 
=== excluding ( object : T ) : Collection(T) ===
 
=== excluding ( object : T ) : Collection(T) ===
Returns a collection containing all elements of *self* minus all occurences of *object*.
+
Returns a collection containing all elements of *self* minus all occurences of *object*. **Note** : at the time of writing, the OCL standard library sports a bug which changes *OrderedSets* in *Sets* when excluding elements.
**Note** : at the time of writing, the OCL standard library sports a bug which changes *OrderedSets* in *Sets* when
+
excluding elements.
+
 
 
 
+-----------------------------------------------------+-------------------------+
 
+-----------------------------------------------------+-------------------------+
Line 567: Line 694:
  
 
=== exists ( expr : OclExpression ) : Boolean ===
 
=== exists ( expr : OclExpression ) : Boolean ===
Returns **true** if at least one element in *self* validates the condition *expr*, **false** otherwise. The evaluation
+
Returns **true** if at least one element in *self* validates the condition *expr*, **false** otherwise. The evaluation stops as soon as one element validating *expr* is found.
stops as soon as one element validating *expr* is found.
+
 
 
 
 
Line 580: Line 706:
  
 
=== flatten () : Collection(T2) ===
 
=== flatten () : Collection(T2) ===
Returns a collection containing all elements of *self* recursively flattened.
+
Returns a collection containing all elements of *self* recursively flattened. **Note** : at the time of writing, the OCL standard library sports a bug which changes *OrderedSets* in *Sets* when flattening.  
**Note** : at the time of writing, the OCL standard library sports a bug which changes *OrderedSets* in *Sets* when
+
flattening.  
+
 
 
 
+---------------------------------------------------------------------------+-------------------------------------+
 
+---------------------------------------------------------------------------+-------------------------------------+
Line 598: Line 722:
  
 
=== forAll ( expr : OclExpression ) : Boolean ===
 
=== forAll ( expr : OclExpression ) : Boolean ===
Returns **true** if the all the elements contained in *self* validate the condition *expr*, **false** otherwise.
+
Returns **true** if the all the elements contained in *self* validate the condition *expr*, **false** otherwise.
 
 
 
+---------------------------------------------------------------+----------------+
 
+---------------------------------------------------------------+----------------+
Line 610: Line 734:
  
 
=== includes ( object : T ) : Boolean ===
 
=== includes ( object : T ) : Boolean ===
Returns **true** if *object* is contained in *self*, **false** otherwise.
+
Returns **true** if *object* is contained in *self*, **false** otherwise.
 
 
 
+---------------------------------------------------------------+----------------+
 
+---------------------------------------------------------------+----------------+
Line 623: Line 747:
  
 
=== includesAll ( c2 : Collection(T) ) : Boolean ===
 
=== includesAll ( c2 : Collection(T) ) : Boolean ===
Returns **true** if all element of *c2* are contained in *self*, **false** otherwise.
+
Returns **true** if all element of *c2* are contained in *self*, **false** otherwise.
 
 
 
+---------------------------------------------------------------+----------------+
 
+---------------------------------------------------------------+----------------+
Line 635: Line 759:
  
 
=== including ( object : T ) : Collection(T) ===
 
=== including ( object : T ) : Collection(T) ===
Returns a collection containing all elements of *self* followed by *object*.
+
Returns a collection containing all elements of *self* followed by *object*. **Note** : at the time of writing, the OCL standard library sports a bug which changes *OrderedSets* in *Sets* when including elements.
**Note** : at the time of writing, the OCL standard library sports a bug which changes *OrderedSets* in *Sets* when
+
including elements.
+
 
 
 
+-----------------------------------------------------+-------------------------+
 
+-----------------------------------------------------+-------------------------+
Line 653: Line 775:
  
 
=== isEmpty () : Boolean ===
 
=== isEmpty () : Boolean ===
Returns **true** if *self* is empty, **false** otherwise.
+
Returns **true** if *self* is empty, **false** otherwise.
 
 
 
+---------------------------------------------------------------+----------------+
 
+---------------------------------------------------------------+----------------+
Line 667: Line 789:
  
 
=== isUnique ( expr : OclExpression ) : Boolean ===
 
=== isUnique ( expr : OclExpression ) : Boolean ===
Returns **true** if all elements contained in *self* evaluate to a distinct value for *expr*.
+
Returns **true** if all elements contained in *self* evaluate to a distinct value for *expr*.
 
 
 
+---------------------------------------------------------------+----------------+
 
+---------------------------------------------------------------+----------------+
Line 679: Line 801:
  
 
=== notEmpty () : Boolean ===
 
=== notEmpty () : Boolean ===
Returns **true** if *self* contains at least one element, **false** otherwise.
+
Returns **true** if *self* contains at least one element, **false** otherwise.
 
 
 
+---------------------------------------------------------------+----------------+
 
+---------------------------------------------------------------+----------------+
Line 693: Line 815:
  
 
=== one ( expr : OclExpression ) : Boolean ===
 
=== one ( expr : OclExpression ) : Boolean ===
Returns **true** if there is only one element contained in *self* that validates the condition *expr*, **false** otherwise.
+
Returns **true** if there is only one element contained in *self* that validates the condition *expr*, **false** otherwise.
 
 
 
+---------------------------------------------------------------+----------------+
 
+---------------------------------------------------------------+----------------+
Line 705: Line 827:
  
 
=== product ( c2 : Collection(T2) ) : Set(Tuple(first : T, second : T2)) ===
 
=== product ( c2 : Collection(T2) ) : Set(Tuple(first : T, second : T2)) ===
Returns a Set of Tuples which represents the cartesian product of *self* with *c2*.
+
Returns a Set of Tuples which represents the cartesian product of *self* with *c2*.
 
 
 
+------------------------------------------+-----------------------------------------------------------------+
 
+------------------------------------------+-----------------------------------------------------------------+
Line 717: Line 839:
  
 
=== reject ( expr : OclExpression ) : Collection(T) ===
 
=== reject ( expr : OclExpression ) : Collection(T) ===
Returns a collection with all elements of *self* except for those who validate the OclExpression *expr*.  
+
Returns a collection with all elements of *self* except for those who validate the OclExpression *expr*.  
 
 
 
+-------------------------------------------------------+-------------------------+
 
+-------------------------------------------------------+-------------------------+
Line 733: Line 855:
  
 
=== select ( expr : OclExpression ) : Collection(T) ===
 
=== select ( expr : OclExpression ) : Collection(T) ===
Returns a collection with all elements of *self* that validate the OclExpression *expr*.
+
Returns a collection with all elements of *self* that validate the OclExpression *expr*.
 
 
 
+-------------------------------------------------------+-------------------------+
 
+-------------------------------------------------------+-------------------------+
Line 748: Line 870:
  
  
=== size () : Boolean ===
+
=== size () : Integer ===
Returns the number of elements contained in *self*.
+
Returns the number of elements contained in *self*.
 
 
 
+---------------------------------------------------------------+----------------+
 
+---------------------------------------------------------------+----------------+
Line 761: Line 883:
  
 
=== sortedBy ( expr : OclExpression ) : Sequence(T) ===
 
=== sortedBy ( expr : OclExpression ) : Sequence(T) ===
Returns a sorted collection containing all elements from *self* sorted in accordance with the OclExpression *expr*.
+
Returns a sorted collection containing all elements from *self* sorted in accordance with the OclExpression *expr*.
This can be used on all kind of collections yet will always yield a Sequence-typed result except for OrderedSet which
+
This can be used on all kind of collections yet will always yield a Sequence-typed result except for OrderedSet which returns an OrderedSet.
returns an OrderedSet.
+
 
+
For the purpose of these examples we'll assume here that we have a Class *Employee* with an attribute *age*. Our model contains two employees such as *employee1.age = 24* and *employee2.age = 27*.
For the purpose of these examples we'll assume here that we have a Class *Employee* with an attribute *age*. Our
+
model contains two employees such as *employee1.age = 24* and *employee2.age = 27*.
+
 
 
 
+-------------------------------------------------------+--------------------------------+
 
+-------------------------------------------------------+--------------------------------+
Line 777: Line 897:
  
 
=== sum () : Real ===
 
=== sum () : Real ===
Returns the sum of all elements contained in *self* if they support the '+' operation.
+
Returns the sum of all elements contained in *self* if they support the '+' operation.
 
 
 
+---------------------------------------------------------------+----------------+
 
+---------------------------------------------------------------+----------------+
Line 793: Line 913:
  
 
=== = ( seq : Sequence(T) ) : Boolean ===
 
=== = ( seq : Sequence(T) ) : Boolean ===
Returns **true** if *self* contains the very same objects as *seq* in the very same order as they are in *seq*.
+
Returns **true** if *self* contains the very same objects as *seq* in the very same order as they are in *seq*.
 
 
 
+---------------------------------------------------------------+----------------+
 
+---------------------------------------------------------------+----------------+
Line 807: Line 927:
 
 
 
=== <> ( seq : Sequence(T) ) : Boolean ===
 
=== <> ( seq : Sequence(T) ) : Boolean ===
Returns **true** if *self* does not contain the same objects as *seq*, or if these objects are not in the same order
+
Returns **true** if *self* does not contain the same objects as *seq*, or if these objects are not in the same order as they are in *seq*.
as they are in *seq*.
+
 
 
+---------------------------------------------------------------+----------------+
+
+---------------------------------------------------------------+----------------+
 
| Expression                                                    | Result        |
 
| Expression                                                    | Result        |
 
+===============================================================+================+
 
+===============================================================+================+
Line 822: Line 941:
  
 
=== append ( object : T ) : Sequence(T) ===
 
=== append ( object : T ) : Sequence(T) ===
Returns a Sequence containing all elements of *self* followed by *object*.
+
Returns a Sequence containing all elements of *self* followed by *object*.
 
 
 
+-----------------------------------------------------+-------------------------+
 
+-----------------------------------------------------+-------------------------+
Line 832: Line 951:
  
 
=== at ( index : Integer ) : T ===
 
=== at ( index : Integer ) : T ===
Returns the element of *self* at the *index* position.
+
Returns the element of *self* at the *index* position.
 
 
 
+-----------------------------------------------------+-------------------------+
 
+-----------------------------------------------------+-------------------------+
Line 842: Line 961:
  
 
=== first () : T ===
 
=== first () : T ===
Returns the first element of *self*.
+
Returns the first element of *self*.
 
 
 
+-----------------------------------------------------+-------------------------+
 
+-----------------------------------------------------+-------------------------+
Line 852: Line 971:
  
 
=== indexOf ( object : T ) : Integer ===
 
=== indexOf ( object : T ) : Integer ===
Returns the position of *object* in sequence *self*.
+
Returns the position of *object* in sequence *self*.
 
 
 
+-----------------------------------------------------+-------------------------+
 
+-----------------------------------------------------+-------------------------+
Line 862: Line 981:
  
 
=== insertAt ( index : Integer, object : T) : Sequence(T) ===
 
=== insertAt ( index : Integer, object : T) : Sequence(T) ===
Returns a Sequence containing *self* with *object* inserted at the *index* position.
+
Returns a Sequence containing *self* with *object* inserted at the *index* position.
 
 
 
+-----------------------------------------------------+-------------------------+
 
+-----------------------------------------------------+-------------------------+
Line 878: Line 997:
  
 
=== last () : T ===
 
=== last () : T ===
Returns the last element of *self*.
+
Returns the last element of *self*.
 
 
 
+-----------------------------------------------------+-------------------------+
 
+-----------------------------------------------------+-------------------------+
Line 888: Line 1,007:
  
 
=== prepend ( object : T ) : Sequence(T) ===
 
=== prepend ( object : T ) : Sequence(T) ===
Returns a Sequence containing *object* followed by all elements of *self* .
+
Returns a Sequence containing *object* followed by all elements of *self* .
 
 
 
+-----------------------------------------------------+-------------------------+
 
+-----------------------------------------------------+-------------------------+
Line 898: Line 1,017:
  
 
=== subSequence ( startIndex : Integer, endIndex : Integer ) : Sequence(T) ===
 
=== subSequence ( startIndex : Integer, endIndex : Integer ) : Sequence(T) ===
Returns a Sequence containing all elements of *self* between the positions 'startIndex' and 'endIndex'.  
+
Returns a Sequence containing all elements of *self* between the positions 'startIndex' and 'endIndex'.  
 
 
 
+-----------------------------------------------------+-------------------------+
 
+-----------------------------------------------------+-------------------------+
Line 910: Line 1,029:
  
 
=== union ( seq : Sequence(T) ) : Sequence(T) ===
 
=== union ( seq : Sequence(T) ) : Sequence(T) ===
Returns a Sequence containing all elements of *self* followed by all elements of *seq*.
+
Returns a Sequence containing all elements of *self* followed by all elements of *seq*.
 
 
 
+-----------------------------------------------------+-----------------------------------+
 
+-----------------------------------------------------+-----------------------------------+
Line 922: Line 1,041:
  
 
=== = ( bag : Bag(T) ) : Boolean ===
 
=== = ( bag : Bag(T) ) : Boolean ===
Returns **true** if *self* contains the same objects as *bag* in the same quantities.
+
Returns **true** if *self* contains the same objects as *bag* in the same quantities.
 
 
 
+---------------------------------------------------------------+----------------+
 
+---------------------------------------------------------------+----------------+
Line 937: Line 1,056:
  
 
=== <> ( bag : Bag(T) ) : Boolean ===
 
=== <> ( bag : Bag(T) ) : Boolean ===
Returns **true** if *self* does not contain the same objects as *bag* in the same quantities.
+
Returns **true** if *self* does not contain the same objects as *bag* in the same quantities.
 
 
 
+---------------------------------------------------------------+----------------+
 
+---------------------------------------------------------------+----------------+
Line 952: Line 1,071:
  
 
=== intersection ( bag : Bag(T) ) : Bag(T) ===
 
=== intersection ( bag : Bag(T) ) : Bag(T) ===
Returns a Bag containing all elements of *self* that are also contained by *bag*.
+
Returns a Bag containing all elements of *self* that are also contained by *bag*.
 
 
 
+-----------------------------------------------------------+-----------------------------------+
 
+-----------------------------------------------------------+-----------------------------------+
Line 964: Line 1,083:
 
 
 
=== intersection ( set : Set(T) ) : Set(T) ===
 
=== intersection ( set : Set(T) ) : Set(T) ===
Returns a Set containing all elements of *self* that are also contained by *set*.
+
Returns a Set containing all elements of *self* that are also contained by *set*.
 
 
 
+----------------------------------------------------------+-----------------------------------+
 
+----------------------------------------------------------+-----------------------------------+
Line 974: Line 1,093:
  
 
=== 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*.
+
Returns a Bag containing all elements of *self* and all elements of *bag*.
 
 
 
+-----------------------------------------------------+-----------------------------------+
 
+-----------------------------------------------------+-----------------------------------+
Line 984: Line 1,103:
  
 
=== union ( set : Set(T) ) : Bag(T) ===
 
=== union ( set : Set(T) ) : Bag(T) ===
Returns a Bag containing all elements of *self* and all elements of *set*.
+
Returns a Bag containing all elements of *self* and all elements of *set*.
 
 
 
+-----------------------------------------------------+-----------------------------------+
 
+-----------------------------------------------------+-----------------------------------+
Line 995: Line 1,114:
 
== Ocl operations for type *OrderedSet* ==
 
== Ocl operations for type *OrderedSet* ==
 
=== = ( set : Set(T) ) : Boolean ===
 
=== = ( set : Set(T) ) : Boolean ===
Returns **true** if *self* contains the same objects as *set*.
+
Returns **true** if *self* contains the same objects as *set*.
 
 
 
+---------------------------------------------------------------+----------------+
 
+---------------------------------------------------------------+----------------+
Line 1,008: Line 1,127:
 
 
 
=== = ( orderedset : OrderedSet(T) ) : Boolean ===
 
=== = ( orderedset : OrderedSet(T) ) : Boolean ===
Returns **true** if *self* contains the same objects as *orderedset* regardless of element ordering.
+
Returns **true** if *self* contains the same objects as *orderedset* regardless of element ordering.
 
 
 
+---------------------------------------------------------------+----------------+
 
+---------------------------------------------------------------+----------------+
Line 1,024: Line 1,143:
  
 
=== <> ( set : Set(T) ) : Boolean ===
 
=== <> ( set : Set(T) ) : Boolean ===
Returns **true** if *self* does not contain the same objects as *set*.
+
Returns **true** if *self* does not contain the same objects as *set*.
 
 
 
+---------------------------------------------------------------+----------------+
 
+---------------------------------------------------------------+----------------+
Line 1,038: Line 1,157:
  
 
=== <> ( orderedset : OrderedSet(T) ) : Boolean ===
 
=== <> ( orderedset : OrderedSet(T) ) : Boolean ===
Returns **true** if *self* does not contain the same objects as *orderedset*.
+
Returns **true** if *self* does not contain the same objects as *orderedset*.
 
 
 
+---------------------------------------------------------------+----------------+
 
+---------------------------------------------------------------+----------------+
Line 1,053: Line 1,172:
  
 
=== `-` ( set : Set(T) ) : Set(T) ===
 
=== `-` ( set : Set(T) ) : Set(T) ===
Returns a Set containing all elements of *self* minus all elements of *set*.
+
Returns a Set containing all elements of *self* minus all elements of *set*.
 
 
 
+-----------------------------------------------------+-----------------------------------+
 
+-----------------------------------------------------+-----------------------------------+
Line 1,063: Line 1,182:
  
 
=== append ( object : T ) : OrderedSet(T) ===
 
=== append ( object : T ) : OrderedSet(T) ===
Returns an OrderedSet containing all elements of *self* followed by *object*.
+
Returns an OrderedSet containing all elements of *self* followed by *object*.
 
 
 
+-----------------------------------------------------+---------------------------+
 
+-----------------------------------------------------+---------------------------+
Line 1,074: Line 1,193:
  
 
=== at ( index : Integer ) : T ===
 
=== at ( index : Integer ) : T ===
Returns the element of *self* located at position *index* in the collection.
+
Returns the element of *self* located at position *index* in the collection.
 
 
 
+-----------------------------------------------------+-------------------------+
 
+-----------------------------------------------------+-------------------------+
Line 1,085: Line 1,204:
  
 
=== first () : T ===
 
=== first () : T ===
Returns the first element of *self*.
+
Returns the first element of *self*.
 
 
 
+-----------------------------------------------------+-------------------------+
 
+-----------------------------------------------------+-------------------------+
Line 1,096: Line 1,215:
  
 
=== indexOf ( object : T ) : Integer ===
 
=== indexOf ( object : T ) : Integer ===
Returns the position of *object* in *self*.
+
Returns the position of *object* in *self*.
 
 
 
+-----------------------------------------------------+-------------------------+
 
+-----------------------------------------------------+-------------------------+
Line 1,107: Line 1,226:
  
 
=== insertAt ( index : Integer, object : T ) : OrderedSet(T) ===
 
=== insertAt ( index : Integer, object : T ) : OrderedSet(T) ===
Returns an OrderedSet containing *self* with *object* inserted at the *index* position.
+
Returns an OrderedSet containing *self* with *object* inserted at the *index* position.
 
 
 
+-----------------------------------------------------+---------------------------+
 
+-----------------------------------------------------+---------------------------+
Line 1,120: Line 1,239:
  
 
=== intersection ( bag : Bag(T) ) : Set(T) ===
 
=== intersection ( bag : Bag(T) ) : Set(T) ===
Returns a Set containing all elements of *self* that are also contained by *bag*.
+
Returns a Set containing all elements of *self* that are also contained by *bag*.
 
 
 
+--------------------------------------------------------+--------------------------------+
 
+--------------------------------------------------------+--------------------------------+
Line 1,130: Line 1,249:
  
 
=== intersection ( set : Set(T) ) : Set(T) ===
 
=== intersection ( set : Set(T) ) : Set(T) ===
Returns a Set containing all elements of *self* that are also contained by *set*.
+
Returns a Set containing all elements of *self* that are also contained by *set*.
 
 
 
+--------------------------------------------------------+--------------------------------+
 
+--------------------------------------------------------+--------------------------------+
Line 1,140: Line 1,259:
  
 
=== last () : T ===
 
=== last () : T ===
Returns the last element of *self*.
+
Returns the last element of *self*.
 
 
 
+-----------------------------------------------------+-------------------------+
 
+-----------------------------------------------------+-------------------------+
Line 1,151: Line 1,270:
  
 
=== prepend ( object : T ) : OrderedSet(T) ===
 
=== prepend ( object : T ) : OrderedSet(T) ===
Returns an OrderedSet containing *object* followed by all elements of *self*.
+
Returns an OrderedSet containing *object* followed by all elements of *self*.
 
 
 
+-----------------------------------------------------+---------------------------+
 
+-----------------------------------------------------+---------------------------+
Line 1,162: Line 1,281:
  
 
=== subOrderedSet ( startIndex : Integer, endIndex : Integer ) : OrderedSet(T) ===
 
=== subOrderedSet ( startIndex : Integer, endIndex : Integer ) : OrderedSet(T) ===
Returns an OrderedSet containing all elements of *self* between the positions *startIndex* and *endIndex*.
+
Returns an OrderedSet containing all elements of *self* between the positions *startIndex* and *endIndex*.
 
 
 
+-----------------------------------------------------+---------------------------+
 
+-----------------------------------------------------+---------------------------+
Line 1,175: Line 1,294:
  
 
=== 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.
+
Returns a Set containing all of the elements of *self* and *set* that are not present in both.
 
 
 
+-------------------------------------------------------------------------+---------------+
 
+-------------------------------------------------------------------------+---------------+
Line 1,186: Line 1,305:
  
 
=== union ( bag : Bag(T) ) : Bag(T) ===
 
=== union ( bag : Bag(T) ) : Bag(T) ===
Returns a Bag containing all elements of *self* followed by all elements of *bag*.
+
Returns a Bag containing all elements of *self* followed by all elements of *bag*.
 
 
 
+-----------------------------------------------------+-----------------------------------+
 
+-----------------------------------------------------+-----------------------------------+
Line 1,196: Line 1,315:
  
 
=== union ( set : Set(T) ) : Set(T) ===
 
=== union ( set : Set(T) ) : Set(T) ===
Returns a Set containing all elements of *self* followed by all elements of *set*.
+
Returns a Set containing all elements of *self* followed by all elements of *set*.
 
 
 
+-----------------------------------------------------+-----------------------------------+
 
+-----------------------------------------------------+-----------------------------------+
Line 1,208: Line 1,327:
  
 
=== = ( set : Set(T) ) : Boolean ===
 
=== = ( set : Set(T) ) : Boolean ===
Returns **true** if *self* contains the same objects as *set*.
+
Returns **true** if *self* contains the same objects as *set*.
 
 
 
+---------------------------------------------------------------+----------------+
 
+---------------------------------------------------------------+----------------+
Line 1,223: Line 1,342:
  
 
=== <> ( set : Set(T) ) : Boolean ===
 
=== <> ( set : Set(T) ) : Boolean ===
Returns **true** if *self* does not contain the same objects as *set*.
+
Returns **true** if *self* does not contain the same objects as *set*.
 
 
 
+---------------------------------------------------------------+----------------+
 
+---------------------------------------------------------------+----------------+
Line 1,238: Line 1,357:
  
 
=== `-` ( set : Set(T) ) : Set(T) ===
 
=== `-` ( set : Set(T) ) : Set(T) ===
Returns a Set containing all elements of *self* minus all elements of *set*.
+
Returns a Set containing all elements of *self* minus all elements of *set*.
 
 
 
+-----------------------------------------------------+-----------------------------------+
 
+-----------------------------------------------------+-----------------------------------+
Line 1,249: Line 1,368:
  
 
=== 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*.
+
Returns a Bag containing all elements of *self* that are also contained in *bag*.
 
 
 
+-------------------------------------------------------+-----------------------------------+
 
+-------------------------------------------------------+-----------------------------------+
Line 1,259: Line 1,378:
  
 
=== 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*.
+
Returns a Set containing all elements of *self* that are also contained in *set*.
 
 
 
+-------------------------------------------------------+-----------------------------------+
 
+-------------------------------------------------------+-----------------------------------+
Line 1,269: Line 1,388:
  
 
=== 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.
+
Returns a Set containing all of the elements of *self* and *set* that are not present in both.
 
 
 
+------------------------------------------------------------------+-------------------------+
 
+------------------------------------------------------------------+-------------------------+
Line 1,279: Line 1,398:
  
 
=== 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*.
+
Returns a Bag containing all elements of *self* and all elements of *bag*.
 
 
 
+-----------------------------------------------------+-----------------------------------+
 
+-----------------------------------------------------+-----------------------------------+
Line 1,289: Line 1,408:
  
 
=== 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*.
+
Returns a Set containing all elements of *self* and all elements of *set*.
 
 
 
+-----------------------------------------------------+-----------------------------------+
 
+-----------------------------------------------------+-----------------------------------+
Line 1,302: Line 1,421:
 
=== And ===
 
=== And ===
  
.. list-table::
+
{| border="1" cellpadding="5" cellspacing="0"
:class: truthtable
+
|-
:header-rows: 1
+
! style="background: #BCBCBC;" align="center"| And
:stub-columns: 1
+
! style="background: #BCBCBC;" align="center"| True
         
+
! style="background: #BCBCBC;" align="center"| False
* - And
+
! style="background: #BCBCBC;" align="center"| Invalid
  - true
+
|-
  - false
+
| true
  - |invalid|
+
| true
* - true
+
| false
  - true
+
| true
  - false
+
|-
  - true
+
| false
* - false
+
| false
  - false
+
| false
  - false
+
| false
  - false
+
|-
* - |invalid|
+
| invalid
  - |invalid|
+
| invalid
  - false
+
| false
  - |invalid|
+
| invalid
 
+
|}
  
  

Revision as of 17:40, 19 January 2011

Contents

OCL operation reference

Ocl operations for type *Classifier*

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'}


Ocl operations for type *OclAny*

oclAsType ( typespec : Classifier ) : T

Returns *self* statically typed as typespec if it is an instance of this type. *Note* that this does not alter the runtime value of *self*, it only enables access to subtype operations. This operation allows users to cast self to another type.

Expression Result
aPerson.oclAsType(Employee) an object of Employee type


oclIsInvalid () : Boolean

Returns true if self is equal to *invalid*.

Expression Result
let anObject : String = null in anObject.oclIsUndefined() false
let anObject : String = invalid in anObject.oclIsUndefined() true
let anObject : String = 'null' in anObject.oclIsUndefined() false


oclIsKindOf( Classifier typespec ) : Boolean

Returns **true** if the type of self corresponds to the type or supertype of typespec, false otherwise. This operation allows users to check the class hierarchy of self much like would an instanceof Java.

Expression Result
anEmployee.oclIsKindOf(Employee) true
anEmployee.oclIsKindOf(Person) true
aCat.oclIsKindOf(Person) false


oclIsTypeOf( typespec : Classifier ) : Boolean

Returns true if the type of self is the same as typespec, or **false** otherwise. This operation allows users to check the exact class type of self.

Expression Result
anEmployee.oclIsTypeOf(Employee) true
anEmployee.oclIsTypeOf(Person) false
aCat.oclIsTypeOf(Person) false


oclIsUndefined () : Boolean

Returns **true** if *self* is equal to *invalid* or *null*.

Expression Result
let anObject : String = null in anObject.oclIsUndefined() true
let anObject : String = invalid in anObject.oclIsUndefined() true
let anObject : String = 'null' in anObject.oclIsUndefined() false


<> ( object : OclAny ) : Boolean

Returns **true** if *self* is a different object from *object*.

Expression Result
let a : String = 'a', b : String = 'a' in a <> b false
let a : Integer = 2, b : Real = 2.0 in a <> b false
let a : Integer = -2, b : Integer = 2 in a <> b true


= ( object : OclAny) : Boolean

Returns **true** if *self* is equal to *object*.

Expression Result
let a : String = 'a', b : String = 'a' in a = b true
let a : Integer = 2, b : Real = 2.0 in a = b true
let a : Integer = -2, b : Integer = 2 in a = b false


< ( object : T ) : Boolean

Returns **true** if *self* is comparable to *object* and less than *object*.

Expression Result
let a : Integer = 1, b : Integer = 2 in a < b true
let a : Real = 1.5, b : Integer = 2 in a < b true
let a : String = 'Anteater', b : String = 'Aardvark' in a < b false


> ( object : T ) : Boolean

Returns **true** if *self* is comparable to *object* and greater than *object*.

Expression Result
let a : Integer = 1, b : Integer = 2 in a > b false
let a : Real = 1.5, b : Integer = 2 in a > b false
let a : String = 'Anteater', b : String = 'Aardvark' in a > b true


<= ( object : T ) : Boolean

Returns **true** if *self* is comparable to *object* and less than or equal to *object*.

Expression Result
let a : Integer = 1, b : Integer = 2 in a <= b true
let a : Real = 1.5, b : Integer = 2 in a <= b true
let a : String = 'Anteater', b : String = 'Aardvark' in a <= b false


>= ( object : T ) : Boolean

Returns **true** if *self* is comparable to *object* and greater than or equal to *object*.

Expression Result
let a : Integer = 1, b : Integer = 2 in a >= b false
let a : Real = 1.5, b : Integer = 2 in a >= b false
let a : String = 'Anteater', b : String = 'Aardvark' in a >= b true


Ocl operations for type *String*

    • A note on Strings** : OCL Strings begin at index *1*, not *0* as in most languages. Thus *'test'.at(0)* fails in
  • invalid* whereas *'test'.at(1)* yields *'t'*. Likewise, *'test'.substring(2, 2)* returns *'e'*.

concat ( s : String ) : String

Returns a string containing *self* followed by *s*.

Expression Result
'concat'.concat(' ').concat('operation') 'concat operation'


size () : Integer

Returns the number of characters composing *self*.

Expression Result
'size operation'.size() 14


substring ( lower : Integer, upper : Integer ) : String

Returns a string containing all characters from *self* starting from index *lower* up to index *upper* included. Both *lower* and *upper* parameters should be contained between *1* and *self.size()* included. *lower* cannot be greater than *upper*.

Expression Result
'substring operation'.substring(11, 19) 'operation'
'substring operation'.substring(1, 1) 's'
'substring operation'.substring(0, 1) invalid


toInteger () : Integer

Returns an Integer of value equal to *self*, or |invalid| if *self* does not represent an integer.

Expression Result
'3.0'.toInteger() invalid
'4'.toInteger() 4
'toInteger'.toInteger() invalid


toLower () : String

Returns *self* with all characters converted to lowercase.

Expression Result
'LoWeR OpErAtIoN'.toLower() 'lower operation'


toReal () : Real

Returns a Real of value equal to *self*, or |invalid| if *self* does not represent a real.

Expression Result
'3.0'.toReal() 3.0
'4'.toReal() 4.0
'toReal'.toReal() invalid


toUpper () : String

Returns *self* with all characters converted to uppercase.

Expression Result
'UpPeR OpErAtIoN'.toUpper() 'UPPER OPERATION'


Ocl operations for type *Number*

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.

Number::abs () : Number

Returns the absolute value of *self*, *self* if it is already a positive number.

Expression Result
(-2.3).abs() 2.3
-5.abs() 5


Number::floor () : Integer

Returns the integer part of *self* if it is a Real, *self* if it is an Integer.

Expression Result
(2.3).floor() 2
(2.8).floor() 2
2.floor() 2


Number::max ( r : Number ) : Number

Returns the greatest number between *self* and *r*.

Expression Result
6.max(3) 6
6.max(5.2) 6.0
(2.3).max(3) 3.0
(2.3).max(5.2) 5.2


Number::min ( r : Number ) : Number

Returns the lowest number between *self* and *r*.

Expression Result
6.min(3) 3
6.min(5.2) 5.2
(2.3).min(3) 2.3
(2.3).min(5.2) 2.3


Number::round () : Integer

Returns the nearest integer to *self* if it is a Real, *self* if it is an Integer.

Expression Result
(2.3).round() 2
(2.5).round() 3
(2.8).round() 3
2.round() 2


Integer::div ( i : Integer ) : Integer

Returns the integer quotient of the division of *self* by *i*.

Expression Result
3.div(2) 1
11.div(3) 3


Integer::mod ( i : Integer ) : Integer

Returns the integer remainder of the division of *self* by *i*.

Expression Result
3.mod(2) 1
11.mod(3) 2


Ocl operations for type *Collection*

Please note that OCL collections can contain the *null* value (null) but not the *invalid* value (|invalid|). Trying to add |invalid| within a new or existing collection will yield |invalid| as a result. OCL proposes four distinct kinds of collections offering all possibilities of ordering/unicity.


Collection type Ordered Unique
Sequence true false
OrderedSet true true
Bag false false
Set false true


any ( expr : OclExpression ) : T

Returns any element contained in *self* that validates the condition *expr*, null otherwise. Evaluation is shortcut as soon as an element validating *expr* is found. Note that the result of this on unordered collections will be random if more than one element validates *expr*.

Expression Result
Sequence{1.2, 2.3, 5.2, 0.9}->any(self < 1) 0.9
Sequence{1.2, 2.3, 5.2, 0.9}->any(self < 2) 1.2


asBag () : Bag(T)

Returns a Bag containing all elements of *self*.

Expression Result
Sequence{'3', 1, 2.0, '3'}->asBag() Bag{2.0, '3', 1, '3'}
Bag{1, 2.0, '3'}->asBag() Bag{2.0, 1, '3'}
OrderedSet{1, 2.0, '3'}->asBag() Bag{2.0, 1, '3'}
OrderedSet{1, 1, 2.0, '3'}->asBag() Bag{'3', 1, 2.0}
Set{1, 2.0, '3'}->asBag() Bag{2.0, 1, '3'}
Set{1, 1, 2.0, '3'}->asBag() Bag{2.0, '3', 1}


asOrderedSet () : OrderedSet(T)

Returns an OrderedSet containing all elements of *self*. Element ordering is preserved when possible.

Expression Result
Sequence{1, 2.0, '3'}->asOrderedSet() OrderedSet{1, '3', 2.0}
Sequence{1, 1, 2.0, '3'}->asOrderedSet() OrderedSet{'3', 1, 2.0}
Bag{1, 2.0, '3'}->asOrderedSet() OrderedSet{2.0, 1, '3'}
Bag{1, 1, 2.0, '3'}->asOrderedSet() OrderedSet{1, '3', 2.0}
OrderedSet{1, 2.0, '3'}->asOrderedSet() OrderedSet{1, 2.0, '3'}
Set{1, 2.0, '3'}->asOrderedSet() OrderedSet{'3', 1, 2.0}


asSequence () : Boolean

Returns a Sequence containing all elements of *self*. Element ordering is preserved when possible.

+-------------------------------------------------------+-----------------------+ | Expression | Result | +=======================================================+=======================+ | Sequence{1, 2.0, '3'}->asSequence() | Sequence{1, 2.0, '3'} | +-------------------------------------------------------+-----------------------+ | Bag{1, 2.0, '3'}->asSequence() | Sequence{2.0, 1, '3'} | +-------------------------------------------------------+-----------------------+ | OrderedSet{1, 2.0, '3'}->asSequence() | Sequence{1, 2.0, '3'} | +-------------------------------------------------------+-----------------------+ | Set{1, 2.0, '3'}->asSequence() | Sequence{'3', 1, 2.0} | +-------------------------------------------------------+-----------------------+


asSet () : Set(T)

Returns a Set containing all elements of *self*.

+-------------------------------------------------------+-----------------------+ | Expression | Result | +=======================================================+=======================+ | Sequence{1, 2.0, '3'}->asSet() | Set{1, '3', 2.0} | +-------------------------------------------------------+-----------------------+ | Sequence{1, 1, 2.0, '3'}->asSet() | Set{'3', 1, 2.0} | +-------------------------------------------------------+-----------------------+ | Bag{1, 2.0, '3'}->asSet() | Set{2.0, 1, '3'} | +-------------------------------------------------------+-----------------------+ | Bag{1, 1, 2.0, '3'}->asSet() | Set{1, '3', 2.0} | +-------------------------------------------------------+-----------------------+ | OrderedSet{1, 2.0, '3'}->asSet() | Set{1, '3', 2.0} | +-------------------------------------------------------+-----------------------+ | OrderedSet{1, 1, 2.0, '3'}->asSet() | Set{'3', 1, 2.0} | +-------------------------------------------------------+-----------------------+ | Set{1, 2.0, '3'}->asSet() | Set{2.0, 1, '3'} | +-------------------------------------------------------+-----------------------+ | Set{1, 1, 2.0, '3'}->asSet() | Set{'3', 1, 2.0} | +-------------------------------------------------------+-----------------------+

collect ( expr : OclExpression ) : Collection(T2)

Returns a collection containing the result of applying *expr* on all elements contained in *self*.

+---------------------------------------------------------------+-----------------------------+ | Expression | Result | +===============================================================+=============================+ | Sequence{'first', 'second'}->collect(toUpper()) | Sequence{'FIRST', 'SECOND'} | +---------------------------------------------------------------+-----------------------------+


collectNested ( expr : OclExpression ) : Collection(T2)

Returns a collection containing all the elements contained in *self* on which we applied the OclExpression *expr*. The results won't be flattened. The type of the resulting collection depends on the type of *self*.

For the purpose of these examples we'll assume here that we have a Class *Person* with a reference *children*. Our model contains two persons such as *person1.children = {James, Jane}* and *person2.children = {John}*.


+-------------------------------------------------------+-------------------------------------------------+ | Expression | Result | +=======================================================+=================================================+ | self.persons->collectNested(children.firstname) | Sequence{Sequence{James, Jane}, Sequence{John}} | +-------------------------------------------------------+-------------------------------------------------+


count ( object : T ) : Integer

Returns how many times *object* is in the collection *self*.

  +---------------------------------------------------------------+----------------+
  | Expression                                                    | Result         |
  +===============================================================+================+
  | Sequence{2.3, 5.2}->count(5.2)                                | 1              |
  +---------------------------------------------------------------+----------------+
  | Set{3, 'test', 4.0, 4, 4.0, 'test'}->count(null)              | 0              |
  +---------------------------------------------------------------+----------------+
  | Set{3, null, 4.0, null, 'test'}->count(null)                  | 1              |
  +---------------------------------------------------------------+----------------+
  | Bag{3, null, 4.0, null, 'test'}->count(null)                  | 2              |
  +---------------------------------------------------------------+----------------+


excludes ( object : T ) : Boolean

Returns **true** if *object* is not contained in *self*, **false** otherwise.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | Sequence{2.3}->excludes(2.1) | true | +---------------------------------------------------------------+----------------+ | Sequence{2.0}->excludes(2) | false | +---------------------------------------------------------------+----------------+


excludesAll ( c2 : Collection(T) ) : Boolean

Returns **true** if no element of *c2* is contained in *self*, **false** otherwise.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | Sequence{2.3, 5.2, 'a', 3, null}->excludesAll(Set{4, null}) | false | +---------------------------------------------------------------+----------------+ | Sequence{2.3, 5.2, 'a', 3}->excludesAll(Set{4, null}) | true | +---------------------------------------------------------------+----------------+


excluding ( object : T ) : Collection(T)

Returns a collection containing all elements of *self* minus all occurences of *object*. **Note** : at the time of writing, the OCL standard library sports a bug which changes *OrderedSets* in *Sets* when excluding elements.

+-----------------------------------------------------+-------------------------+ | Expression | Result | +=====================================================+=========================+ | Sequence{'b', 'a', 'b', 'c'}->excluding('b') | Sequence{'a', 'c'} | +-----------------------------------------------------+-------------------------+ | Bag{'b', 'a', 'b', 'c'}->excluding('b') | Bag{'c', 'a'} | +-----------------------------------------------------+-------------------------+ | OrderedSet{'b', 'a', 'b', 'c'}->excluding('b') | Set{'c', 'a'} | +-----------------------------------------------------+-------------------------+ | Set{'b', 'a', 'b', 'c'}->excluding('b') | Set{'c', 'a'} | +-----------------------------------------------------+-------------------------+


exists ( expr : OclExpression ) : Boolean

Returns **true** if at least one element in *self* validates the condition *expr*, **false** otherwise. The evaluation stops as soon as one element validating *expr* is found.


+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | Sequence{2.3, 5.2}->exists(self > 3) | true | +---------------------------------------------------------------+----------------+


flatten () : Collection(T2)

Returns a collection containing all elements of *self* recursively flattened. **Note** : at the time of writing, the OCL standard library sports a bug which changes *OrderedSets* in *Sets* when flattening.

+---------------------------------------------------------------------------+-------------------------------------+ | Expression | Result | +===========================================================================+=====================================+ | Sequence{Set{1, 2, 3}, Sequence{2.0, 3.0}, Bag{'test'}}->flatten() | Sequence{1, 2, 3, 2.0, 3.0, 'test'} | +---------------------------------------------------------------------------+-------------------------------------+ | Bag{Set{Bag{'test', 2, 3.0}}, Sequence{OrderedSet{2.0, 3, 1}}}->flatten() | Bag{1, 2, 3, 2.0, 3.0, 'test'} | +---------------------------------------------------------------------------+-------------------------------------+ | OrderedSet{Set{Bag{'test', 2, 3.0}}, Sequence{Set{2.0, 3, 1}}}->flatten() | Set{3.0, 2, 1, 3, 'test', 2.0} | +---------------------------------------------------------------------------+-------------------------------------+ | Set{Set{Bag{'test', 2, 3.0}}, Sequence{OrderedSet{2.0, 3, 1}}}->flatten() | Set{3.0, 2, 1, 3, 'test', 2.0} | +---------------------------------------------------------------------------+-------------------------------------+


forAll ( expr : OclExpression ) : Boolean

Returns **true** if the all the elements contained in *self* validate the condition *expr*, **false** otherwise.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | Sequence{2.3, 5.2}->forAll(self > 3) | false | +---------------------------------------------------------------+----------------+ | Sequence{2.3, 5.2}->forAll(self > 1.2) | true | +---------------------------------------------------------------+----------------+


includes ( object : T ) : Boolean

Returns **true** if *object* is contained in *self*, **false** otherwise.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | Sequence{2.3}->includes(2.1) | false | +---------------------------------------------------------------+----------------+ | Sequence{2.0}->includes(2) | true | +---------------------------------------------------------------+----------------+


includesAll ( c2 : Collection(T) ) : Boolean

Returns **true** if all element of *c2* are contained in *self*, **false** otherwise.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | Sequence{2.3, 5.2, 'a', 3, null}->includesAll(Set{3, null}) | true | +---------------------------------------------------------------+----------------+ | Sequence{2.3, 5.2, 'a', 3}->includesAll(Set{3, null}) | false | +---------------------------------------------------------------+----------------+


including ( object : T ) : Collection(T)

Returns a collection containing all elements of *self* followed by *object*. **Note** : at the time of writing, the OCL standard library sports a bug which changes *OrderedSets* in *Sets* when including elements.

+-----------------------------------------------------+-------------------------+ | Expression | Result | +=====================================================+=========================+ | Sequence{'a', 'b'}->including('c') | Sequence{'a', 'b', 'c'} | +-----------------------------------------------------+-------------------------+ | Bag{'a', 'b'}->including('c') | Bag{'a', 'c', 'b'} | +-----------------------------------------------------+-------------------------+ | OrderedSet{'a', 'b'}->including('c') | Set{'a', 'c', 'b'} | +-----------------------------------------------------+-------------------------+ | Set{'a', 'b'}->including('c') | Set{'a', 'c', 'b'} | +-----------------------------------------------------+-------------------------+


isEmpty () : Boolean

Returns **true** if *self* is empty, **false** otherwise.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | Sequence{2, 'a'}->isEmpty() | false | +---------------------------------------------------------------+----------------+ | Sequence{null}->isEmpty() | false | +---------------------------------------------------------------+----------------+ | Sequence{}->isEmpty() | true | +---------------------------------------------------------------+----------------+


isUnique ( expr : OclExpression ) : Boolean

Returns **true** if all elements contained in *self* evaluate to a distinct value for *expr*.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | Sequence{2.3, 5.2}->isUnique(self > 3) | true | +---------------------------------------------------------------+----------------+ | Sequence{2.3, 5.2}->isUnique(self > 1) | false | +---------------------------------------------------------------+----------------+


notEmpty () : Boolean

Returns **true** if *self* contains at least one element, **false** otherwise.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | Sequence{2, 'a'}->notEmpty() | true | +---------------------------------------------------------------+----------------+ | Sequence{null}->notEmpty() | true | +---------------------------------------------------------------+----------------+ | Sequence{}->notEmpty() | false | +---------------------------------------------------------------+----------------+


one ( expr : OclExpression ) : Boolean

Returns **true** if there is only one element contained in *self* that validates the condition *expr*, **false** otherwise.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | Sequence{1.2, 2.3, 5.2, 0.9}->one(self < 1) | true | +---------------------------------------------------------------+----------------+ | Sequence{1.2, 2.3, 5.2, 0.9}->one(self < 2) | false | +---------------------------------------------------------------+----------------+


product ( c2 : Collection(T2) ) : Set(Tuple(first : T, second : T2))

Returns a Set of Tuples which represents the cartesian product of *self* with *c2*.

+------------------------------------------+-----------------------------------------------------------------+ | Expression | Result | +==========================================+=================================================================+ | Sequence{3, 4}->product(Bag{3.0, 4.0}) | Set{Tuple{3, 3.0}, Tuple{3, 4.0}, Tuple{4, 3.0}, Tuple{4, 4.0}} | +------------------------------------------+-----------------------------------------------------------------+ | Set{3, 4}->product(OrderedSet{3.0, 4.0}) | Set{Tuple{3, 3.0}, Tuple{3, 4.0}, Tuple{4, 3.0}, Tuple{4, 4.0}} | +------------------------------------------+-----------------------------------------------------------------+


reject ( expr : OclExpression ) : Collection(T)

Returns a collection with all elements of *self* except for those who validate the OclExpression *expr*.

+-------------------------------------------------------+-------------------------+ | Expression | Result | +=======================================================+=========================+ | Sequence{1, 2, 3}->reject(i : Integer | i > 1 ) | Sequence{1} | +-------------------------------------------------------+-------------------------+ | Bag{1, 2, 3}->reject(i : Integer | i > 1 ) | Bag{1} | +-------------------------------------------------------+-------------------------+ | OrderedSet{1, 2, 3}->reject(i : Integer | i > 1 ) | OrderedSet{1} | +-------------------------------------------------------+-------------------------+ | Set{1, 2, 3}->reject(i : Integer | i > 1 ) | Set{1} | +-------------------------------------------------------+-------------------------+


select ( expr : OclExpression ) : Collection(T)

Returns a collection with all elements of *self* that validate the OclExpression *expr*.

+-------------------------------------------------------+-------------------------+ | Expression | Result | +=======================================================+=========================+ | Sequence{1, 2, 3}->select(i : Integer | i > 1) | Sequence{2, 3} | +-------------------------------------------------------+-------------------------+ | Bag{1, 2, 3}->select(i : Integer | i > 1 ) | Bag{3, 2} | +-------------------------------------------------------+-------------------------+ | OrderedSet{1, 2, 3}->select(i : Integer | i > 1 ) | OrderedSet{2, 3} | +-------------------------------------------------------+-------------------------+ | Set{1, 2, 3}->select(i : Integer | i > 1 ) | Set{3, 2} | +-------------------------------------------------------+-------------------------+


size () : Integer

Returns the number of elements contained in *self*.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | Sequence{2.3, 5}->size() | 2 | +---------------------------------------------------------------+----------------+ | Sequence{}->size() | 0 | +---------------------------------------------------------------+----------------+


sortedBy ( expr : OclExpression ) : Sequence(T)

Returns a sorted collection containing all elements from *self* sorted in accordance with the OclExpression *expr*. This can be used on all kind of collections yet will always yield a Sequence-typed result except for OrderedSet which returns an OrderedSet.

For the purpose of these examples we'll assume here that we have a Class *Employee* with an attribute *age*. Our model contains two employees such as *employee1.age = 24* and *employee2.age = 27*.

+-------------------------------------------------------+--------------------------------+ | Expression | Result | +=======================================================+================================+ | self.employees->sortedBy(age) | Sequence{employee1, employee2} | +-------------------------------------------------------+--------------------------------+


sum () : Real

Returns the sum of all elements contained in *self* if they support the '+' operation.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | Sequence{2.3, 5.2} in c->sum() | 7.5 | +---------------------------------------------------------------+----------------+ | Sequence{2, 4} in c->sum() | 6 | +---------------------------------------------------------------+----------------+ | Sequence{2, '4'} in c->sum() | |invalid| | +---------------------------------------------------------------+----------------+


Ocl operations for type *Sequence*

= ( seq : Sequence(T) ) : Boolean

Returns **true** if *self* contains the very same objects as *seq* in the very same order as they are in *seq*.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | Sequence{4, 5, 'test'} = Sequence{4, 5, 'test'} | true | +---------------------------------------------------------------+----------------+ | Sequence{4, 5, 'test'} = Sequence{4, 'test', 5} | false | +---------------------------------------------------------------+----------------+ | Sequence{4, 5, 'test', 5} = Sequence{4, 5, 'test'} | false | +---------------------------------------------------------------+----------------+


<> ( seq : Sequence(T) ) : Boolean

Returns **true** if *self* does not contain the same objects as *seq*, or if these objects are not in the same order as they are in *seq*.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | Sequence{4, 5, 'test'} = Sequence{4, 5, 'test'} | false | +---------------------------------------------------------------+----------------+ | Sequence{4, 5, 'test'} = Sequence{4, 'test', 5} | true | +---------------------------------------------------------------+----------------+ | Sequence{4, 5, 'test', 5} = Sequence{4, 5, 'test'} | true | +---------------------------------------------------------------+----------------+


append ( object : T ) : Sequence(T)

Returns a Sequence containing all elements of *self* followed by *object*.

+-----------------------------------------------------+-------------------------+ | Expression | Result | +=====================================================+=========================+ | Sequence{'a', 'b'}->append('c') | Sequence{'a', 'b', 'c'} | +-----------------------------------------------------+-------------------------+


at ( index : Integer ) : T

Returns the element of *self* at the *index* position.

+-----------------------------------------------------+-------------------------+ | Expression | Result | +=====================================================+=========================+ | Sequence{'a', 'b'}->at(1) | a | +-----------------------------------------------------+-------------------------+


first () : T

Returns the first element of *self*.

+-----------------------------------------------------+-------------------------+ | Expression | Result | +=====================================================+=========================+ | Sequence{1, 2.0, '3'}->first() | 1 | +-----------------------------------------------------+-------------------------+


indexOf ( object : T ) : Integer

Returns the position of *object* in sequence *self*.

+-----------------------------------------------------+-------------------------+ | Expression | Result | +=====================================================+=========================+ | Sequence{'a', 'b'}->indexOf('a') | 1 | +-----------------------------------------------------+-------------------------+


insertAt ( index : Integer, object : T) : Sequence(T)

Returns a Sequence containing *self* with *object* inserted at the *index* position.

+-----------------------------------------------------+-------------------------+ | Expression | Result | +=====================================================+=========================+ |Sequence{'a', 'b'}->insertAt(0, 'c') | |invalid| | +-----------------------------------------------------+-------------------------+ |Sequence{'a', 'b'}->insertAt(1, 'c') | Sequence{'c', 'a', 'b'} | +-----------------------------------------------------+-------------------------+ |Sequence{'a', 'b'}->insertAt(3, 'c') | Sequence{'a', 'b', 'c'} | +-----------------------------------------------------+-------------------------+ |Sequence{'a', 'b'}->insertAt(4, 'c') | |invalid| | +-----------------------------------------------------+-------------------------+


last () : T

Returns the last element of *self*.

+-----------------------------------------------------+-------------------------+ | Expression | Result | +=====================================================+=========================+ | Sequence{1, 2.0, '3'}->last() | '3' | +-----------------------------------------------------+-------------------------+


prepend ( object : T ) : Sequence(T)

Returns a Sequence containing *object* followed by all elements of *self* .

+-----------------------------------------------------+-------------------------+ | Expression | Result | +=====================================================+=========================+ | Sequence{'a', 'b'}->prepend('c') | Sequence{'c', 'a', 'b'} | +-----------------------------------------------------+-------------------------+


subSequence ( startIndex : Integer, endIndex : Integer ) : Sequence(T)

Returns a Sequence containing all elements of *self* between the positions 'startIndex' and 'endIndex'.

+-----------------------------------------------------+-------------------------+ | Expression | Result | +=====================================================+=========================+ | Sequence{'a', 'b', 'c', 'd'}->subSequence(2, 3) | Sequence{'b', 'c'} | +-----------------------------------------------------+-------------------------+ | Sequence{'a', 'b', 'c', 'd'}->subSequence(4, 4) | Sequence{'d'} | +-----------------------------------------------------+-------------------------+


union ( seq : Sequence(T) ) : Sequence(T)

Returns a Sequence containing all elements of *self* followed by all elements of *seq*.

+-----------------------------------------------------+-----------------------------------+ | Expression | Result | +=====================================================+===================================+ | Sequence{'a', 'b', 'a'}->union(Sequence{'b', 'c'}) | Sequence{'a', 'b', 'a', 'b', 'c'} | +-----------------------------------------------------+-----------------------------------+


Ocl operations for type *Bag*

= ( bag : Bag(T) ) : Boolean

Returns **true** if *self* contains the same objects as *bag* in the same quantities.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | Bag{4, 5, 'test', 4} = Bag{4, 'test', 5, 4} | true | +---------------------------------------------------------------+----------------+ | Bag{4, 5, 'test'} = Bag{4, 'test', 5} | true | +---------------------------------------------------------------+----------------+ | Bag{4, 5, 'test', 5} = Bag{4, 5, 'test'} | false | +---------------------------------------------------------------+----------------+


<> ( bag : Bag(T) ) : Boolean

Returns **true** if *self* does not contain the same objects as *bag* in the same quantities.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | Bag{4, 5, 'test'} = Bag{4, 5, 'test'} | false | +---------------------------------------------------------------+----------------+ | Bag{4, 5, 'test'} = Bag{4, 'test', 5} | false | +---------------------------------------------------------------+----------------+ | Bag{4, 5, 'test', 5} = Bag{4, 5, 'test'} | true | +---------------------------------------------------------------+----------------+


intersection ( bag : Bag(T) ) : Bag(T)

Returns a Bag containing all elements of *self* that are also contained by *bag*.

+-----------------------------------------------------------+-----------------------------------+ | Expression | Result | +===========================================================+===================================+ | Bag{'a', 'b', 'a'}->intersection(Bag{'a', 'b'}) | Bag{'a', 'b'} | +-----------------------------------------------------------+-----------------------------------+ | Bag{'a', 'b', 'a', 'b'}->intersection(Bag{'a', 'b', 'b'}) | Bag{'b', 'a', 'b'} | +-----------------------------------------------------------+-----------------------------------+


intersection ( set : Set(T) ) : Set(T)

Returns a Set containing all elements of *self* that are also contained by *set*.

+----------------------------------------------------------+-----------------------------------+ | Expression | Result | +==========================================================+===================================+ | Bag{'a', 'b', 'a'}->intersection(Set{'a', 'b', 'c'}) | Set{'a', 'b'} | +----------------------------------------------------------+-----------------------------------+


union ( bag : Bag(T) ) : Bag(T)

Returns a Bag containing all elements of *self* and all elements of *bag*.

+-----------------------------------------------------+-----------------------------------+ | Expression | Result | +=====================================================+===================================+ | Bag{'a', 'b', 'a'}->union(Bag{'b', 'c'}) | Bag{'b', 'a', 'b', 'a', 'c'} | +-----------------------------------------------------+-----------------------------------+


union ( set : Set(T) ) : Bag(T)

Returns a Bag containing all elements of *self* and all elements of *set*.

+-----------------------------------------------------+-----------------------------------+ | Expression | Result | +=====================================================+===================================+ | Bag{'a', 'b', 'a'}->union(Set{'b', 'c'}) | Bag{'b', 'c', 'a', 'b', 'a'} | +-----------------------------------------------------+-----------------------------------+


Ocl operations for type *OrderedSet*

= ( set : Set(T) ) : Boolean

Returns **true** if *self* contains the same objects as *set*.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | OrderedSet{3, 5, 4} = Set{3, 5, 4} | true | +---------------------------------------------------------------+----------------+ | OrderedSet{3, 5, 4} = Set{4, 3, 5, 4, 4} | true | +---------------------------------------------------------------+----------------+ | OrderedSet{3, 5, 4} = Set{2, 5 ,4, 4} | false | +---------------------------------------------------------------+----------------+

= ( orderedset : OrderedSet(T) ) : Boolean

Returns **true** if *self* contains the same objects as *orderedset* regardless of element ordering.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | OrderedSet{3, 5, 4} = OrderedSet{3, 5, 4} | true | +---------------------------------------------------------------+----------------+ | OrderedSet{4, 5, 'test', 5} = OrderedSet{4, 5, 'test'} | true | +---------------------------------------------------------------+----------------+ | OrderedSet{4, 5, 'test'} = OrderedSet{4, 'test', 5} | true | +---------------------------------------------------------------+----------------+ | OrderedSet{4, 5, 'test'} = OrderedSet{4, 'test'} | false | +---------------------------------------------------------------+----------------+


<> ( set : Set(T) ) : Boolean

Returns **true** if *self* does not contain the same objects as *set*.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | OrderedSet{4, 5, 'test', 4} <> Set{4, 5, 'test'} | false | +---------------------------------------------------------------+----------------+ | OrderedSet{4, 5, 'test', 4} <> Set{4, 'test', 5, 4} | false | +---------------------------------------------------------------+----------------+ | OrderedSet{4, 5, 'test', 4} <> Set{4, 5, 'test', 2} | true | +---------------------------------------------------------------+----------------+


<> ( orderedset : OrderedSet(T) ) : Boolean

Returns **true** if *self* does not contain the same objects as *orderedset*.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | OrderedSet{4, 5, 'test', 4} <> OrderedSet{4, 5, 'test') | false | +---------------------------------------------------------------+----------------+ | OrderedSet{4, 5, 'test', 4} <> OrderedSet{4, 'test', 5, 4} | false | +---------------------------------------------------------------+----------------+ | OrderedSet{4, 5, 'test', 4} <> OrderedSet{4, 5, 'test', 2} | true | +---------------------------------------------------------------+----------------+


`-` ( set : Set(T) ) : Set(T)

Returns a Set containing all elements of *self* minus all elements of *set*.

+-----------------------------------------------------+-----------------------------------+ | Expression | Result | +=====================================================+===================================+ | OrderedSet{'a', 'b', 'c'} - Set{'c', 'a'} | Set{'b'} | +-----------------------------------------------------+-----------------------------------+


append ( object : T ) : OrderedSet(T)

Returns an OrderedSet containing all elements of *self* followed by *object*.

+-----------------------------------------------------+---------------------------+ | Expression | Result | +=====================================================+===========================+ | OrderedSet{'a', 'b'}->append('c') | OrderedSet{'a', 'b', 'c'} | +-----------------------------------------------------+---------------------------+


at ( index : Integer ) : T

Returns the element of *self* located at position *index* in the collection.

+-----------------------------------------------------+-------------------------+ | Expression | Result | +=====================================================+=========================+ | OrderedSet{'a', 'b'}->at(1) | 'a' | +-----------------------------------------------------+-------------------------+


first () : T

Returns the first element of *self*.

+-----------------------------------------------------+-------------------------+ | Expression | Result | +=====================================================+=========================+ | OrderedSet{1, 2.0, '3'}->first() | 1 | +-----------------------------------------------------+-------------------------+


indexOf ( object : T ) : Integer

Returns the position of *object* in *self*.

+-----------------------------------------------------+-------------------------+ | Expression | Result | +=====================================================+=========================+ | OrderedSet{'a', 'b'}->indexOf('a') | 1 | +-----------------------------------------------------+-------------------------+


insertAt ( index : Integer, object : T ) : OrderedSet(T)

Returns an OrderedSet containing *self* with *object* inserted at the *index* position.

+-----------------------------------------------------+---------------------------+ | Expression | Result | +=====================================================+===========================+ | OrderedSet{'a', 'b'}->insertAt(1, 'c') | OrderedSet{'c', 'a', 'b'} | +-----------------------------------------------------+---------------------------+ | OrderedSet{'a', 'b'}->insertAt(3, 'c') | OrderedSet{'a', 'b', 'c'} | +-----------------------------------------------------+---------------------------+


intersection ( bag : Bag(T) ) : Set(T)

Returns a Set containing all elements of *self* that are also contained by *bag*.

+--------------------------------------------------------+--------------------------------+ | Expression | Result | +========================================================+================================+ | OrderedSet{'a', 'b', 'a'}->intersection(Bag{'a', 'b'}) | Set{'a', 'b'} | +--------------------------------------------------------+--------------------------------+


intersection ( set : Set(T) ) : Set(T)

Returns a Set containing all elements of *self* that are also contained by *set*.

+--------------------------------------------------------+--------------------------------+ | Expression | Result | +========================================================+================================+ | OrderedSet{'a', 'b', 'a'}->intersection(Set{'a', 'b'}) | Set{'b', 'a'} | +--------------------------------------------------------+--------------------------------+


last () : T

Returns the last element of *self*.

+-----------------------------------------------------+-------------------------+ | Expression | Result | +=====================================================+=========================+ |OrderedSet{1, 2.0, '3'}->last() | '3' | +-----------------------------------------------------+-------------------------+


prepend ( object : T ) : OrderedSet(T)

Returns an OrderedSet containing *object* followed by all elements of *self*.

+-----------------------------------------------------+---------------------------+ | Expression | Result | +=====================================================+===========================+ | OrderedSet{'a', 'b'}->prepend('c') | OrderedSet{'c', 'a', 'b'} | +-----------------------------------------------------+---------------------------+


subOrderedSet ( startIndex : Integer, endIndex : Integer ) : OrderedSet(T)

Returns an OrderedSet containing all elements of *self* between the positions *startIndex* and *endIndex*.

+-----------------------------------------------------+---------------------------+ | Expression | Result | +=====================================================+===========================+ | OrderedSet{'a', 'b', 'c', 'd'}->subOrderedSet(2, 3) | OrderedSet{'b', 'c'} | +-----------------------------------------------------+---------------------------+ | OrderedSet{'a', 'b', 'c', 'd'}->subOrderedSet(4, 4) | OrderedSet{'d'} | +-----------------------------------------------------+---------------------------+


symmetricDifference ( set : Set(T) ) : Set(T)

Returns a Set containing all of the elements of *self* and *set* that are not present in both.

+-------------------------------------------------------------------------+---------------+ | Expression | Result | +=========================================================================+===============+ | OrderedSet{'b', 'a', 'b', 'c'}->symmetricDifference(Set{'a', 'c', 'd'}) | Set{'d', 'b'} | +-------------------------------------------------------------------------+---------------+


union ( bag : Bag(T) ) : Bag(T)

Returns a Bag containing all elements of *self* followed by all elements of *bag*.

+-----------------------------------------------------+-----------------------------------+ | Expression | Result | +=====================================================+===================================+ | OrderedSet{'a', 'b', 'a'}->union(Bag{'b', 'c'}) | Bag{'a', 'c', 'b', 'b'} | +-----------------------------------------------------+-----------------------------------+


union ( set : Set(T) ) : Set(T)

Returns a Set containing all elements of *self* followed by all elements of *set*.

+-----------------------------------------------------+-----------------------------------+ | Expression | Result | +=====================================================+===================================+ | OrderedSet{'a', 'b', 'a'}->union(Set{'b', 'c'}) | Set{'a', 'c', 'b'} | +-----------------------------------------------------+-----------------------------------+


Ocl operations for type *Set*

= ( set : Set(T) ) : Boolean

Returns **true** if *self* contains the same objects as *set*.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | Set{3, 5, 4} = Set{3, 5, 4} | true | +---------------------------------------------------------------+----------------+ | Set{3, 5, 4} = Set{3, 4, 4, 5} | true | +---------------------------------------------------------------+----------------+ | Set{3, 5, 4} = Set{2, 3, 5, 4} | false | +---------------------------------------------------------------+----------------+


<> ( set : Set(T) ) : Boolean

Returns **true** if *self* does not contain the same objects as *set*.

+---------------------------------------------------------------+----------------+ | Expression | Result | +===============================================================+================+ | Set{4, 5, 'test', 4} <> Set{4, 5, 'test'} | false | +---------------------------------------------------------------+----------------+ | Set{4, 5, 'test', 4} <> Set{5, 4, 'test', 4} | false | +---------------------------------------------------------------+----------------+ | Set{4, 5, 'test', 4} <> Set{4, 'test', 5, 2} | true | +---------------------------------------------------------------+----------------+


`-` ( set : Set(T) ) : Set(T)

Returns a Set containing all elements of *self* minus all elements of *set*.

+-----------------------------------------------------+-----------------------------------+ | Expression | Result | +=====================================================+===================================+ | Set{'a', 'b', 'c'} - Set{'c', 'a'} | Set{'b'} | +-----------------------------------------------------+-----------------------------------+


intersection ( bag : Bag(T) ) : Set(T)

Returns a Bag containing all elements of *self* that are also contained in *bag*.

+-------------------------------------------------------+-----------------------------------+ | Expression | Result | +=======================================================+===================================+ | Set{'a', 'b', 'a'}->intersection(Bag{'a', 'b', 'c'}) | Set{'a', 'b'} | +-------------------------------------------------------+-----------------------------------+


intersection ( set : Set(T) ) : Set(T)

Returns a Set containing all elements of *self* that are also contained in *set*.

+-------------------------------------------------------+-----------------------------------+ | Expression | Result | +=======================================================+===================================+ | Set{'a', 'b', 'a'}->intersection(Set{'a', 'b', 'c'}) | Set{'b', 'a'} | +-------------------------------------------------------+-----------------------------------+


symmetricDifference ( set : Set(T) ) : Set(T)

Returns a Set containing all of the elements of *self* and *set* that are not present in both.

+------------------------------------------------------------------+-------------------------+ | Expression | Result | +==================================================================+=========================+ | Set{'b', 'a', 'b', 'c'}->symmetricDifference(Set{'a', 'c', 'd'}) | Set{'b', 'd'} | +------------------------------------------------------------------+-------------------------+


union ( bag : Bag(T) ) : Bag(T)

Returns a Bag containing all elements of *self* and all elements of *bag*.

+-----------------------------------------------------+-----------------------------------+ | Expression | Result | +=====================================================+===================================+ | Set{'a', 'b', 'a'}->union(Bag{'b', 'c'}) | Bag{'a', 'c', 'b', 'b'} | +-----------------------------------------------------+-----------------------------------+


union ( set : Set(T) ) : Set(T)

Returns a Set containing all elements of *self* and all elements of *set*.

+-----------------------------------------------------+-----------------------------------+ | Expression | Result | +=====================================================+===================================+ | Set{'a', 'b', 'a'}->union(Set{'b', 'c'}) | Set{'a', 'c', 'b'} | +-----------------------------------------------------+-----------------------------------+


Ocl operations for type *Boolean*

And

And True False Invalid
true true false true
false false false false
invalid invalid false invalid


Implies

.. list-table:: :class: truthtable :header-rows: 1 :stub-columns: 1

* - Implies - true - false - |invalid| * - true - true - false - |invalid| * - false - true - true - true * - |invalid| - true - |invalid| - |invalid|


Or

.. list-table:: :class: truthtable :header-rows: 1 :stub-columns: 1

* - Or - true - false - |invalid| * - true - true - true - true * - false - true - false - |invalid| * - |invalid| - true - |invalid| - |invalid|


Not

.. list-table:: :class: truthtable :header-rows: 1 :stub-columns: 1

* - Not - Result * - true - false * - false - true * - |invalid| - |invalid|


Xor

.. list-table:: :class: truthtable :header-rows: 1 :stub-columns: 1

* - Xor - true - false - |invalid| * - true - false - true - |invalid| * - false - true - false - |invalid| * - |invalid| - |invalid| - |invalid| - |invalid|



Acceleo Portal
Project Project · Installation
Features Acceleo Features · Runtime · Acceleo editor · Views & Perspective · Interpreter · Maven
User documentation Getting Started · User Guide · Acceleo operations reference · OCL operations reference · Text Production Rules · Migration From Acceleo 2.x · Best Practices · Videos · FAQ
Developer documentation Source code · How to contribute · Compatibility · MOFM2T specification · OCL specification
Community Professional Support · Report a bug

Back to the top