| Reverse sort for sortedBy() [message #939654] |
Wed, 10 October 2012 20:14  |
Warwick Burrows Messages: 84 Registered: July 2009 Location: Austin, TX |
Member |
|
|
Hi,
Is there a way to perform a reverse sort in an OCL query? Looking on the web the only place I found a reference to reverse OCL sorting indicated that putting a "-" in front of the sort field would work e.g. sortedBy(e|-e.name). But I get an exception:
Caused by: org.eclipse.ocl.SemanticException: Cannot find operation (-()) for the type (String)
I also tried sortedBy(-e|e.name) but got this error instead:
Caused by: org.eclipse.ocl.SyntaxException: 2:374:2:374 "::" expected instead of "|"
Is that the correct syntax? Is there another way to reverse sort?
Thanks,
Warwick
[Updated on: Wed, 10 October 2012 20:21] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
| Re: Reverse sort for sortedBy() [message #942607 is a reply to message #941762] |
Sat, 13 October 2012 13:40  |
Ed Willink Messages: 3165 Registered: July 2009 |
Senior Member |
|
|
Hi
oclAsType() should not be necessary, and it isn't with the new
pivot-based OCL that has fully modeled library declarations exploiting
templated types to avoid loss of static type precision.
Regards
Ed Willink
On 12/10/2012 22:00, Warwick Burrows wrote:
> That works! I just needed one adjustment to get around the issue
> where the defined type of the "backwards" variable didn't match the
> results returned by the query. I found someone with a similar problem
> and just added the oclAsType(MyMap) to the sorted results.
>
>
> let backwards : Sequence(MyMap) =
> MyMap.allInstances()->sortedBy(name).oclAsType(MyMap) in
> let size: Integer = backwards->size() in
> Sequence{0..size-1}->collect(i : Integer | backwards->at(size - i))
>
>
> Thanks,
> Warwick
>
|
|
|
Powered by
FUDForum. Page generated in 0.01982 seconds