Pergunta

I have a UML model (which is actually irrelevant as it could be any MOF model) with an ordered set I need to access from the last to the first element. I thus need to reverse it through OCL. I have seen there is the sortedBy method that needs an OCLExpression to use as sorting criterion but I can't get how to use it.

Any idea?

Foi útil?

Solução

If you are using Acceleo (your comment is suggesting that you are), you have two options:

  • use "myOrderedSet->reverse()" provided by the Acceleo library (that's not 100% pure OCL)
  • use something like "myOrderedSet->iterate(elem: MyType| myOrderedSet.insertAt(0, elem))"

Edit: It's been a long time since I used iterate since I use reverse all the time, the correct for of the iterate is this: link. And in case anyone had a doubt, here is the answer with reverse: link

Regards,

Stephane Begaudeau

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top