mx4j/src/core/javax/management/openmbean OpenMBeanInfoSupport.java,1.10,1.11

Jeremy Boynes <[email protected]> Thu, 10 Feb 2005 02:03:54 +0000
Newsgroups gmane.comp.java.mx4j.cvs
Message-ID <[email protected]>
Update of /cvsroot/mx4j/mx4j/src/core/javax/management/openmbean
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8015/src/core/javax/management/openmbean

Modified Files:
	OpenMBeanInfoSupport.java 
Log Message:
Fix for [ 1115212 ] OpenMBeanInfoSupport has precise equals/hashcode
Well, equals is not well defined but the Set oriented definition for hashCode means that equals needs to work that way too.

Index: OpenMBeanInfoSupport.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/core/javax/management/openmbean/OpenMBeanInfoSupport.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** OpenMBeanInfoSupport.java	13 Nov 2004 16:38:22 -0000	1.10
--- OpenMBeanInfoSupport.java	10 Feb 2005 02:03:51 -0000	1.11
***************
*** 11,14 ****
--- 11,15 ----
  import java.io.Serializable;
  import java.util.Arrays;
+ import java.util.HashSet;
  import javax.management.MBeanAttributeInfo;
  import javax.management.MBeanConstructorInfo;
***************
*** 48,59 ****
        if (thisClassName != null ? !thisClassName.equals(otherClassName) : otherClassName != null) return false;
  
!       if (!Arrays.equals(getConstructors(), other.getConstructors())) return false;
!       if (!Arrays.equals(getAttributes(), other.getAttributes())) return false;
!       if (!Arrays.equals(getOperations(), other.getOperations())) return false;
!       if (!Arrays.equals(getNotifications(), other.getNotifications())) return false;
  
        return true;
     }
  
     public int hashCode()
     {
--- 49,64 ----
        if (thisClassName != null ? !thisClassName.equals(otherClassName) : otherClassName != null) return false;
  
!       if (!compare(getConstructors(), other.getConstructors())) return false;
!       if (!compare(getAttributes(), other.getAttributes())) return false;
!       if (!compare(getOperations(), other.getOperations())) return false;
!       if (!compare(getNotifications(), other.getNotifications())) return false;
  
        return true;
     }
  
+    private boolean compare(Object[] o1, Object[] o2) {
+       return new HashSet(Arrays.asList(o1)).equals(new HashSet(Arrays.asList(o2)));
+    }
+ 
     public int hashCode()
     {
***************
*** 61,68 ****
        {
           int hash = getClassName() == null ? 0 : getClassName().hashCode();
!          if (getConstructors() != null) hash += Arrays.asList(getConstructors()).hashCode();
!          if (getAttributes() != null) hash += Arrays.asList(getAttributes()).hashCode();
!          if (getOperations() != null) hash += Arrays.asList(getOperations()).hashCode();
!          if (getNotifications() != null) hash += Arrays.asList(getNotifications()).hashCode();
           hashCode = hash;
        }
--- 66,73 ----
        {
           int hash = getClassName() == null ? 0 : getClassName().hashCode();
!          if (getConstructors() != null) hash += new HashSet(Arrays.asList(getConstructors())).hashCode();
!          if (getAttributes() != null) hash += new HashSet(Arrays.asList(getAttributes())).hashCode();
!          if (getOperations() != null) hash += new HashSet(Arrays.asList(getOperations())).hashCode();
!          if (getNotifications() != null) hash += new HashSet(Arrays.asList(getNotifications())).hashCode();
           hashCode = hash;
        }



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click