|
Re: SortBy in xtend [message #1121249 is a reply to message #1121192] |
Mon, 30 September 2013 08:22  |
Eclipse User |
|
|
|
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 :)
|
|
|
Powered by
FUDForum. Page generated in 0.04673 seconds