commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Leppik <>
Subject Re: [collections] FixedOrderComparator, bug #16823
Date Mon, 17 Feb 2003 23:14:29 GMT
Stephen Colebourne wrote:
> I believe that a FixedOrderComparator would be a useful addition to
> [collections]. It seems to fill an obvious gap.

Since you've latched onto FixedOrderComparator as the name, I'll run 
with it.

> I would welcome an implementation in the correct package, with test cases
> following the style of collections.
> For your example code, I would suggest adding a List constructor to
> complement the array one.

Makes sense, and it's only 3 lines.

> I believe on furhter thinking that the Map constructor and methods are
> probably implementation detail. They should not be exposed at present.
> Are you still able to submit this ;-) ?
> Stephen

I'll get to work on it just as soon as deadlines allow.

Thanks for your input!


> Among the simple classes I use frequently is a Comparator which imposes a
> fixed
> and arbitrary order on a group of objects.  As with so many things, it's not
> hard to coerce this behavior, but it's really convenient to have a class
> which
> does it for you.  It's also something that can be hard to live without once
> you
> have it, assuming the appropriate problem space.  (Then again, what isn't?)
> I wrote such a class for my current employer ( which
> has
> graciously given me permission to donate it and its unit tests to Commons,
> as
> well as spend work hours on this project.  It will need some cleaning up
> (add
> the Apache copyright, probably change the name, and tighten error handling),
> which I am prepared to do.
> If others consider this valuable, I'd like some advice on how to proceed to
> best
> integrate it into Commons.  But first some details.
> The class is currently named MapOrderComparator, since it uses a map to
> enforce
> the underlying order.  I don't like the name because it obscures its
> purpose.
> I'm still fishing for a better name; FixedOrderComparator and/or
> ArbitraryComparator don't get the point across, though.  A sample usage is
> as
> follows:
>     String[] days = { "Monday", "Tuesday", "Wednesday", /* etc...*/ };
>     /* Construct a Comparator which uses the order of the array */
>     Comparator dayComparator = new MapOrderComparator(days);
>     TreeMap stuffThatHappensDuringTheWeek = new TreeMap(dayComparator);
>     myThingie.populate(stuffThatHappensDuringTheWeek);
>     myViewer.displaySomeMappedData(stuffThatHappensDuringTheWeek);
> I wrote the class to do arbitrary order comparisons, using a Map
> implementation,
> but included some general-purpose Map functionality, including a constructor
> which takes a Map.  I've never populated the map values with anything other
> than
> Integers to keep track of the initial order.  So one way to proceed would be
> to
> hide the Map as an implementation detail.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

David Leppik
Senior Software Engineer
Vocal Laboratories Inc.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message