aspose file tools*
The moose likes Java in General and the fly likes sort PersistentSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "sort PersistentSet" Watch "sort PersistentSet" New topic
Author

sort PersistentSet

liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
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

Joined: Oct 27, 2005
Posts: 19762
    
  20

There are Collections.sort and Arrays.sort, but the first takes a List and the second any type of array.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
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

Joined: Oct 27, 2005
Posts: 19762
    
  20

Arrays.sort either takes an array of comparable objects, or an object array and a matching comparator. It returns void.
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sort PersistentSet