Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » SortBy in xtend(SortBy in xtend)
icon5.gif  SortBy in xtend [message #1121192] Mon, 30 September 2013 11:12 Go to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hello all,
I am sorting some collection in Xtend.
I.e. coll.sortBy[name]
This sorts me collection based on name.

But here name is a string datatype which should be converted to int.
So If I say coll.sortBy[Integer.valueOf(name)]

It will work for sure.
But name can have only integers (e.g. 1, 100,500 etc) or integers with comma (e.g. 1,3)
Here name is 1,3.
So if it contains comma then I want to add 1+3=4 and this based on these names I want to sort.

Any ideas??
Thanks in advance Smile


Arshad
Re: SortBy in xtend [message #1121249 is a reply to message #1121192] Mon, 30 September 2013 12:22 Go to previous message
Axel Guckelsberger is currently offline Axel GuckelsbergerFriend
Messages: 354
Registered: July 2009
Senior Member
Hi,

you should put your logic for computing the "result value" of a name into an
extension method.

Something like this:

coll.sortBy(name.resultValue)


def resultValue(String input) {
if (!input.contains(',')) {
return input
}

val inputParts = input.split(',')
var result = 0
for (s : inputParts) {
result = result + Integer.valueOf(s)
}
result.toString
}


HTH
Axel


Arshad Adavani wrote:

> Hello all,
> I am sorting some collection in Xtend.
> I.e. coll.sortBy[name]
> This sorts me collection based on name.
>
> But here name is a string datatype which should be converted to int.
> So If I say coll.sortBy[Integer.valueOf(name)]
>
> It will work for sure.
> But name can have only integers (e.g. 1, 100,500 etc) or integers with
> comma (e.g. 1,3) Here name is 1,3.
> So if it contains comma then I want to add 1+3=4 and this based on these
> names I want to sort.
>
> Any ideas??
> Thanks in advance :)
Previous Topic:Accessing files in other projects in xtext
Next Topic:Creat automatically element in the current resource
Goto Forum:
  


Current Time: Wed Apr 24 16:10:14 GMT 2024

Powered by FUDForum. Page generated in 0.10392 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top