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 Adavani
Messages: 109
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 Guckelsberger
Messages: 224
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: Thu Oct 23 04:02:59 GMT 2014

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

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