commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael A. Smith" <...@apache.org>
Subject Re: [collections] ReverseComparator
Date Wed, 20 Mar 2002 00:22:10 GMT
On Tue, 19 Mar 2002, Morgan Delagrange wrote:
> If you like.  Either we add setComparator/getComparator, or we remove the
> undesirable no-op constructor.  If it were me, I'd just do the later, but
> I'm not in the "make every class a bean" camp.

I disagree.  a no-arg constructor and dynamic instantiation of the
comparator may be useful without a get/setComparator mechanism.  For
example, consider an application that allows you to specify a comparator
in a configuration file while it will use for a particular application 
specific task.  The config fail may just ask for the comparator class 
name, and the app can instantiate an instance of the comparator to use.  

get/setComparator methods are really only useful for altering the 
underlying comparator once the reverse/inverse comparator has been 
constructed.  I think this is bad because the underlying comparator is 
part of the functionality, and providing modification of it thus changes 
the functionality of the reverse/inverse comparator.  That doesn't seem 
like an appropriate attribute modification. 

Since there's been a bit of discussion on the issue, and I haven't really
heard any objections to my diff (fixing the comparator with respect to the
comparator contract), I'm going to check that in. I'm also going to check
in the argument swap rather than multiplication.  We can continue
discussion on the rename and whether or not to have a no-arg constructor.

regards,
michael

> 
> ----- Original Message -----
> From: "Henri Yandell" <bayard@generationjava.com>
> To: "Jakarta Commons Developers List" <commons-dev@jakarta.apache.org>;
> "Morgan Delagrange" <morgand@apache.org>
> Sent: Tuesday, March 19, 2002 2:08 PM
> Subject: Re: [collections] ReverseComparator
> 
> 
> > The only reason I'd normally expect to have an empty constructor would be
> > for reflection. To that end, should it have a setComparator/getComparator
> > methods?
> >
> > Hen
> >
> > On Tue, 19 Mar 2002, Morgan Delagrange wrote:
> >
> > > Do we need an empty constructor?  If it does not produce desirable
> > > behaviour, why not can it?
> > >
> > > ----- Original Message -----
> > > From: "Henri Yandell" <bayard@generationjava.com>
> > > To: "Jakarta Commons Developers List" <commons-dev@jakarta.apache.org>
> > > Sent: Tuesday, March 19, 2002 11:11 AM
> > > Subject: Re: [collections] ReverseComparator
> > >
> > >
> > > >
> > > > Functionality wise, I feel that Michael's proposed change is a
> negative
> > > > move. However he is absolutely right in all of his points. The
> current -1
> > > > does break the Comparator contract, the -1* is unnecessary coding,
> making
> > > > the constructor take ComparableComparator is then no different from
> > > > reverseOrder, and the name then does make more sense as
> InverseComparator.
> > > >
> > > > It's like a stack of dominoes :) Each point seems not necessarily true
> > > > until you realise each one leads to the next. So I'm:
> > > >
> > > > +1 on removing the -1*.
> > > > +1 on killing the current empty constructor.
> > > > +0 on using ComparableComparator which simulates reverseOrder
> > > functionality.
> > > >    It feels bad to replicate this, but we need an empty constructor.
> > > > +0 on the name of the class. It does behave more as an
> InverseComparator
> > > >    from a mathematical point of view (which I share), but Reverse does
> > > >    seem more readable.
> > > >
> > > > Hen
> > > >
> > > >
> > > > On Tue, 19 Mar 2002, Morgan Delagrange wrote:
> > > >
> > > > > Michael suggested that the no-op constructor essentially behave like
> > > this:
> > > > >
> > > > >   ReverseComparator() {
> > > > >       this(ComparableComparator.getInstance());
> > > > >   }
> > > > >
> > > > > What do you think, Hen?  Do you think that is preferable, or do you
> > > prefer
> > > > > your initial behaviour (reversing the List).
> > > > >
> > > > >
> > > > > ----- Original Message -----
> > > > > From: "Henri Yandell" <bayard@generationjava.com>
> > > > > To: "Jakarta Commons Developers List"
> <commons-dev@jakarta.apache.org>
> > > > > Sent: Tuesday, March 19, 2002 7:50 AM
> > > > > Subject: Re: [collections] ReverseComparator
> > > > >
> > > > >
> > > > > >
> > > > > > I'm happy with the name Inverse as it is more what the comparator
> > > does.
> > > > > > Reverse makes it easier to see how it can be used for one case,
> but
> > > will
> > > > > > hide other meanings.
> > > > > >
> > > > > > Why does this exist over Collections.reverseOrder? Because the
Sun
> > > version
> > > > > > is limited. Why can I only reverse Comparables? Really there
> should be
> > > a
> > > > > > Collections.reverseOrder(Comparator) as well.
> > > > > >
> > > > > > Hen
> > > > > >
> > > > > > > I agree that reverse is common terminology when sorting,
but I
> > > disagree
> > > > > > > that sorting is intrinsicly what a comparator does. While
> sorting is
> > > > > > > probably the most common use-case for comparators, the
> comparator
> > > itself
> > > > > > > does not do any sorting.  It compares objects and returns
a
> > > negative,
> > > > > zero
> > > > > > > value, or positive result.  It doesn't rearrange, reverse,
> order, or
> > > > > > > "sort".  It just compares two objects. This particular
> comparator
> > > > > > > "inverses" the result of the compare to be a positive,
zero
> value,
> > > or
> > > > > > > negative result (respectively).  I use "inverse" here in
its
> > > > > mathematical
> > > > > > > sense of inverting the result, since that's all this comparator
> is
> > > > > doing.
> > > > > > >
> > > > > > > I'm not going to argue this anymore though.  I've changed
my
> > > position --
> > > > > > > why is this class even included in commons when the JDK
provides
> a
> > > > > > > reverse/inverse comparator already?  @see
> Collections.reverseOrder()
> > > > > > >
> > > > > > > regards,
> > > > > > > michael
> > > > > > >
> > > > > > > > "Michael A. Smith" wrote:
> > > > > > > > >[snip]
> > > > > > > > > Additionally, I think that "InverseComparator"
is a more
> > > appropriate
> > > > > name,
> > > > > > > > > as "inverse" has a more direct meaning (to me
at least).
> > > Inverse
> > > > > has the
> > > > > > > > > mathematical meaning of the opposite sign which
is exactly
> what
> > > this
> > > > > > > > > comparator does.  Reverse, on the other hand,
implies
> switching
> > > the
> > > > > order
> > > > > > > > > of something, the comparator isn't really switching
the
> order
> > > > > (although a
> > > > > > > > > collection using the comparator may be "reversed"
if it uses
> the
> > > > > "inverse"
> > > > > > > > > comparator).
> > > > > > > > >
> > > > > > > > > Thoughts?
> > > > > > > > >[snip]
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > To unsubscribe, e-mail:
> > > > > <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> > > > > > > For additional commands, e-mail:
> > > > > <mailto:commons-dev-help@jakarta.apache.org>
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > To unsubscribe, e-mail:
> > > > > <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> > > > > > For additional commands, e-mail:
> > > > > <mailto:commons-dev-help@jakarta.apache.org>
> > > > >
> > > > >
> > > > > _________________________________________________________
> > > > > Do You Yahoo!?
> > > > > Get your free @yahoo.com address at http://mail.yahoo.com
> > > > >
> > > > >
> > > > > --
> > > > > To unsubscribe, e-mail:
> > > <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> > > > > For additional commands, e-mail:
> > > <mailto:commons-dev-help@jakarta.apache.org>
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > To unsubscribe, e-mail:
> > > <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> > > > For additional commands, e-mail:
> > > <mailto:commons-dev-help@jakarta.apache.org>
> > >
> > >
> > > _________________________________________________________
> > > Do You Yahoo!?
> > > Get your free @yahoo.com address at http://mail.yahoo.com
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> > > For additional commands, e-mail:
> <mailto:commons-dev-help@jakarta.apache.org>
> > >
> > >
> 
> 
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message