Return-Path: X-Original-To: apmail-commons-dev-archive@www.apache.org Delivered-To: apmail-commons-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 29E088EC7 for ; Fri, 26 Aug 2011 08:41:06 +0000 (UTC) Received: (qmail 67677 invoked by uid 500); 26 Aug 2011 08:41:05 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 66056 invoked by uid 500); 26 Aug 2011 08:40:58 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 66037 invoked by uid 99); 26 Aug 2011 08:40:55 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Aug 2011 08:40:55 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [209.85.161.171] (HELO mail-gx0-f171.google.com) (209.85.161.171) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Aug 2011 08:40:49 +0000 Received: by gxk22 with SMTP id 22so3464599gxk.30 for ; Fri, 26 Aug 2011 01:40:27 -0700 (PDT) MIME-Version: 1.0 Received: by 10.231.29.138 with SMTP id q10mr1661006ibc.87.1314348027593; Fri, 26 Aug 2011 01:40:27 -0700 (PDT) Received: by 10.231.46.140 with HTTP; Fri, 26 Aug 2011 01:40:27 -0700 (PDT) In-Reply-To: References: Date: Fri, 26 Aug 2011 01:40:27 -0700 Message-ID: Subject: Re: [lang] ComparatorChain redesign From: James Ring To: Commons Developers List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Google Guava has Ordering: http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/c= ollect/Ordering.html It is an incredibly useful class. Some random example of how it's awesome: http://www.polygenelubricants.com/2010/10/elegant-comparison-logic-with-gua= va.html Recommend that ComparatorChain.. just do what Ordering does. :) On Fri, Aug 26, 2011 at 1:17 AM, Henri Yandell wrote: > Looking at the Collections ComparatorChain class, I think it's overcompli= cated. > > The current API is: > > public class ComparatorChain implements Comparator, Serializable { > =A0 =A0public ComparatorChain() { > =A0 =A0public ComparatorChain(Comparator comparator) { > =A0 =A0public ComparatorChain(Comparator comparator, boolean reverse) = { > =A0 =A0public ComparatorChain(List> list) { > =A0 =A0public ComparatorChain(List> list, BitSet bits) { > =A0 =A0public void addComparator(Comparator comparator) { > =A0 =A0public void addComparator(Comparator comparator, boolean revers= e) { > =A0 =A0public void setComparator(int index, Comparator comparator) > throws IndexOutOfBoundsException { > =A0 =A0public void setComparator(int index, Comparator comparator, > boolean reverse) { > =A0 =A0public void setForwardSort(int index) { > =A0 =A0public void setReverseSort(int index) { > =A0 =A0public int size() { > =A0 =A0public boolean isLocked() { > =A0 =A0public int compare(E o1, E o2) throws UnsupportedOperationExceptio= n { > =A0 =A0public int hashCode() { > =A0 =A0public boolean equals(Object object) { > > The whole reverse notion seems like unnecessary duplication. If you > wanted such you could wrap a ReverseComparator around the comparator > before adding. I also think the notion of locking should also go away, > make these immutable objects. > > ie: > > > public class ComparatorChain implements Comparator, Serializable { > =A0 =A0public ComparatorChain(Comparator comparator...) { > =A0 =A0public ComparatorChain(List> list) { > =A0 =A0public int size() { > =A0 =A0public int compare(E o1, E o2) { > =A0 =A0public int hashCode() { > =A0 =A0public boolean equals(Object object) { > > The constructors could throw exceptions when they contain no > comparator. Or we could simply return 0 as having no comparators is > the same as the comparators being exhausted. > > Any thoughts on the simpler API? > > Should it also implement Iterable as a way to loop through the > contained comparators? > > Hen > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > For additional commands, e-mail: dev-help@commons.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org