Tuesday 15 July 2014

java - sort list by date in descending order - groovy madness -


I am not able to sort a list of objects according to a date in a supernatural order

We say this is my class Thing

  class Thing {Profil Profile String Status = 'Ready' date dtCreated = new date ()}   

Things to do in the 'i list'

  list profile = profile. Xyz? .collect {Profil.collection.findOne (_id: it)} Items in the list = []   

And then I populate the list with each related item of each profile < / P>

  profiles.each () {profile, i - & gt;   

OK There are so many things in things , unfortunately [order: 'desc'] was applied in each set and I sorted the entire list by dtCreated Required, which works fine, now everything has sorted by date, but in the wrong order, most recently. The last item in the list is

So I need to sort in the opposite direction, I did not find anything on the web which pushed me up, like stuff tried

 < Code> things.sort {-it.dtCreated} // does not work things.sort {it.dtCreated} .reverse () // has no effect   

and I do not have any I'm not searching for Grivi's approach to such standard operations, maybe someone's sign that I can sort my things by date. [Sort: 'dtCreated', order: 'desc'] Or is not it?

Thanks in advance for any indication

Instead of

  things.sort {-it.dtCreated}   

you can try

  Things.sort {a, b-> B.dtCreated & lt; = & Gt; A.dtCreated}   

Nothing does anything because it creates a new list instead of changing the current one.

  Things should change. {{Code} things = things.revers ()     former> 

as well.

No comments:

Post a Comment