• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sort PersistentSet

 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I'm not sure if this is the best forum for my question, sorting a Set seems to fit it. I'm working in .groovy files and have a hibernate.collection.PersistentSet that I need to sort in the following form:


The PersistentSet is returned with sp.repGroupProfiles, where sp is a db domain object and repGroupProfiles is part of has-many relation. I have sorting algorithms at hand way back from school, but before using them, I'd like to see if there is something else I could use. Ideally, I'd like to be able to sort right in render statement, but not sure if that's at all possible. If anyone knows of elegant solutions to this, I'd sure be happy to hear about them. Thank you in advance.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are Collections.sort and Arrays.sort, but the first takes a List and the second any type of array.
 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I tried that, no results at all. The trouble is that I want to sort it by a property groupNames in sp.repGroupProfiles, the notation is:

And groupNames are strings, I think Arrays.sort are for sorting numbers, maybe not, but it did nothing in this case


It returns null, I wonder if syntax is off.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arrays.sort either takes an array of comparable objects, or an object array and a matching comparator. It returns void.
 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, Here is what works:



The problem is then I loose bd objects, and have only a string arr, which means I cant use other properties of repGroupProfiles like ids. It would work, it is just not ideal.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic