how to sort Groups?

154 views
Skip to first unread message

Alison Winters

unread,
Feb 13, 2011, 4:02:26 PM2/13/11
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?

Paul Woodward

unread,
Aug 29, 2013, 6:20:16 AM8/29/13
to lam...@googlegroups.com
Did anyone find a solution to this?

Jean-Philippe Heng

unread,
May 4, 2015, 6:42:11 AM5/4/15
to lam...@googlegroups.com
the sort method on the by method applies only on the key value.
So i think i can't work.
I'am still looking for a way to group on a condition and to sort on another condition.
Does someone knows how to do that please?
Reply all
Reply to author
Forward
0 new messages