Collection-Related Types

This section defines the collection types and their operations. As defined in this section, each collection type is actually a template type with one parameter. `T' denotes the parameter. A concrete collection type is created by substituting a type for the T. So Set (Integer) and Bag (Person) are collection types.
 

Collection

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. This section defines the properties on Collections that have identical semantics for all collection subtypes. Some operations may be defined within the subtype as well, which means that there is an additional postcondition or a more specialized return value. Collection is itself an instance of the metatype CollectionType.

The definition of several common operations is different for each subtype. These operations are not mentioned in this section.

The semantics of the collection operations is given in the form of a postcondtion that uses the IterateExp ot the IteratorExp construct. The semantics of those constructs is defined in chapter 10 ("Semantics Described using UML").

In several cases the postcondtion refers to other collection operations, which in turn are defined in terms of the IterateExp or IteratorExp constructs.
 

Set

The Set is the mathematical set. It contains elements without duplicates. Set is itself an instance of the metatype SetType.
 

OrderedSet

The OrderedSet is a Set the elements of which are ordered. It contains no duplicates. OrderedSet is itself an instance of the metatype OrderedSetType.
 

Bag

A bag is a collection with duplicates allowed. That is, one object can be an element of a bag many times. There is no ordering defined on the elements in a bag. Bag is itself an instance of the metatype BagType.
 

Sequence

A sequence is a collection where the elements are ordered. An element may be part of a sequence more than once. Sequence is itself an instance of the metatype SequenceType.