Alison Winters
unread,Feb 13, 2011, 4:02:26 PM2/13/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to lambdaj
I just started using the Group feature, and it's pretty cool, but I am
having trouble getting it to sort. There is no documentation
indicating how to do it, but it looks like you should be able to do:
List<Thing> things = getThings();
Group group = group(things,
by(on(Thing.class).value).sort(on(Thing.class)));
This doesn't seem to work, however - I get a NullPointerException when
trying to sort. I have also tried:
Group group = group(things,
by(on(Thing.class).value).sort(on(Thing.class).value));
This also fails. I have a feeling I am using the GroupCondition.sort()
method incorrectly. What I would like to do is create a Group grouped
by a particular value, but within that Group I would also like to sort
by a custom Comparator. Right now my Thing object implements
Comparable, so the following works:
Group group = group(things, by(on(Thing.class).value));
List<Thing> sortedThings = group.findAll();
Collections.sort(sortedThings);
But that feels like an extra step. What is the correct usage of Group
sorting? And is it possible to trigger a sort of parts of the Group in-
place without having to always get a List representation first?