You are on page 1of 36

23/10/2014

Help - Eclipse Platform

Acceleo Model To Text Transformation Language (MTL) > User Guide

OCL operations
reference
Authors:
Contact:

Laurent Goubet
Laurent Delaigue
laurent.goubet@obeo.fr,
laurent.delaigue@obeo.fr

Copyright 2009, 2010 Obeo.


Contents
Ocl operations for type Classifier
allInstances () : Set{T}
Ocl operations for type OclAny
oclAsType ( typespec : Classifier ) : T
oclIsInvalid () : Boolean
oclIsKindOf( Classifier typespec ) : Boolean
oclIsTypeOf( typespec : Classifier ) : Boolean
oclIsUndefined () : Boolean
<> ( object : OclAny ) : Boolean
= ( object : OclAny) : Boolean
< ( object : T ) : Boolean
> ( object : T ) : Boolean
<= ( object : T ) : Boolean
>= ( object : T ) : Boolean
Ocl operations for type String
concat ( s : String ) : String
size () : Integer
substring ( lower : Integer, upper : Integer ) : String
toInteger () : Integer
toLower () : String
toReal () : Real
toUpper () : String
Ocl operations for type Number
Number::abs () : Number
Number::floor () : Integer
Number::max ( r : Number ) : Number
Number::min ( r : Number ) : Number
Number::round () : Integer
Integer::div ( i : Integer ) : Integer
Integer::mod ( i : Integer ) : Integer
Ocl operations for type Collection
any ( expr : OclExpression ) : T
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

1/36

23/10/2014

Help - Eclipse Platform

asBag () : Bag(T)
asOrderedSet () : OrderedSet(T)
asSequence () : Boolean
asSet () : Set(T)
collect ( expr : OclExpression ) : Collection(T2)
collectNested ( expr : OclExpression ) : Collection(T2)
count ( object : T ) : Integer
excludes ( object : T ) : Boolean
excludesAll ( c2 : Collection(T) ) : Boolean
excluding ( object : T ) : Collection(T)
exists ( expr : OclExpression ) : Boolean
flatten () : Collection(T2)
forAll ( expr : OclExpression ) : Boolean
includes ( object : T ) : Boolean
includesAll ( c2 : Collection(T) ) : Boolean
including ( object : T ) : Collection(T)
isEmpty () : Boolean
isUnique ( expr : OclExpression ) : Boolean
notEmpty () : Boolean
one ( expr : OclExpression ) : Boolean
product ( c2 : Collection(T2) ) : Set(Tuple(first : T, second : T2))
reject ( expr : OclExpression ) : Collection(T)
select ( expr : OclExpression ) : Collection(T)
size () : Integer
sortedBy ( expr : OclExpression ) : Sequence(T)
sum () : Real
Ocl operations for type Sequence
= ( seq : Sequence(T) ) : Boolean
<> ( seq : Sequence(T) ) : Boolean
append ( object : T ) : Sequence(T)
at ( index : Integer ) : T
first () : T
indexOf ( object : T ) : Integer
insertAt ( index : Integer, object : T) : Sequence(T)
last () : T
prepend ( object : T ) : Sequence(T)
subSequence ( startIndex : Integer, endIndex : Integer ) :
Sequence(T)
union ( seq : Sequence(T) ) : Sequence(T)
Ocl operations for type Bag
= ( bag : Bag(T) ) : Boolean
<> ( bag : Bag(T) ) : Boolean
intersection ( bag : Bag(T) ) : Bag(T)
intersection ( set : Set(T) ) : Set(T)
union ( bag : Bag(T) ) : Bag(T)
union ( set : Set(T) ) : Bag(T)
Ocl operations for type OrderedSet
= ( set : Set(T) ) : Boolean
= ( orderedset : OrderedSet(T) ) : Boolean
<> ( set : Set(T) ) : Boolean
<> ( orderedset : OrderedSet(T) ) : Boolean
- ( set : Set(T) ) : Set(T)
append ( object : T ) : OrderedSet(T)
at ( index : Integer ) : T
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

2/36

23/10/2014

Help - Eclipse Platform

first () : T
indexOf ( object : T ) : Integer
insertAt ( index : Integer, object : T ) : OrderedSet(T)
intersection ( bag : Bag(T) ) : Set(T)
intersection ( set : Set(T) ) : Set(T)
last () : T
prepend ( object : T ) : OrderedSet(T)
subOrderedSet ( startIndex : Integer, endIndex : Integer ) :
OrderedSet(T)
symmetricDifference ( set : Set(T) ) : Set(T)
union ( bag : Bag(T) ) : Bag(T)
union ( set : Set(T) ) : Set(T)
Ocl operations for type Set
= ( set : Set(T) ) : Boolean
<> ( set : Set(T) ) : Boolean
- ( set : Set(T) ) : Set(T)
intersection ( bag : Bag(T) ) : Set(T)
intersection ( set : Set(T) ) : Set(T)
symmetricDifference ( set : Set(T) ) : Set(T)
union ( bag : Bag(T) ) : Bag(T)
union ( set : Set(T) ) : Set(T)
Ocl operations for type Boolean
And
Implies
Or
Not
Xor
Glossary

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).
examples:
Expression
let a : String = 'a', b : String = 'b',
c : Integer = 2 in
String.allInstances()

Result
Set{'a','b'}

Back to Contents

Ocl operations for type OclAny


http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

3/36

23/10/2014

Help - Eclipse Platform

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.
examples:
Expression
aPerson.oclAsType(Employee)

Result
an object of
Employee
type

Back to Contents

oclIsInvalid () : Boolean
Returns true if self is equal to invalid.
examples:
Expression
let anObject : String = null in
anObject.oclIsUndefined()
let anObject : String = invalid in
anObject.oclIsUndefined()
let anObject : String = 'null' in
anObject.oclIsUndefined()

Result
false
true
false

Back to Contents

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.
examples:
Expression
Result
anEmployee.oclIsKindOf(Employee) true
anEmployee.oclIsKindOf(Person)
true
aCat.oclIsKindOf(Person)
false
Back to Contents
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

4/36

23/10/2014

Help - Eclipse Platform

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.
examples:
Expression
Result
anEmployee.oclIsTypeOf(Employee) true
anEmployee.oclIsTypeOf(Person)
false
aCat.oclIsTypeOf(Person)
false
Back to Contents

oclIsUndefined () : Boolean
Returns true if self is equal to invalid or null.
examples:
Expression
let anObject : String = null in
anObject.oclIsUndefined()
let anObject : String = invalid in
anObject.oclIsUndefined()
let anObject : String = 'null' in
anObject.oclIsUndefined()

Result
true
true
false

Back to Contents

<> ( object : OclAny ) : Boolean


Returns true if self is a different object from object.
examples:
Expression
Result
let a : String = 'a', b : String = 'a' in a
false
<> b
let a : Integer = 2, b : Real = 2.0 in a
false
<> b
let a : Integer = -2, b : Integer = 2 in a
true
<> b
Back to Contents
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

5/36

23/10/2014

Help - Eclipse Platform

= ( object : OclAny) : Boolean


Returns true if self is equal to object.
examples:
Expression
Result
let a : String = 'a', b : String = 'a' in a = true
b
let a : Integer = 2, b : Real = 2.0 in a = true
b
let a : Integer = -2, b : Integer = 2 in a
false
=b
Back to Contents

< ( object : T ) : Boolean


Returns true if self is comparable to object and less than object.
examples:
Expression
Result
let a : Integer = 1, b : Integer = 2 in a < true
b
let a : Real = 1.5, b : Integer = 2 in a < true
b
let a : String = 'Anteater', b : String =
false
'Aardvark' in a < b
Back to Contents

> ( object : T ) : Boolean


Returns true if self is comparable to object and greater than object.
examples:
Expression
Result
let a : Integer = 1, b : Integer = 2 in a > false
b
let a : Real = 1.5, b : Integer = 2 in a > false
b
let a : String = 'Anteater', b : String =
true
'Aardvark' in a > b
Back to Contents
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

6/36

23/10/2014

Help - Eclipse Platform

<= ( object : T ) : Boolean


Returns true if self is comparable to object and less than or equal to
object.
examples:
Expression
let a : Integer = 1, b : Integer = 2 in a
<= b
let a : Real = 1.5, b : Integer = 2 in a
<= b
let a : String = 'Anteater', b : String =
'Aardvark' in a <= b

Result
true
true
false

Back to Contents

>= ( object : T ) : Boolean


Returns true if self is comparable to object and greater than or equal
to object.
examples:
Expression
let a : Integer = 1, b : Integer = 2 in a
>= b
let a : Real = 1.5, b : Integer = 2 in a
>= b
let a : String = 'Anteater', b : String =
'Aardvark' in a >= b

Result
false
false
true

Back to Contents

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.
examples:
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

7/36

23/10/2014

Help - Eclipse Platform

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

Result
'concat
operation'

Back to Contents

size () : Integer
Returns the number of characters composing self.
examples:
Expression
'size operation'.size()

Result
14

Back to Contents

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.
examples:
Expression
'substring
operation'.substring(11, 19)
'substring operation'.substring(1,
1)
'substring operation'.substring(0,
1)

Result
'operation'
's'

Back to Contents

toInteger () : Integer
Returns an Integer of value equal to self, or if self does not
represent an integer.
examples:
Expression
'3.0'.toInteger()

Result

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

8/36

23/10/2014

Help - Eclipse Platform

'4'.toInteger()
'toInteger'.toInteger()

Back to Contents

toLower () : String
Returns self with all characters converted to lowercase.
examples:
Expression
'LoWeR OpErAtIoN'.toLower()

Result
'lower
operation'

Back to Contents

toReal () : Real
Returns a Real of value equal to self, or if self does not represent a
real.
examples:
Expression
'3.0'.toReal()
'4'.toReal()
'toReal'.toReal()

Result
3.0
4.0

Back to Contents

toUpper () : String
Returns self with all characters converted to uppercase.
examples:
Expression
'UpPeR
OpErAtIoN'.toUpper()

Result
'UPPER
OPERATION'

Back to Contents

Ocl operations for type Number


http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

9/36

23/10/2014

Help - Eclipse Platform

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.
examples:
Expression
(-2.3).abs()
-5.abs()

Result
2.3
5

Back to Contents

Number::floor () : Integer
Returns the integer part of self if it is a Real, self if it is an Integer.
examples:
Expression
(2.3).floor()
(2.8).floor()
2.floor()

Result
2
2
2

Back to Contents

Number::max ( r : Number ) : Number


Returns the greatest number between self and r.
examples:
Expression
6.max(3)
6.max(5.2)
(2.3).max(3)
(2.3).max(5.2)

Result
6
6.0
3.0
5.2

Back to Contents

Number::min ( r : Number ) : Number


http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

10/36

23/10/2014

Help - Eclipse Platform

Returns the lowest number between self and r.


examples:
Expression
6.min(3)
6.min(5.2)
(2.3).min(3)
(2.3).min(5.2)

Result
6
5.2
2.3
2.3

Back to Contents

Number::round () : Integer
Returns the nearest integer to self if it is a Real, self if it is an Integer.
examples:
Expression
(2.3).round()
(2.5).round()
(2.8).round()
2.round()

Result
2
3
3
2

Back to Contents

Integer::div ( i : Integer ) : Integer


Returns the integer quotient of the division of self by i.
examples:
Expression
3.div(2)
11.div(3)

Result
1
3

Back to Contents

Integer::mod ( i : Integer ) : Integer


Returns the integer remainder of the division of self by i.
examples:
Expression
3.mod(2)

Result
1

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

11/36

23/10/2014

Help - Eclipse Platform

11.mod(3)

Back to Contents

Ocl operations for type Collection


Please note that OCL collections can contain the null value (null) but not the
invalid value (). Trying to add within a new or existing collection will yield
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
Back to Contents

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.
examples:
Expression
Sequence{1.2, 2.3, 5.2, 0.9}>any(self < 1)
Sequence{1.2, 2.3, 5.2, 0.9}>any(self < 2)

Result
0.9
1.2

Back to Contents

asBag () : Bag(T)
Returns a Bag containing all elements of self.
examples:
Expression
Sequence{'3', 1, 2.0, '3'}-

Result
Bag{2.0,

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

12/36

23/10/2014

Help - Eclipse Platform

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

'3', 1, '3'}
Bag{2.0, 1,
'3'}
Bag{2.0, 1,
'3'}
Bag{'3', 1,
2.0}
Bag{2.0, 1,
'3'}
Bag{2.0,
'3', 1}

Back to Contents

asOrderedSet () : OrderedSet(T)
Returns an OrderedSet containing all elements of self. Element
ordering is preserved when possible.
examples:
Expression
Sequence{1, 2.0, '3'}>asOrderedSet()
Sequence{1, 1, 2.0, '3'}>asOrderedSet()
Bag{1, 2.0, '3'}>asOrderedSet()
Bag{1, 1, 2.0, '3'}>asOrderedSet()
OrderedSet{1, 2.0, '3'}>asOrderedSet()
Set{1, 2.0, '3'}>asOrderedSet()

Result
OrderedSet{1,
'3', 2.0}
OrderedSet{'3',
1, 2.0}
OrderedSet{2.0,
1, '3'}
OrderedSet{1,
'3', 2.0}
OrderedSet{1,
2.0, '3'}
OrderedSet{'3',
1, 2.0}

Back to Contents

asSequence () : Boolean
Returns a Sequence containing all elements of self. Element ordering
is preserved when possible.
examples:
Expression
Sequence{1, 2.0, '3'}>asSequence()
Bag{1, 2.0, '3'}-

Result
Sequence{1,
2.0, '3'}
Sequence{2.0,

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

13/36

23/10/2014

Help - Eclipse Platform

>asSequence()
OrderedSet{1, 2.0, '3'}>asSequence()
Set{1, 2.0, '3'}>asSequence()

1, '3'}
Sequence{1,
2.0, '3'}
Sequence{'3',
1, 2.0}

Back to Contents

asSet () : Set(T)
Returns a Set containing all elements of self.
examples:
Expression
Sequence{1, 2.0, '3'}->asSet()
Sequence{1, 1, 2.0, '3'}>asSet()
Bag{1, 2.0, '3'}->asSet()
Bag{1, 1, 2.0, '3'}->asSet()
OrderedSet{1, 2.0, '3'}->asSet()
OrderedSet{1, 1, 2.0, '3'}>asSet()
Set{1, 2.0, '3'}->asSet()
Set{1, 1, 2.0, '3'}->asSet()

Result
Set{1, '3',
2.0}
Set{'3', 1,
2.0}
Set{2.0, 1,
'3'}
Set{1, '3',
2.0}
Set{1, '3',
2.0}
Set{'3', 1,
2.0}
Set{2.0, 1,
'3'}
Set{'3', 1,
2.0}

Back to Contents

collect ( expr : OclExpression ) :


Collection(T2)
Returns a collection containing the result of applying expr on all
elements contained in self.
examples:
Expression
Sequence{'first',
'second'}>collect(toUpper())

Result
Sequence{'FIRST',
'SECOND'}

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

14/36

23/10/2014

Help - Eclipse Platform

Back to Contents

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.
examples:
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
self.persons>collectNested(children.firstname)

Result
Sequence{Sequence{James,
Jane}, Sequence{John}}

Back to Contents

count ( object : T ) : Integer


Returns how many times object is in the collection self.
examples:
Expression
Sequence{2.3, 5.2}->count(5.2)
Set{3, 'test', 4.0, 4, 4.0, 'test'}>count(null)
Set{3, null, 4.0, null, 'test'}>count(null)
Bag{3, null, 4.0, null, 'test'}>count(null)

Result
1
0
1
2

Back to Contents

excludes ( object : T ) : Boolean


Returns true if object is not contained in self, false otherwise.
examples:
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

15/36

23/10/2014

Help - Eclipse Platform

Expression
Sequence{2.3}->excludes(2.1)
Sequence{2.0}->excludes(2)

Result
true
false

Back to Contents

excludesAll ( c2 : Collection(T) ) : Boolean


Returns true if no element of c2 is contained in self, false otherwise.
examples:
Expression
Sequence{2.3, 5.2, 'a', 3, null}>excludesAll(Set{4, null})
Sequence{2.3, 5.2, 'a', 3}>excludesAll(Set{4, null})

Result
false
true

Back to Contents

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.
examples:
Expression
Sequence{'b', 'a', 'b', 'c'}>excluding('b')
Bag{'b', 'a', 'b', 'c'}>excluding('b')
OrderedSet{'b', 'a', 'b', 'c'}>excluding('b')
Set{'b', 'a', 'b', 'c'}>excluding('b')

Result
Sequence{'a',
'c'}
Bag{'c', 'a'}
Set{'c', 'a'}
Set{'c', 'a'}

Back to Contents

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.
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

16/36

23/10/2014

Help - Eclipse Platform

examples:
Expression
Result
Sequence{2.3, 5.2}->exists(self > 3) true
Back to Contents

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.
examples:
Expression
Sequence{Set{1, 2, 3},
Sequence{2.0, 3.0},
Bag{'test'}}->flatten()
Bag{Set{Bag{'test', 2, 3.0}},
Sequence{OrderedSet{2.0, 3,
1}}}->flatten()
OrderedSet{Set{Bag{'test', 2,
3.0}}, Sequence{Set{2.0, 3,
1}}}->flatten()
Set{Set{Bag{'test', 2, 3.0}},
Sequence{OrderedSet{2.0, 3,
1}}}->flatten()

Result
Sequence{1,
2, 3, 2.0, 3.0,
'test'}
Bag{1, 2, 3,
2.0, 3.0,
'test'}
Set{3.0, 2, 1,
3, 'test', 2.0}
Set{3.0, 2, 1,
3, 'test', 2.0}

Back to Contents

forAll ( expr : OclExpression ) : Boolean


Returns true if the all the elements contained in self validate the
condition expr, false otherwise.
examples:
Expression
Sequence{2.3, 5.2}->forAll(self > 3)
Sequence{2.3, 5.2}->forAll(self >
1.2)

Result
false
true

Back to Contents

includes ( object : T ) : Boolean


http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

17/36

23/10/2014

Help - Eclipse Platform

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


examples:
Expression
Sequence{2.3}->includes(2.1)
Sequence{2.0}->includes(2)

Result
false
true

Back to Contents

includesAll ( c2 : Collection(T) ) : Boolean


Returns true if all element of c2 are contained in self, false otherwise.
examples:
Expression
Sequence{2.3, 5.2, 'a', 3, null}>includesAll(Set{3, null})
Sequence{2.3, 5.2, 'a', 3}>includesAll(Set{3, null})

Result
true
false

Back to Contents

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.
examples:
Expression
Sequence{'a', 'b'}>including('c')
Bag{'a', 'b'}->including('c')
OrderedSet{'a', 'b'}>including('c')
Set{'a', 'b'}->including('c')

Result
Sequence{'a',
'b', 'c'}
Bag{'a', 'c',
'b'}
Set{'a', 'c', 'b'}
Set{'a', 'c', 'b'}

Back to Contents

isEmpty () : Boolean
Returns true if self is empty, false otherwise.
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

18/36

23/10/2014

Help - Eclipse Platform

examples:
Expression
Sequence{2, 'a'}->isEmpty()
Sequence{null}->isEmpty()
Sequence{}->isEmpty()

Result
false
false
true

Back to Contents

isUnique ( expr : OclExpression ) : Boolean


Returns true if all elements contained in self evaluate to a distinct
value for expr.
examples:
Expression
Result
Sequence{2.3, 5.2}->isUnique(self > true
3)
Sequence{2.3, 5.2}->isUnique(self > false
1)
Back to Contents

notEmpty () : Boolean
Returns true if self contains at least one element, false otherwise.
examples:
Expression
Sequence{2, 'a'}->notEmpty()
Sequence{null}->notEmpty()
Sequence{}->notEmpty()

Result
true
true
false

Back to Contents

one ( expr : OclExpression ) : Boolean


Returns true if there is only one element contained in self that
validates the condition expr, false otherwise.
examples:
Expression
Sequence{1.2, 2.3, 5.2, 0.9}-

Result
true

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

19/36

23/10/2014

Help - Eclipse Platform

>one(self < 1)
Sequence{1.2, 2.3, 5.2, 0.9}>one(self < 2)

false

Back to Contents

product ( c2 : Collection(T2) ) : Set(Tuple(first


: T, second : T2))
Returns a Set of Tuples which represents the cartesian product of self
with c2.
examples (notation of the tuples has been simplified):
Expression
Sequence{3, 4}>product(Bag{3.0, 4.0})
Set{3, 4}>product(OrderedSet{3.0,
4.0})

Result
Set{Tuple{3, 3.0},
Tuple{3, 4.0},
Tuple{4, 3.0},
Tuple{4, 4.0}}
Set{Tuple{3, 3.0},
Tuple{3, 4.0},
Tuple{4, 3.0},
Tuple{4, 4.0}}

Back to Contents

reject ( expr : OclExpression ) : Collection(T)


Returns a collection with all elements of self except for those who
validate the OclExpression expr.
examples:
Expression
Sequence{1, 2, 3}->reject(i :
Integer | i > 1 )
Bag{1, 2, 3}->reject(i :
Integer | i > 1 )
OrderedSet{1, 2, 3}->reject(i
: Integer | i > 1 )
Set{1, 2, 3}->reject(i : Integer
|i>1)

Result
Sequence{1}
Bag{1}
OrderedSet{1}
Set{1}

Back to Contents

select ( expr : OclExpression ) : Collection(T)


http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

20/36

23/10/2014

Help - Eclipse Platform

Returns a collection with all elements of self that validate the


OclExpression expr.
examples:
Expression
Sequence{1, 2, 3}->select(i :
Integer | i > 1)
Bag{1, 2, 3}->select(i :
Integer | i > 1 )
OrderedSet{1, 2, 3}->select(i
: Integer | i > 1 )
Set{1, 2, 3}->select(i :
Integer | i > 1 )

Result
Sequence{2,
3}
Bag{3, 2}
OrderedSet{2,
3}
Set{3, 2}

Back to Contents

size () : Integer
Returns the number of elements contained in self.
examples:
Expression
Sequence{2.3, 5}->size()
Sequence{}->size()

Result
2
0

Back to Contents

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.
examples:
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
self.employees>sortedBy(age)

Result
Sequence{employee1,
employee2}

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

21/36

23/10/2014

Help - Eclipse Platform

Back to Contents

sum () : Real
Returns the sum of all elements contained in self if they support the '+'
operation.
examples:
Expression
Sequence{2.3, 5.2} in c->sum()
Sequence{2, 4} in c->sum()
Sequence{2, '4'} in c->sum()

Result
7.5
6

Back to Contents

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.
examples:
Expression
Sequence{4, 5, 'test'} =
Sequence{4, 5, 'test'}
Sequence{4, 5, 'test'} =
Sequence{4, 'test', 5}
Sequence{4, 5, 'test', 5} =
Sequence{4, 5, 'test'}

Result
true
false
false

Back to Contents

<> ( 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.
examples:
Expression
Sequence{4, 5, 'test'} =
Sequence{4, 5, 'test'}
Sequence{4, 5, 'test'} =

Result
false
true

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

22/36

23/10/2014

Help - Eclipse Platform

Sequence{4, 'test', 5}
Sequence{4, 5, 'test', 5} =
Sequence{4, 5, 'test'}

true

Back to Contents

append ( object : T ) : Sequence(T)


Returns a Sequence containing all elements of self followed by object.
examples:
Expression
Sequence{'a', 'b'}>append('c')

Result
Sequence{'a',
'b', 'c'}

Back to Contents

at ( index : Integer ) : T
Returns the element of self at the index position.
examples:
Expression
Sequence{'a', 'b'}->at(1)

Result
a

Back to Contents

first () : T
Returns the first element of self.
examples:
Expression
Sequence{1, 2.0, '3'}->first()

Result
1

Back to Contents

indexOf ( object : T ) : Integer


Returns the position of object in sequence self.
examples:
Expression

Result

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

23/36

23/10/2014

Help - Eclipse Platform

Sequence{'a', 'b'}>indexOf('a')

Back to Contents

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


Returns a Sequence containing self with object inserted at the index
position.
examples:
Expression
Sequence{'a', 'b'}->insertAt(0,
'c')
Sequence{'a', 'b'}->insertAt(1,
'c')
Sequence{'a', 'b'}->insertAt(3,
'c')
Sequence{'a', 'b'}->insertAt(4,
'c')

Result

Sequence{'c',
'a', 'b'}
Sequence{'a',
'b', 'c'}

Back to Contents

last () : T
Returns the last element of self.
examples:
Expression
Sequence{1, 2.0, '3'}->last()

Result
'3'

Back to Contents

prepend ( object : T ) : Sequence(T)


Returns a Sequence containing object followed by all elements of self
.
examples:
Expression
Sequence{'a', 'b'}>prepend('c')

Result
Sequence{'c',
'a', 'b'}

Back to Contents
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

24/36

23/10/2014

Help - Eclipse Platform

subSequence ( startIndex : Integer, endIndex :


Integer ) : Sequence(T)
Returns a Sequence containing all elements of self between the
positions 'startIndex' and 'endIndex'.
examples:
Expression
Sequence{'a', 'b', 'c', 'd'}>subSequence(2, 3)
Sequence{'a', 'b', 'c', 'd'}>subSequence(4, 4)

Result
Sequence{'b',
'c'}
Sequence{'d'}

Back to Contents

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


Returns a Sequence containing all elements of self followed by all
elements of seq.
examples:
Expression
Sequence{'a', 'b', 'a'}>union(Sequence{'b', 'c'})

Result
Sequence{'a',
'b', 'a', 'b', 'c'}

Back to Contents

Ocl operations for type Bag


= ( bag : Bag(T) ) : Boolean
Returns true if self contains the same objects as bag in the same
quantities.
examples:
Expression
Bag{4, 5, 'test', 4} = Bag{4, 'test', 5,
4}
Bag{4, 5, 'test'} = Bag{4, 'test', 5}
Bag{4, 5, 'test', 5} = Bag{4, 5, 'test'}

Result
true
true
false

Back to Contents

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

25/36

23/10/2014

Help - Eclipse Platform

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


Returns true if self does not contain the same objects as bag in the
same quantities.
examples:
Expression
Bag{4, 5, 'test'} = Bag{4, 5, 'test'}
Bag{4, 5, 'test'} = Bag{4, 'test', 5}
Bag{4, 5, 'test', 5} = Bag{4, 5, 'test'}

Result
false
false
true

Back to Contents

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


Returns a Bag containing all elements of self that are also contained
by bag.
examples:
Expression
Bag{'a', 'b', 'a'}>intersection(Bag{'a', 'b'})
Bag{'a', 'b', 'a', 'b'}>intersection(Bag{'a', 'b',
'b'})

Result
Bag{'a', 'b'}
Bag{'b', 'a', 'b'}

Back to Contents

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


Returns a Set containing all elements of self that are also contained
by set.
examples:
Expression
Bag{'a', 'b', 'a'}>intersection(Set{'a', 'b',
'c'})

Result
Set{'a', 'b'}

Back to Contents

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


Returns a Bag containing all elements of self and all elements of bag.
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

26/36

23/10/2014

Help - Eclipse Platform

examples:
Expression
Bag{'a', 'b', 'a'}>union(Bag{'b', 'c'})

Result
Bag{'b', 'a', 'b',
'a', 'c'}

Back to Contents

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


Returns a Bag containing all elements of self and all elements of set.
examples:
Expression
Bag{'a', 'b', 'a'}>union(Set{'b', 'c'})

Result
Bag{'b', 'c', 'a',
'b', 'a'}

Back to Contents

Ocl operations for type OrderedSet


= ( set : Set(T) ) : Boolean
Returns true if self contains the same objects as set.
examples:
Expression
Result
OrderedSet{3, 5, 4} = Set{3, 5, 4}
true
OrderedSet{3, 5, 4} = Set{4, 3, 5, 4, true
4}
OrderedSet{3, 5, 4} = Set{2, 5 ,4, 4} false
Back to Contents

= ( orderedset : OrderedSet(T) ) : Boolean


Returns true if self contains the same objects as orderedset
regardless of element ordering.
examples:
Expression
Result
OrderedSet{3, 5, 4} = OrderedSet{3, true
5, 4}
OrderedSet{4, 5, 'test', 5} =
true
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

27/36

23/10/2014

Help - Eclipse Platform

OrderedSet{4, 5, 'test'}
OrderedSet{4, 5, 'test'} =
OrderedSet{4, 'test', 5}
OrderedSet{4, 5, 'test'} =
OrderedSet{4, 'test'}

true
false

Back to Contents

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


Returns true if self does not contain the same objects as set.
examples:
Expression
OrderedSet{4, 5, 'test', 4} <> Set{4,
5, 'test'}
OrderedSet{4, 5, 'test', 4} <> Set{4,
'test', 5, 4}
OrderedSet{4, 5, 'test', 4} <> Set{4,
5, 'test', 2}

Result
false
false
true

Back to Contents

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


Returns true if self does not contain the same objects as orderedset.
examples:
Expression
OrderedSet{4, 5, 'test', 4} <>
OrderedSet{4, 5, 'test')
OrderedSet{4, 5, 'test', 4} <>
OrderedSet{4, 'test', 5, 4}
OrderedSet{4, 5, 'test', 4} <>
OrderedSet{4, 5, 'test', 2}

Result
false
false
true

Back to Contents

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


Returns a Set containing all elements of self minus all elements of
set.
examples:
Expression

Result

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

28/36

23/10/2014

Help - Eclipse Platform

OrderedSet{'a', 'b', 'c'} Set{'c', 'a'}

Set{'b'}

Back to Contents

append ( object : T ) : OrderedSet(T)


Returns an OrderedSet containing all elements of self followed by
object.
examples:
Expression
OrderedSet{'a', 'b'}>append('c')

Result
OrderedSet{'a',
'b', 'c'}

Back to Contents

at ( index : Integer ) : T
Returns the element of self located at position index in the collection.
examples:
Expression
OrderedSet{'a', 'b'}->at(1)

Result
'a'

Back to Contents

first () : T
Returns the first element of self.
examples:
Expression
OrderedSet{1, 2.0, '3'}->first()

Result
1

Back to Contents

indexOf ( object : T ) : Integer


Returns the position of object in self.
examples:
Expression

Result

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

29/36

23/10/2014

Help - Eclipse Platform

OrderedSet{'a', 'b'}>indexOf('a')

Back to Contents

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


Returns an OrderedSet containing self with object inserted at the
index position.
examples:
Expression
OrderedSet{'a', 'b'}>insertAt(1, 'c')
OrderedSet{'a', 'b'}>insertAt(3, 'c')

Result
OrderedSet{'c',
'a', 'b'}
OrderedSet{'a',
'b', 'c'}

Back to Contents

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


Returns a Set containing all elements of self that are also contained
by bag.
examples:
Expression
OrderedSet{'a', 'b', 'a'}>intersection(Bag{'a', 'b'})

Result
Set{'a', 'b'}

Back to Contents

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


Returns a Set containing all elements of self that are also contained
by set.
examples:
Expression
OrderedSet{'a', 'b', 'a'}>intersection(Set{'a', 'b'})

Result
Set{'b', 'a'}

Back to Contents

last () : T
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

30/36

23/10/2014

Help - Eclipse Platform

Returns the last element of self.


examples:
Expression
OrderedSet{1, 2.0, '3'}->last()

Result
'3'

Back to Contents

prepend ( object : T ) : OrderedSet(T)


Returns an OrderedSet containing object followed by all elements of
self.
examples:
Expression
OrderedSet{'a', 'b'}>prepend('c')

Result
OrderedSet{'c',
'a', 'b'}

Back to Contents

subOrderedSet ( startIndex : Integer, endIndex :


Integer ) : OrderedSet(T)
Returns an OrderedSet containing all elements of self between the
positions startIndex and endIndex.
examples:
Expression
OrderedSet{'a', 'b', 'c', 'd'}>subOrderedSet(2, 3)
OrderedSet{'a', 'b', 'c', 'd'}>subOrderedSet(4, 4)

Result
OrderedSet{'b',
'c'}
OrderedSet{'d'}

Back to Contents

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


Returns a Set containing all of the elements of self and set that are
not present in both.
examples:
Expression
OrderedSet{'b', 'a', 'b', 'c'}-

Result
Set{'d',

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

31/36

23/10/2014

Help - Eclipse Platform

>symmetricDifference(Set{'a', 'c',
'd'})

'b'}

Back to Contents

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


Returns a Bag containing all elements of self followed by all elements
of bag.
examples:
Expression
OrderedSet{'a', 'b', 'a'}>union(Bag{'b', 'c'})

Result
Bag{'a', 'c', 'b',
'b'}

Back to Contents

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


Returns a Set containing all elements of self followed by all elements
of set.
examples:
Expression
OrderedSet{'a', 'b', 'a'}>union(Set{'b', 'c'})

Result
Set{'a', 'c', 'b'}

Back to Contents

Ocl operations for type Set


= ( set : Set(T) ) : Boolean
Returns true if self contains the same objects as set.
examples:
Expression
Set{3, 5, 4} = Set{3, 5, 4}
Set{3, 5, 4} = Set{3, 4, 4, 5}
Set{3, 5, 4} = Set{2, 3, 5, 4}

Result
true
true
false

Back to Contents

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

32/36

23/10/2014

Help - Eclipse Platform

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


Returns true if self does not contain the same objects as set.
examples:
Expression
Set{4, 5, 'test', 4} <> Set{4, 5, 'test'}
Set{4, 5, 'test', 4} <> Set{5, 4, 'test',
4}
Set{4, 5, 'test', 4} <> Set{4, 'test', 5,
2}

Result
false
false
true

Back to Contents

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


Returns a Set containing all elements of self minus all elements of
set.
examples:
Expression
Set{'a', 'b', 'c'} - Set{'c', 'a'}

Result
Set{'b'}

Back to Contents

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


Returns a Bag containing all elements of self that are also contained
in bag.
examples:
Expression
Set{'a', 'b', 'a'}>intersection(Bag{'a', 'b',
'c'})

Result
Set{'a', 'b'}

Back to Contents

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


Returns a Set containing all elements of self that are also contained in
set.
examples:
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

33/36

23/10/2014

Help - Eclipse Platform

Expression
Set{'a', 'b', 'a'}>intersection(Set{'a', 'b',
'c'})

Result
Set{'b', 'a'}

Back to Contents

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


Returns a Set containing all of the elements of self and set that are
not present in both.
examples:
Expression
Set{'b', 'a', 'b', 'c'}>symmetricDifference(Set{'a', 'c',
'd'})

Result
Set{'b', 'd'}

Back to Contents

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


Returns a Bag containing all elements of self and all elements of bag.
examples:
Expression
Set{'a', 'b', 'a'}>union(Bag{'b', 'c'})

Result
Bag{'a', 'c', 'b',
'b'}

Back to Contents

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


Returns a Set containing all elements of self and all elements of set.
examples:
Expression
Set{'a', 'b', 'a'}>union(Set{'b', 'c'})

Result
Set{'a', 'c', 'b'}

Back to Contents

Ocl operations for type Boolean


http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

34/36

23/10/2014

Help - Eclipse Platform

And
And true false
true true
false
false false false

false

true
false

Back to Contents

Implies
Implies true false
true
true false
false
true true

true

true

Back to Contents

Or
Or true false
true
true true
false true false

true

true

Back to Contents

Not
Not
true
false

Result
false
true

Back to Contents

Xor
Xor true false
true
false true
false true
false

Back to Contents

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

35/36

23/10/2014

Help - Eclipse Platform

Glossary
invalid
invalid is the singleton instance of the OCLInvalid type. It is
returned whenever an evaluation fails, whatever the cause.
Referred to as in this guide.

See invalid.
Back to Contents

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html

36/36

You might also like