FYI, java.lang.String.CASE_INSENSITIVE_ORDER does what your 
LowercaseComparator does, but somewhat more efficiently.

-Paul


> -----Original Message-----
> From: Eric Pugh [mailto:[EMAIL PROTECTED]]
> Sent: Monday, June 10, 2002 1:35 PM
> To: 'Jakarta Commons Developers List'
> Subject: RE: [COLLECTIONS/BEANUTILS] Is there a comparator that can
> dynamically pick a method to call on a bean?
> 
> 
> Hi all,
> 
> Attached is my first attempt at submitting a BeanComparator, 
> along with the
> test case..  However, i am running into two issues becomes of 
> my lack of
> familiarty with beans that are causing me pain.  However, in my app,
> everything is working great!  My testcase is attached.
> 
> 1) the test suite fails because my test object which has a 
> getBeanValue and
> setBeanValue causes the WrapDynaBean class to throw an exception that
> "value" has no read method..  Yet it does, and in other uses of the
> BeanComparator in my code it works great.
> 
> 2) All comparisions are string comparisons..  So when I 
> compare Bigdecimals
> 2, 12, and 22, the orders is 12, 2, 22!  Do I need to hand in 
> another class
> to cast the objects to?
> 
> Also, I would love to see the ComparatorUtils, I created my own one to
> handle the reversing of my sorts based on the text values 
> ASC/DESC, and
> removed them from my BeanComparator.
> 
> I have also attached my LowercaseComparator..  I was sorting 
> columns of
> String data, and noticed that if I didn't lowercase them, the 
> A versus a
> differenced caused funny looking ordering.  I also set up
> LowercaseComparator and BeanComparator to work as decorators 
> (similar to
> ReverseComparator).  Lastly, for the bean comparator, I am using
> PropertyUtils, so if you can pass in NESTED properties!  customer.name
> results in getCustomer().getName() being returned!  I would 
> love to add
> jxPath converter as I build up some more experience!
> 
> Here is some sample code:
> 
>       public static Comparator sortedBean( String sortProperty, String
> sortPolarity )
>               throws java.lang.IllegalArgumentException {
>               Comparator c = null;
>               sortPolarity = sortPolarity.toUpperCase();
>               if ( !sortPolarity.equals( ASC ) && 
> !sortPolarity.equals( DESC ) ) {
>                       throw new 
> java.lang.IllegalArgumentException( "The argument:" +
> sortPolarity + " was invalid." );
>               }
>               if ( sortPolarity.equals( ASC ) ) {
>                       c = new BeanComparator( sortProperty, 
> new LowercaseComparator() );
>               }
>               else {
>                       c = new ReverseComparator( new 
> BeanComparator( sortProperty, new
> LowercaseComparator() ) );
> 
>               }
>               return c;
>       }
> 
> 
> Any suggestions/help would be much appreciated, and I would 
> love to see
> these added to the comparators available!
> 
> Eric
> 
> -----Original Message-----
> From: Michael A. Smith [mailto:[EMAIL PROTECTED]]
> Sent: Friday, June 07, 2002 3:07 PM
> To: Jakarta Commons Developers List
> Subject: RE: [COLLECTIONS/BEANUTILS] Is there a comparator that can
> dynamically pick a method to call on a bean?
> 
> 
> On Fri, 7 Jun 2002, Henri Yandell wrote:
> > Sorry Eric, I'm not sure you got my question.
> >
> > BeanComparator = good, +1. I think it'd be great to commit a
> > BeanComparator.
> >
> > The ASC/DESC bit is unnecessary I think due to 
> ReverseComparator. This is
> > an opinion though, I don't believe in ASC/DESC in 
> Comparators. So I was
> > just -1 on the Polarity part of your BeanComparator :)
> >
> > Morgan or Michael may want to veto that though :)
> 
> Neither of us can veto your veto.  We can try to twist your 
> arm, but in
> this case, I have no reason to: I agree with you.  The reverse
> comparator can provide the complementary ascending or descending
> behavior.
> 
> regards,
> michael
> 
> 
> --
> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
> 

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to