Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 8581 invoked from network); 10 Jun 2002 20:50:12 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 10 Jun 2002 20:50:12 -0000 Received: (qmail 28605 invoked by uid 97); 10 Jun 2002 20:50:16 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 28567 invoked by uid 97); 10 Jun 2002 20:50:15 -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 28555 invoked by uid 98); 10 Jun 2002 20:50:15 -0000 X-Antivirus: nagoya (v4198 created Apr 24 2002) Message-ID: From: "Jack, Paul" To: 'Jakarta Commons Developers List' Subject: RE: [COLLECTIONS/BEANUTILS] Is there a comparator that can dynami cally pick a method to call on a bean? Date: Mon, 10 Jun 2002 13:45:03 -0700 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N FYI, java.lang.String.CASE_INSENSITIVE_ORDER does what your LowercaseComparator does, but somewhat more efficiently. -Paul > -----Original Message----- > From: Eric Pugh [mailto:epugh@upstate.com] > 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:mas@apache.org] > 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: > > For additional commands, e-mail: > > -- To unsubscribe, e-mail: For additional commands, e-mail: