commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne" <>
Subject [collections] FixedOrderComparator, bug #16823
Date Sat, 15 Feb 2003 11:11:05 GMT

I believe that a FixedOrderComparator would be a useful addition to
[collections]. It seems to fill an obvious gap.

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.

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 ;-) ?


Among the simple classes I use frequently is a Comparator which imposes a
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
does it for you.  It's also something that can be hard to live without once
have it, assuming the appropriate problem space.  (Then again, what isn't?)

I wrote such a class for my current employer ( which
graciously given me permission to donate it and its unit tests to Commons,
well as spend work hours on this project.  It will need some cleaning up
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
integrate it into Commons.  But first some details.

The class is currently named MapOrderComparator, since it uses a map to
the underlying order.  I don't like the name because it obscures its
I'm still fishing for a better name; FixedOrderComparator and/or
ArbitraryComparator don't get the point across, though.  A sample usage is

    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);


I wrote the class to do arbitrary order comparisons, using a Map
but included some general-purpose Map functionality, including a constructor
which takes a Map.  I've never populated the map values with anything other
Integers to keep track of the initial order.  So one way to proceed would be
hide the Map as an implementation detail.

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

View raw message