I love lambdaj and use it a lot, but I can't seem to figure out if it is possible to sort a list using multiple sort conditions.
Here is an example using Google Collections. Can the same thing be done in lambdaj?
Sorted first by color then by name:
Function<Fruit, Color> getColorFunction = new Function<Fruit, Color>() {
public Color apply(Fruit from) {
return from.getColor();
}
};
Function<Fruit, String> getNameFunction = new Function<Fruit, String>() {
public String apply(Fruit from) {
return from.getName();
}
};
Ordering<Fruit> colorOrdering = Ordering.natural().onResultOf(getColorFunction);
Ordering<Fruit> nameOrdering = Ordering.natural().onResultOf(getNameFunction);
Ordering<Fruit> colorAndNameOrdering = colorOrdering.compound(nameOrdering);
ImmutableSortedSet<Fruit> sortedFruits = ImmutableSortedSet.orderedBy(
colorAndNameOrdering).addAll(fruits).build();