commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonathan Carlson <joncrl...@yahoo.com>
Subject [Collections] TransformingComparator
Date Fri, 07 Jun 2002 19:22:37 GMT
I have attached a very simple, but powerful
TransformingComparator that I wrote.  It would go well in
the Collections framework.  It decorates another Comparator
with  behavior from any Transformer.  That is, the return
value from the #transform method will be passed to the
#compare method on the decorated Comparator.  The default
decorated Comparator is the ComparableComparator.

This will allow you to reuse Transformers and Comparators
in interesting and powerful combinations, like use an
existing Address comparator to sort a list of Employees by
address (for example).

I also have a generic ReflectingTransformer that I wrote,
which, when coupled with the attached
TransformingComparator will allow you to dynamically sort a
collection based on any getter.  However, it uses a generic
ReflectionHelper that wouldn't fit within the Collections
framework (I don't know where it would go).  But if anyone
is interested in that code too, I'd be happy to share it.

Jonathan



=====
Jonathan Carlson
joncrlsn@users.sf.net
Minneapolis, Minnesota

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com
Mime
View raw message