Professional Documents
Culture Documents
OCL operations
reference
Authors:
Contact:
Laurent Goubet
Laurent Delaigue
laurent.goubet@obeo.fr,
laurent.delaigue@obeo.fr
1/36
23/10/2014
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
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
Result
Set{'a','b'}
Back to Contents
3/36
23/10/2014
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
4/36
23/10/2014
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
5/36
23/10/2014
6/36
23/10/2014
Result
true
true
false
Back to Contents
Result
false
false
true
Back to Contents
7/36
23/10/2014
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
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
'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
9/36
23/10/2014
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
Result
6
6.0
3.0
5.2
Back to Contents
10/36
23/10/2014
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
Result
1
3
Back to Contents
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
11.mod(3)
Back to Contents
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
>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
>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
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
Back to Contents
Result
Sequence{Sequence{James,
Jane}, Sequence{John}}
Back to Contents
Result
1
0
1
2
Back to Contents
15/36
23/10/2014
Expression
Sequence{2.3}->excludes(2.1)
Sequence{2.0}->excludes(2)
Result
true
false
Back to Contents
Result
false
true
Back to Contents
Result
Sequence{'a',
'c'}
Bag{'c', 'a'}
Set{'c', 'a'}
Set{'c', 'a'}
Back to Contents
16/36
23/10/2014
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
Result
false
true
Back to Contents
17/36
23/10/2014
Result
false
true
Back to Contents
Result
true
false
Back to Contents
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
examples:
Expression
Sequence{2, 'a'}->isEmpty()
Sequence{null}->isEmpty()
Sequence{}->isEmpty()
Result
false
false
true
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
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
>one(self < 1)
Sequence{1.2, 2.3, 5.2, 0.9}>one(self < 2)
false
Back to Contents
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
Result
Sequence{1}
Bag{1}
OrderedSet{1}
Set{1}
Back to Contents
20/36
23/10/2014
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
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
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
Result
true
false
false
Back to Contents
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
Sequence{4, 'test', 5}
Sequence{4, 5, 'test', 5} =
Sequence{4, 5, 'test'}
true
Back to Contents
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
Result
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html
23/36
23/10/2014
Sequence{'a', 'b'}>indexOf('a')
Back to Contents
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
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
Result
Sequence{'b',
'c'}
Sequence{'d'}
Back to Contents
Result
Sequence{'a',
'b', 'a', 'b', 'c'}
Back to Contents
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
Result
false
false
true
Back to Contents
Result
Bag{'a', 'b'}
Bag{'b', 'a', 'b'}
Back to Contents
Result
Set{'a', 'b'}
Back to Contents
26/36
23/10/2014
examples:
Expression
Bag{'a', 'b', 'a'}>union(Bag{'b', 'c'})
Result
Bag{'b', 'a', 'b',
'a', 'c'}
Back to Contents
Result
Bag{'b', 'c', 'a',
'b', 'a'}
Back to Contents
27/36
23/10/2014
OrderedSet{4, 5, 'test'}
OrderedSet{4, 5, 'test'} =
OrderedSet{4, 'test', 5}
OrderedSet{4, 5, 'test'} =
OrderedSet{4, 'test'}
true
false
Back to Contents
Result
false
false
true
Back to Contents
Result
false
false
true
Back to Contents
Result
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html
28/36
23/10/2014
Set{'b'}
Back to Contents
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
Result
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.acceleo.doc%2Fdoc%2Fhtml%2Focl_operation_reference.html
29/36
23/10/2014
OrderedSet{'a', 'b'}>indexOf('a')
Back to Contents
Result
OrderedSet{'c',
'a', 'b'}
OrderedSet{'a',
'b', 'c'}
Back to Contents
Result
Set{'a', 'b'}
Back to Contents
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
Result
'3'
Back to Contents
Result
OrderedSet{'c',
'a', 'b'}
Back to Contents
Result
OrderedSet{'b',
'c'}
OrderedSet{'d'}
Back to Contents
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
>symmetricDifference(Set{'a', 'c',
'd'})
'b'}
Back to Contents
Result
Bag{'a', 'c', 'b',
'b'}
Back to Contents
Result
Set{'a', 'c', 'b'}
Back to Contents
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
Result
false
false
true
Back to Contents
Result
Set{'b'}
Back to Contents
Result
Set{'a', 'b'}
Back to Contents
33/36
23/10/2014
Expression
Set{'a', 'b', 'a'}>intersection(Set{'a', 'b',
'c'})
Result
Set{'b', 'a'}
Back to Contents
Result
Set{'b', 'd'}
Back to Contents
Result
Bag{'a', 'c', 'b',
'b'}
Back to Contents
Result
Set{'a', 'c', 'b'}
Back to Contents
34/36
23/10/2014
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
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