Collection<T>

Collection<T>

Collection is the abstract supertype of all collection types in the OCL Standard Library. Each occurrence of an object in a collection is called an element. If an object occurs twice in a collection, there are two elements.

conformsTo OclAny

Operations

=(object2 : OclAny) : Boolean precedence: EQUALITY

True if c is a collection of the same kind as self and contains the same elements in the same quantities and in the same order, in the case of an ordered collection type.

<>(object2 : OclAny) : Boolean precedence: EQUALITY

True if c is not equal to self.

asBag() : Bag<T>

The Bag that contains all the elements from self.

asOrderedSet() : OrderedSet<T>

An OrderedSet that contains all the elements from self, with duplicates removed, in an order dependent on the particular concrete collection type.

asSequence() : Sequence<T>

A Sequence that contains all the elements from self, in an order dependent on the particular concrete collection type.

asSet() : Set<T>

The Set containing all the elements from self, with duplicates removed.

count(object : OclAny) : Integer

The number of times that object occurs in the collection self.

excludes(object : OclAny) : Boolean

True if object is not an element of self, false otherwise.

excludesAll<T2>(c2 : Collection<T2>) : Boolean

Does self contain none of the elements of c2 ?

excluding(object : OclAny) : Collection<T>

The collection containing all elements of self apart from object.

flatten<T2>() : Collection<T2>

If the element type is not a collection type, this results in the same collection as self. If the element type is a collection type, the result is a collection containing all the elements of all the recursively flattened elements of self.

includes(object : OclAny) : Boolean

True if object is an element of self, false otherwise.

includesAll<T2>(c2 : Collection<T2>) : Boolean

Does self contain all the elements of c2 ?

including(object : T) : Collection<T>

The collection containing all elements of self plus object.

isEmpty() : Boolean

Is self the empty collection? Note: null->isEmpty() returns ‘true’ in virtue of the implicit casting from null to Bag{}

max() : T

The element with the maximum value of all elements in self. Elements must be of a type supporting the max operation. The max operation – supported by the elements – must take one parameter of type T and be both associative and commutative. UnlimitedNatural, Integer and Real fulfill this condition.

min() : T

The element with the minimum value of all elements in self. Elements must be of a type supporting the min operation. The min operation – supported by the elements – must take one parameter of type T and be both associative and commutative. UnlimitedNatural, Integer and Real fulfill this condition.

notEmpty() : Boolean

Is self not the empty collection? null->notEmpty() returns ‘false’ in virtue of the implicit casting from null to Bag{}.

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

The cartesian product operation of self and c2.

size() : Integer

The number of elements in the collection self.

sum() : T

The addition of all elements in self. Elements must be of a type supporting the + operation. The + operation must take one parameter of type T and be both associative: (a+b) c = a(b+c), and commutative: a+b = b+a. UnlimitedNatural, Integer and Real fulfill this condition. If the + operation is not both associative and commutative, the sum expression is not well-formed, which may result in unpredictable results during evaluation. If an implementation is able to detect a lack of associativity or commutativity, the implementation may bypass the evaluation and return an invalid result.

Iterations

any(i : T | body : Lambda T() : Boolean) : T

Returns any element in the source collection for which body evaluates to true. If there is more than one element for which body is true, one of them is returned. There must be at least one element fulfilling body, otherwise the result of this IteratorExp is null.

collect<V>(i : T | body : Lambda T() : V) : Collection<V>

The Collection of elements that results from applying body to every member of the source set. The result is flattened. Notice that this is based on collectNested, which can be of different type depending on the type of source. collectNested is defined individually for each subclass of CollectionType.

collectNested<V>(i : T | body : Lambda T() : V) : Collection<T>

The Collection of elements which results from applying body to every member of the source collection.

exists(i : T | body : Lambda T() : Boolean) : Boolean

Results in true if body evaluates to true for at least one element in the source collection.

exists(i : T, j : T | body : Lambda T() : Boolean) : Boolean

forAll(i : T | body : Lambda T() : Boolean) : Boolean

Results in true if the body expression evaluates to true for each element in the source collection; otherwise, result is false.

forAll(i : T, j : T | body : Lambda T() : Boolean) : Boolean

isUnique(i : T | body : Lambda T() : OclAny) : Boolean

Results in true if body evaluates to a different value for each element in the source collection; otherwise, result is false.

iterate<Tacc>(i : Tacc : ; Tacc) : Tacc

one(i : T | body : Lambda T() : Boolean) : Boolean

Results in true if there is exactly one element in the source collection for which body is true.

reject(i : T | body : Lambda T() : Boolean) : Collection<T>

The sub-collection of the source collection for which body is false.

select(i : T | body : Lambda T() : Boolean) : Collection<T>

The sub-collection of the source collection for which body is true.

sortedBy(i : T | body : Lambda T() : OclAny) : OrderedCollection<T>

Results in the Collection containing all elements of the source collection. The element for which body has the lowest value comes first, and so on. The type of the body expression must have the < operation defined. The < operation must return a Boolean value and must be transitive (i.e., if a < b and b < c then a < c).