Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 59000 invoked from network); 15 Feb 2003 11:09:24 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 15 Feb 2003 11:09:24 -0000 Received: (qmail 17513 invoked by uid 97); 15 Feb 2003 11:11:10 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@nagoya.betaversion.org Received: (qmail 17506 invoked from network); 15 Feb 2003 11:11:10 -0000 Received: from daedalus.apache.org (HELO apache.org) (208.185.179.12) by nagoya.betaversion.org with SMTP; 15 Feb 2003 11:11:10 -0000 Received: (qmail 58782 invoked by uid 500); 15 Feb 2003 11:09:22 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 58771 invoked from network); 15 Feb 2003 11:09:22 -0000 Received: from einsteinium.btinternet.com (194.73.73.147) by daedalus.apache.org with SMTP; 15 Feb 2003 11:09:22 -0000 Received: from host217-41-27-40.in-addr.btopenworld.com ([217.41.27.40] helo=oemcomputer) by einsteinium.btinternet.com with smtp (Exim 3.22 #23) id 18k0CN-0007dD-00 for commons-dev@jakarta.apache.org; Sat, 15 Feb 2003 11:09:35 +0000 Message-ID: <00af01c2d4e2$eeecf800$281b29d9@oemcomputer> From: "Stephen Colebourne" To: "Jakarta Commons Developers List" Subject: [collections] FixedOrderComparator, bug #16823 Date: Sat, 15 Feb 2003 11:11:05 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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