Return-Path: Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 28007 invoked by uid 500); 25 Aug 2003 21:04:52 -0000 Received: (qmail 27975 invoked from network); 25 Aug 2003 21:04:52 -0000 Received: from minotaur.apache.org (209.237.227.194) by daedalus.apache.org with SMTP; 25 Aug 2003 21:04:52 -0000 Received: (qmail 88381 invoked by uid 1289); 25 Aug 2003 21:05:02 -0000 Date: 25 Aug 2003 21:05:02 -0000 Message-ID: <20030825210502.88380.qmail@minotaur.apache.org> From: rdonkin@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/beanutils/src/java/org/apache/commons/beanutils BeanComparator.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N rdonkin 2003/08/25 14:05:02 Modified: beanutils/src/java/org/apache/commons/beanutils BeanComparator.java Log: Added no-argument constructor for use in bean-centric environments. Revision Changes Path 1.5 +31 -6 jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BeanComparator.java Index: BeanComparator.java =================================================================== RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BeanComparator.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- BeanComparator.java 15 Jan 2003 21:59:38 -0000 1.4 +++ BeanComparator.java 25 Aug 2003 21:05:02 -0000 1.5 @@ -76,13 +76,27 @@ private String property; private Comparator comparator; + /** + *

Constructs a Bean Comparator without a property set. + * Note that this is intended to be used + * only in bean-centric environments. + *

+ * Until {@link setProperty} is called with a non-null value. + * this comparator will compare the Objects only. + *

+ */ + public BeanComparator() { + this( null ); + } + /** * Creates a Bean comparator that calls the property specified * on the objects. - * If you pass in a null, the BeanComparator defaults to comparing + * Defaults to comparing * based on the natural order, that is java.lang.Comparable. * - * @param property String name of bean property + * @param property String name of bean property. + * If the property passed in is null then the actual objects will be compared */ public BeanComparator( String property ) { this( property, ComparableComparator.getInstance() ); @@ -94,6 +108,8 @@ * * @param property String method name to call to compare * @param comparator Comparator to call afterwords! + * If you pass in a null, the BeanComparator defaults to comparing + * based on the natural order, that is java.lang.Comparable. */ public BeanComparator( String property, Comparator comparator ) { setProperty( property ); @@ -104,6 +120,7 @@ * Sets the method to be called to compare two JavaBeans * * @param property String method name to call to compare + * If the property passed in is null then the actual objects will be compared */ public void setProperty( String property ) { this.property = property; @@ -113,7 +130,8 @@ /** * Gets the property attribute of the BeanComparator * - * @return String method name to call to compare + * @return String method name to call to compare. + * A null value indicates that the actual objects will be compared */ public String getProperty() { return property; @@ -130,12 +148,19 @@ /** * Compare two JavaBeans by their shared property. + * If {@link getProperty} is null then the actual objects will be compared. * * @param o1 Object The first bean to get data from to compare against * @param o2 Object The second bean to get data from to compare * @return int negative or positive based on order */ public int compare( Object o1, Object o2 ) { + + if ( property == null ) { + // compare the actual objects + return comparator.compare( o1, o2 ); + } + try { Object value1 = PropertyUtils.getProperty( o1, property ); Object value2 = PropertyUtils.getProperty( o2, property );