commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/beanutils/optional/bean-collections/src/java/org/apache/commons/beanutils BeanComparator.java
Date Thu, 03 Jun 2004 21:36:39 GMT
rdonkin     2004/06/03 14:36:39

  Modified:    beanutils/optional/bean-collections/src/java/org/apache/commons/beanutils
                        BeanComparator.java
  Log:
  Added equals and hashcode. Fixes bug #27381. Patch submitted by Brian Westrich.
  
  Revision  Changes    Path
  1.2       +32 -0     jakarta-commons/beanutils/optional/bean-collections/src/java/org/apache/commons/beanutils/BeanComparator.java
  
  Index: BeanComparator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/optional/bean-collections/src/java/org/apache/commons/beanutils/BeanComparator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BeanComparator.java	10 May 2004 19:57:58 -0000	1.1
  +++ BeanComparator.java	3 Jun 2004 21:36:39 -0000	1.2
  @@ -155,5 +155,37 @@
               throw new ClassCastException( e.toString() );
           }
       }
  +    
  +    /**
  +     * Two <code>BeanComparator</code>'s are equals if and only if
  +     * the wrapped comparators and the property names to be compared
  +     * are equal.
  +     */
  +    public boolean equals(Object o) {
  +        if (this == o) return true;
  +        if (!(o instanceof BeanComparator)) return false;
   
  +        final BeanComparator beanComparator = (BeanComparator) o;
  +
  +        if (!comparator.equals(beanComparator.comparator)) return false;
  +        if (property != null)
  +        {
  +            if (!property.equals(beanComparator.property)) return false;
  +        }
  +        else
  +        {
  +            return (beanComparator.property == null);
  +        }
  +
  +        return true;
  +    }
  +
  +    /**
  +     * Hashcode compatible with equals.
  +     */ 
  +    public int hashCode() {
  +        int result;
  +        result = comparator.hashCode();
  +        return result;
  +    }
   }
  
  
  

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


Mime
View raw message