11.7.4 Bag

= (bag : Bag(T)) : Boolean

如果selfs包含相同的元素,并且每个元素的数目相同,则为真。

post: result = (self->forAll(elem | self->count(elem) = bag->count(elem)) and
                bag->forAll(elem | bag->count(elem) = self->count(elem)) )

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

selfs的并包。

post: result->forAll( elem | result->count(elem) = self->count(elem) + bag->count(elem))
post: self ->forAll( elem | result->count(elem) = self->count(elem) + bag->count(elem))
post: bag ->forAll( elem | result->count(elem) = self->count(elem) + bag->count(elem))

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

selfbag的并包。

post: result->forAll(elem | result->count(elem) = self->count(elem) + set->count(elem))
post: self ->forAll(elem | result->count(elem) = self->count(elem) + set->count(elem))
post: set ->forAll(elem | result->count(elem) = self->count(elem) + set->count(elem))

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

selfs的交包。

post: result->forAll(elem | result->count(elem) = self->count(elem).min(bag->count(elem)) )
post: self->forAll(elem | result->count(elem) = self->count(elem).min(bag->count(elem)) )
post: bag->forAll(elem | result->count(elem) = self->count(elem).min(bag->count(elem)) )

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

selfs的交集。

post: result->forAll(elem|result->count(elem) = self->count(elem).min(set->count(elem)) )
post: self ->forAll(elem|result->count(elem) = self->count(elem).min(set->count(elem)) )
post: set ->forAll(elem|result->count(elem) = self->count(elem).min(set->count(elem)) )

including(object : T) : Bag(T)

包含self的所有元素以及object的包。

post: result->forAll(elem | if elem = object then
                                result->count(elem) = self->count(elem) + 1
                            else
                                result->count(elem) = self->count(elem)
                            endif)
post: self->forAll(elem | if elem = object then
                              result->count(elem) = self->count(elem) + 1
                          else
                              result->count(elem) = self->count(elem)
                          endif)

excluding(object : T) : Bag(T)

包含除objectself的所有元素的包。

post: result->forAll(elem | if elem = object then
                                result->count(elem) = 0
                            else
                                result->count(elem) = self->count(elem)
                            endif)
post: self->forAll(elem | if elem = object then
                                result->count(elem) = 0
                          else
                                result->count(elem) = self->count(elem)
                          endif)

count(object : T) : Integer

objectself中出现的次数。

post: result <= 1

flatten() : Bag(T2)

重定义Collection的操作。如果元素类型不是一个集合类型,那么结果是一个与self相同的包。如果元素类型是一个集合类型,结果是包含所有self的元素递归展开后的元素的包。

post: result = if self.oclType().elementType.oclIsKindOf(CollectionType) then
                   self->iterate(c; acc : Bag(T2) = Bag{} | acc->union(c->flatten()->asBag() ) )
               else
                   self
               endif

selectByKind(type : Classifier) : Bag(T)

返回self中所有类型是type或其子类型的元素包。返回集合的元素类型T是给定的type

selectByType(type : Classifier) : Bag(T)

返回self中所有类型是type而非其子类的元素包。返回集合的元素类型T是给定的type

asBag() : Bag(T)

重定义Collection的操作。从self获得一个与自身相同的Bag。该操作存在是出于方便的原因。

post: result = self

asSequence() : Sequence(T)

重定义Collection的操作。从self获得一个包含所有元素的Sequence,元素次序未定义。

post: result->forAll(elem | self->count(elem) = result->count(elem))
post: self ->forAll(elem | self->count(elem) = result->count(elem))

asSet() : Set(T)

重定义Collection的操作,从self获得一个包含所有元素的Set,重复的去除。

post: result->forAll(elem | self ->includes(elem))
post: self ->forAll(elem | result->includes(elem))

asOrderedSet() : OrderedSet(T)

重定义Collection的操作。从self获得一个包含所有元素的OrderedSet,重复的去除。元素次序未定义。

post: result->forAll(elem | self ->includes(elem))
post: self ->forAll(elem | result->includes(elem))
post: self ->forAll(elem | result->count(elem) = 1)

results matching ""

    No results matching ""