ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Manifest.java
Date Mon, 29 Apr 2002 11:02:49 GMT
conor       02/04/29 04:02:49

  Modified:    src/main/org/apache/tools/ant/taskdefs Manifest.java
  Log:
  Improve equals implementation
  
  Revision  Changes    Path
  1.33      +70 -36    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Manifest.java
  
  Index: Manifest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Manifest.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -w -u -r1.32 -r1.33
  --- Manifest.java	15 Apr 2002 13:36:17 -0000	1.32
  +++ Manifest.java	29 Apr 2002 11:02:49 -0000	1.33
  @@ -177,18 +177,41 @@
           }
   
           /**
  +         * @see java.lang.Object#hashCode
  +         */
  +        public int hashCode() {
  +            int hashCode = 0;
  +            
  +            if (name != null) {
  +                hashCode += name.hashCode();
  +            }
  +            
  +            hashCode += values.hashCode();
  +            return hashCode;
  +        }
  +
  +        /**
            * @see java.lang.Object#equals
            */
           public boolean equals(Object rhs) {
  -            if (!(rhs instanceof Attribute)) {
  +            if (rhs == null || rhs.getClass() != getClass()) {
                   return false;
               }
   
  +            if (rhs == this) {
  +                return true;
  +            }
  +
               Attribute rhsAttribute = (Attribute) rhs;
  -            return (name != null && rhsAttribute.name != null &&
  -                    getKey().equals(rhsAttribute.getKey()) &&
  -                    values != null && 
  -                    CollectionUtils.equals(values, rhsAttribute.values));
  +            String lhsKey = getKey();
  +            String rhsKey = rhsAttribute.getKey();
  +            if ((lhsKey == null && rhsKey != null) 
  +                 || (lhsKey != null && rhsKey == null)
  +                 || !lhsKey.equals(rhsKey)) {
  +                return false;
  +            }
  +            
  +            return CollectionUtils.equals(values, rhsAttribute.values);
           }
   
           /**
  @@ -642,30 +665,35 @@
           }
   
           /**
  -         * @see java.lang.Object#equals
  +         * @see java.lang.Object#hashCode
            */
  -        public boolean equals(Object rhs) {
  -            if (!(rhs instanceof Section)) {
  -                return false;
  +        public int hashCode() {
  +            int hashCode = 0;
  +            
  +            if (name != null) {
  +                hashCode += name.hashCode();
               }
   
  -            Section rhsSection = (Section) rhs;
  -            if (attributes.size() != rhsSection.attributes.size()) {
  -                return false;
  +            hashCode += attributes.hashCode();
  +            return hashCode;
               }
   
  -            for (Enumeration e = attributes.keys(); e.hasMoreElements();) {
  -                String attributeName = (String) e.nextElement();
  -                Object attributeValue  = attributes.get(attributeName);
  -                Object rhsAttributeValue 
  -                    = rhsSection.attributes.get(attributeName);
  -                if (!attributeValue.equals(rhsAttributeValue)) {
  +        /**
  +         * @see java.lang.Object#equals
  +         */
  +        public boolean equals(Object rhs) {
  +            if (rhs == null || rhs.getClass() != getClass()) {
                       return false;
                   }
  -            }
   
  +            if (rhs == this) {
               return true;
           }
  +
  +            Section rhsSection = (Section) rhs;
  +            
  +            return attributes.equals(rhsSection.attributes);
  +        }
       }
   
   
  @@ -938,13 +966,32 @@
       }
   
       /**
  +     * @see java.lang.Object#hashCode
  +     */
  +    public int hashCode() {
  +        int hashCode = 0;
  +        
  +        if (manifestVersion != null) {
  +            hashCode += manifestVersion.hashCode();
  +        }
  +        hashCode += mainSection.hashCode();
  +        hashCode += sections.hashCode();
  +        
  +        return hashCode;
  +    }
  +    
  +    /**
        * @see java.lang.Object#equals
        */
       public boolean equals(Object rhs) {
  -        if (!(rhs instanceof Manifest)) {
  +        if (rhs == null || rhs.getClass() != getClass()) {
               return false;
           }
   
  +        if (rhs == this) {
  +            return true;
  +        }
  +        
           Manifest rhsManifest = (Manifest) rhs;
           if (manifestVersion == null) {
               if (rhsManifest.manifestVersion != null) {
  @@ -953,25 +1000,12 @@
           } else if (!manifestVersion.equals(rhsManifest.manifestVersion)) {
               return false;
           }
  -        if (sections.size() != rhsManifest.sections.size()) {
  -            return false;
  -        }
   
           if (!mainSection.equals(rhsManifest.mainSection)) {
               return false;
           }
   
  -        Enumeration e = sections.elements(); 
  -        while (e.hasMoreElements()) {
  -            Section section = (Section) e.nextElement();
  -            Section rhsSection 
  -                = (Section) rhsManifest.sections.get(section.getName());
  -            if (!section.equals(rhsSection)) {
  -                return false;
  -            }
  -        }
  -
  -        return true;
  +        return sections.equals(rhsManifest.sections);
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message