commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne" <scolebou...@btopenworld.com>
Subject [collections] FixedOrderComparator, bug #16823
Date Sat, 15 Feb 2003 11:11:05 GMT
http://issues.apache.org/bugzilla/show_bug.cgi?id=16823

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

Stephen

>From david@leppik.net:
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 (http://www.vocalabs.com) 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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message