我正在从事以下领域的工作:
我想表达折叠约束:“不允许连续两个类型的旋转操作”,我尝试了这个声明,但是eclipse没有识别indexOf(元素) :
class Choreography
{
property actions : Action[+|1] { ordered composes };
attribute name : String[?];
/*Succession of two actions of Type is not permitted */
invariant rotate_succ:
self.actions->asSequence()->forAll(a1:Action,a2:Action
|
a1.oclIsTypeOf(Rotate) and (indexOf(a1)=indexOf(a2)+1) implies
not a2.oclIsTypeOf(Rotate)
)
;有没有人知道如何处理来自ocl学院的随机元素的索引?
发布于 2019-12-19 13:52:17
这个
OrderedCollection(T):indexOf(obj : OclAny[?]) : Integer[1]操作需要一个OrderedCollection (Sequence/OrderedSet)作为其源,OclAny作为它的参数。您还没有标识源,因此OCL将首先考虑隐式迭代器,从而导致
a1.indexOf(a1)
a2.indexOf(a1)模糊,这将是一个错误,如果一个动作有一个indexOf操作。然后考虑一个隐式self,它也失败了,因为没有Choreography.indexOf()操作。
我猜你是说
self.actions->indexOf(a1)等,或更容易把self.actions放在一个让-变量多用途.
(使用oclIsTypeOf很少正确。除非您有特定的意图,否则使用oclIsKindOf。)
(self.actions已经是一个OrderedCollection,因此不需要asSequence())。
您对indexOf的使用将导致二次性能。最好使用索引--如下所示:
let theActions = self.actions in
Sequence{1..theActions->size()-1}->forAll(index |
theActions->at(index).oclIsKindOf(Rotate)
implies not theActions->at(index+1).oclIsKindOf(Rotate))https://stackoverflow.com/questions/59407478
复制相似问题