Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 79032 invoked from network); 7 Jun 2002 12:53:21 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 7 Jun 2002 12:53:21 -0000 Received: (qmail 21817 invoked by uid 97); 7 Jun 2002 12:53:20 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 21801 invoked by uid 97); 7 Jun 2002 12:53:19 -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 21789 invoked by uid 98); 7 Jun 2002 12:53:19 -0000 X-Antivirus: nagoya (v4198 created Apr 24 2002) From: "Eric Pugh" To: "'Jakarta Commons Developers List'" Subject: [COLLECTIONS/BEANUTILS] Is there a comparator that can dynamically pick a method to call on a bean? Date: Fri, 7 Jun 2002 08:47:27 -0400 Message-ID: <000001c20e21$7dbaf7f0$bdad94d0@mccom.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2910.0) X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Importance: Normal In-Reply-To: <037e01c20e0a$6c959780$09cb8842@galina> X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Hi all, I have a series of Torque objects that I want to sort. Sometimes I want to sort by MethodA, sometiems by MethodB. (Basically mapping onto all the columns in my database). Right now, I have a comparator compare method that looks like this: public int compare( Object o1, Object o2 ) { Daughterboard db1 = (Daughterboard) o1; Daughterboard db2 = (Daughterboard) o2; int sort = 0; if ( sortMethod.equals( "ScintillationFileNumber" ) ) { /* * if ( db1 == null == db2 ) { * return 0; * } * else if (db1 == null && */ sort = Strings.clean( db1.getScintillationFileNumber() ).compareTo( Strings.clean( db2.getScintillationFileNumber() ) ); } else if ( sortMethod.equals( "DaughterboardId" ) ) { sort = db1.getDaughterboardId().compareTo( db2.getDaughterboardId() ); } if ( sortPolarity.equals( "desc" ) ) { sort = sort * -1; } return sort; } What I really want to do is pass in a sortMethod like ScintillationFileNumber, and dynamically call the objects getter for that name. If I wrap my object in a WrapDynaBean, and use that to call the data, will is actually change the ordering of my objects? Or should I just use the WrapDynaBean locally inside of my compare method to facilitate calling the methods? First time using BeanUtils, but it looks great.. Lastly, would a comparator like this be something of general interest to add to the collections list of comparators? Eric -- To unsubscribe, e-mail: For additional commands, e-mail: