Hey Henri,

On Fri, Aug 26, 2011 at 11:50 PM, Henri Yandell <flame...@gmail.com> wrote:
> Thanks James.
>
> I wanted to pull the comparator classes over from Collections as I
> wanted to still be able to support them (and use internally as I
> already had ComparableComparator hidden away) without having to deal
> with all of Collections.
>
> Maybe the answer though is to ignore them in favour of Ordering, much
> the way we've long ignored the Date API in favour of Joda Time.
>
> It looks like:
>
> ComparableComparator = Ordering.natural
> ReverseComparator = Ordering.reverse
> NullComparator = Ordering.nullsFirst/nullsLast
> ComparatorChain = Ordering.from + Ordering.compound
> FixedOrderComparator = Ordering.explicit

I think one of the most useful methods is onResultOf, e.g.

class Person {
  public static final Function<Person, String> lastNameFunction = new
Function<Person, String>() {
    @Override public String apply(Person input) {
      return person.getLastName();
    }
  }

  ...
}

List<Person> people = ...;

Ordering<Person> lastNameOrdering =
Ordering.natural().reverse().onResultOf(lastNameFunction);
List<Person> sortedPeople = lastNameOrdering.immutableSortedCopy(people);

> Hen

Regards,
James

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to