kermeta::standard
Class Abstract Collection[G] inherited from Object



Collection is the root abstract class for all kermeta collections

@CompilerIgnore "true"
@ScalaCompilerName "k2.standard.Collection"

Method Summary
Void
add()


Adds an element in the Collection (default implementation)


           
Void
addAll[T](Collection)


Adds all elements from the Collection elements in the current Collection
Standard implementation relies on Collection[G].add(G)


           
Void
addSafe(Object)


Adds an element in the Collection if it is of compatible with the collection content


           

any()


Returns an element from the Collection
Raises an EmptyCollection exception if the Collection is empty


           
Bag[G]
asBag()


Returns a new Bag built from the Collection


           
OrderedSet[G]
asOrderedSet()


Returns a new OrderedSet built from the Collection


           
Sequence[G]
asSequence()


Returns a new Sequence built from the Collection


           
Sequence[Y]
asSequenceType[Y]()


Returns a new Sequence built from the Collection and filtering only the elements of type Y
This is a more efficient version of
e.select{ elem | elem.isInstanceOf(Y) }.collect{elem | elem.asType(Y) }


           
Set[G]
asSet()


Returns a new Set built from the Collection


           
Void
clear()


Removes all elements from the Collection


           
Sequence[T]
collect[T]()


Returns a new Sequence which content corresponds to the result
of running the collector function for each element of the Collection
The new collection size is the same as in the original collection, and which element types is the type of the result of the expression.
example :
aCollection2 := aCollection.collect { e | \/* put here an expression, for example e.name *\/ }


           
Boolean
contains()


Returns a Boolean stating whether the Collection contains at least one
instance of element, based on G.equals(elt : Object) definition
Note: for checking whether a physical element is contained by the collection,
make use of G.oid()


           
Boolean
containsAll(Collection)


Returns true if current Collection contains at least one instance
of each element of Collection elements
See Collection[G].contains(G)
Standard implementation relies on Collection[G].contains(G)


           
Integer
count()


Returns the number of instances of element in the Collection


           

detect()


Returns an element of the Collection (usually the first) for which the detector function
is true
Returns void if no elements is validated by the detector function
example :
anObject := aCollection.detect { e | \/* a condition *\/} // returns an element that fulfill the condition.


           
Void
each()


Runs function func on each element of the Collection.
Each is safe against concurrent modifications: even if the collection is modified by the function func,
the iteration will procede on the original collection safely.

Example :
aCollection.each { e | \/* do something with each element e of this collection *\/ }


           
Boolean
empty()


Returns a Boolean stating whether the Collection is empty


           
Boolean
excludes()


Returns true if the Collection does not contain element


           
Boolean
excludesAll(Collection)


Returns true if the Collection contains no element of Collection elements
Standard implementation relies on excludes


           
Boolean
exists()


Returns a Boolean stating whether at least one element of the Collection
validates the condition specified by function func
example :
aBoolean := aCollection.exists { e | \/* a condition *\/} // returns true if at least one element fulfill the condition.


           
Boolean
existsCpl()


Combinaison of exists on two elements in the collection
result := self.exists{x | self.exists {y | f(x,y)}}


           
Boolean
forAll()


Returns a Boolean stating whether no element of the Collection invalidates
the condition specified by function func
example :
aBoolean := aCollection.forAll { e | \/* put here a condition *\/ } // return true if the condition is true for all elements in the collection.


           
Boolean
forAllCpl()


Combinaison of ForAll on two elements in the collection
result := self.forAll{x | self.forAll {y | f(x,y)}}
(where x and y are 2 elements of the Collection)
typical use sample : ownedState.forAllCpl{s1,s2| (s1.name==s2.name).implies(s1==s2)}


           
Boolean
includes()


OCL API alignment, does the same as contains
See Collection.contains(Object)
Standard implementation relies on Collection[G].contains(G)


           
Boolean
includesAll(Collection)


OCL API alignment, does the same as containsAll
See Collection.containsAll(Collection[G])
Standard implementation relies on containsAll


           
Void
indexedEach()


Runs function func on each element of the Collection.
The EachContext variable contains informations about the process that can be used in the function func.
The iteration order is guaranteed only for ordered collections.
IndexedEach is safe against concurrent modifications: even if the collection is modified by the lambda func,
the iteration will procede on the original collection safely.

Typical use:
aCollection.indexedEach { e, eachContext |
stdio.write("element "+ eachContext.index.toString + ": " + e.toString)
if(!eachContext.isLast) then stdio.writeln(",") end
}
This example prints every element of the collection with its rank and adds a comma at the end of the line
only if it is relevant.

See also EachContext.


           
Boolean
isEmpty()


OCL alignment API, does the same as empty
See Collection[G].empty()
Standard implementation relies on Collection[G].empty())


           
Boolean
isNotEmpty()


OCL alignment API
Returns a Boolean stating whether the Collection contains at least
one element
See also Collection[G].empty()
Standard implementation relies on Collection[G].empty()


           
Boolean
isUnique[T]()


Returns a Boolean stating whether the collector function evaluates to a
different value for each element of the Collection
example :
aCollection2 := aCollection.isUnique { e | \/* put here an expression that must be unique for all elements, for example e.name *\/ }


           
Iterator[G]
iterator()


Returns an Iterator on the Collection


           

one()


Returns an element from the Collection or void if the Collection is empty


           
Sequence[G]
reject()


Returns a new Sequence composed of elements of the Collection that
do not validate the rejector function
example :
aCollection2 := aCollection.reject { e |
\/* put here a condition that returns true for elements that must be exclude in the resulting Collection *\/
}


           
Void
remove()


Removes all instances of element from the Collection, based on
G.equals(Object) definition


           
Sequence[G]
select()


Returns a new Sequence composed of elements of the Collection that
validate the selector function
example :
aCollection2 := aCollection.select { e |
\/* put here a condition that returns true for elements that must be included in the resulting Collection *\/
}


           
Sequence[G]
selectOne()


Returns a new Sequence containing one element of the Collection that
validates the selector function or an empty Sequence if no element
validates the selector function
example :
aCollection2 := aCollection.selectOne { e |
\/* put here a condition that returns true for the element that must be included in the resulting Collection *\/
}


           
Integer
size()


Returns the number of elements in the Collection


           

sum()


Sum the elements of the collection if they are summable (ie implement '+' operator by inheriting of the class Summable).
Returns void otherwise.


           


Details of operations

add

Void add[()


Adds an element in the Collection (default implementation)

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;951;994"

addAll

Void addAll[T](Collection)


Adds all elements from the Collection elements in the current Collection
Standard implementation relies on Collection[G].add(G)

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;1561;1627"

addSafe

Void addSafe[(Object)


Adds an element in the Collection if it is of compatible with the collection content

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;1098;1150"

any

 any[()


Returns an element from the Collection
Raises an EmptyCollection exception if the Collection is empty

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;4050;4080"

asBag

Bag[G] asBag[()


Returns a new Bag built from the Collection

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;9470;9507"

asOrderedSet

OrderedSet[G] asOrderedSet[()


Returns a new OrderedSet built from the Collection

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;9960;10011"

asSequence

Sequence[G] asSequence[()


Returns a new Sequence built from the Collection

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;10078;10125"

asSequenceType

Sequence[Y] asSequenceType[Y]()


Returns a new Sequence built from the Collection and filtering only the elements of type Y
This is a more efficient version of
e.select{ elem | elem.isInstanceOf(Y) }.collect{elem | elem.asType(Y) }

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;9834;9891"

asSet

Set[G] asSet[()


Returns a new Set built from the Collection

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;9570;9607"

clear

Void clear[()


Removes all elements from the Collection

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;1374;1410"

collect

Sequence[T] collect[T]()


Returns a new Sequence which content corresponds to the result
of running the collector function for each element of the Collection
The new collection size is the same as in the original collection, and which element types is the type of the result of the expression.
example :
aCollection2 := aCollection.collect { e | \/* put here an expression, for example e.name *\/ }

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;7042;7111"

contains

Boolean contains[()


Returns a Boolean stating whether the Collection contains at least one
instance of element, based on G.equals(elt : Object) definition
Note: for checking whether a physical element is contained by the collection,
make use of G.oid()

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;1891;1944"

containsAll

Boolean containsAll[(Collection)


Returns true if current Collection contains at least one instance
of each element of Collection elements
See Collection[G].contains(G)
Standard implementation relies on Collection[G].contains(G)

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;2389;2457"

count

Integer count[()


Returns the number of instances of element in the Collection

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;9160;9209"

detect

 detect[()


Returns an element of the Collection (usually the first) for which the detector function
is true
Returns void if no elements is validated by the detector function
example :
anObject := aCollection.detect { e | \/* a condition *\/} // returns an element that fulfill the condition.

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;7791;7850"

each

Void each[()


Runs function func on each element of the Collection.
Each is safe against concurrent modifications: even if the collection is modified by the function func,
the iteration will procede on the original collection safely.

Example :
aCollection.each { e | \/* do something with each element e of this collection *\/ }

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;4436;4490"

empty

Boolean empty[()


Returns a Boolean stating whether the Collection is empty

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;3208;3246"

excludes

Boolean excludes[()


Returns true if the Collection does not contain element

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;2766;2818"

excludesAll

Boolean excludesAll[(Collection)


Returns true if the Collection contains no element of Collection elements
Standard implementation relies on excludes

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;2958;3026"

exists

Boolean exists[()


Returns a Boolean stating whether at least one element of the Collection
validates the condition specified by function func
example :
aBoolean := aCollection.exists { e | \/* a condition *\/} // returns true if at least one element fulfill the condition.

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;6370;6435"

existsCpl

Boolean existsCpl[()


Combinaison of exists on two elements in the collection
result := self.exists{x | self.exists {y | f(x,y)}}

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;6566;6633"

forAll

Boolean forAll[()


Returns a Boolean stating whether no element of the Collection invalidates
the condition specified by function func
example :
aBoolean := aCollection.forAll { e | \/* put here a condition *\/ } // return true if the condition is true for all elements in the collection.

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;5676;5736"

forAllCpl

Boolean forAllCpl[()


Combinaison of ForAll on two elements in the collection
result := self.forAll{x | self.forAll {y | f(x,y)}}
(where x and y are 2 elements of the Collection)
typical use sample : ownedState.forAllCpl{s1,s2| (s1.name==s2.name).implies(s1==s2)}

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;6014;6081"

includes

Boolean includes[()


OCL API alignment, does the same as contains
See Collection.contains(Object)
Standard implementation relies on Collection[G].contains(G)

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;2111;2162"

includesAll

Boolean includesAll[(Collection)


OCL API alignment, does the same as containsAll
See Collection.containsAll(Collection[G])
Standard implementation relies on containsAll

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;2623;2691"

indexedEach

Void indexedEach[()


Runs function func on each element of the Collection.
The EachContext variable contains informations about the process that can be used in the function func.
The iteration order is guaranteed only for ordered collections.
IndexedEach is safe against concurrent modifications: even if the collection is modified by the lambda func,
the iteration will procede on the original collection safely.

Typical use:
aCollection.indexedEach { e, eachContext |
stdio.write("element "+ eachContext.index.toString + ": " + e.toString)
if(!eachContext.isLast) then stdio.writeln(",") end
}
This example prints every element of the collection with its rank and adds a comma at the end of the line
only if it is relevant.

See also EachContext.

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;5297;5374"

isEmpty

Boolean isEmpty[()


OCL alignment API, does the same as empty
See Collection[G].empty()
Standard implementation relies on Collection[G].empty())

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;3398;3438"

isNotEmpty

Boolean isNotEmpty[()


OCL alignment API
Returns a Boolean stating whether the Collection contains at least
one element
See also Collection[G].empty()
Standard implementation relies on Collection[G].empty()

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;3658;3701"

isUnique

Boolean isUnique[T]()


Returns a Boolean stating whether the collector function evaluates to a
different value for each element of the Collection
example :
aCollection2 := aCollection.isUnique { e | \/* put here an expression that must be unique for all elements, for example e.name *\/ }

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;7408;7474"

iterator

Iterator[G] iterator[()


Returns an Iterator on the Collection

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;3758;3803"

one

 one[()


Returns an element from the Collection or void if the Collection is empty

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;3896;3926"

reject

Sequence[G] reject[()


Returns a new Sequence composed of elements of the Collection that
do not validate the rejector function
example :
aCollection2 := aCollection.reject { e |
\/* put here a condition that returns true for elements that must be exclude in the resulting Collection *\/
}

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;9011;9080"

remove

Void remove[()


Removes all instances of element from the Collection, based on
G.equals(Object) definition

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;1264;1314"

select

Sequence[G] select[()


Returns a new Sequence composed of elements of the Collection that
validate the selector function
example :
aCollection2 := aCollection.select { e |
\/* put here a condition that returns true for elements that must be included in the resulting Collection *\/
}

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;8159;8228"

selectOne

Sequence[G] selectOne[()


Returns a new Sequence containing one element of the Collection that
validates the selector function or an empty Sequence if no element
validates the selector function
example :
aCollection2 := aCollection.selectOne { e |
\/* put here a condition that returns true for the element that must be included in the resulting Collection *\/
}

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;8618;8693"

size

Integer size[()


Returns the number of elements in the Collection

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;3094;3131"

sum

 sum[()


Sum the elements of the collection if they are summable (ie implement '+' operator by inheriting of the class Summable).
Returns void otherwise.

@traceability_text_reference "file:/mnt/extradisk/builds/workspace/org.kermeta.language.library_master/org/kermeta/language/org.kermeta.language.library.standard/src/main/kmt/kermeta/standard/collections.kmt;9377;9406"