[jdom-interest] Namespace.hashcode patch

Bryan Thale thale at labs.mot.com
Wed May 30 12:50:59 PDT 2001


Greetings all,

When Namespace.equals() was modified to compare only URI's and not
prefixes, hashCode() was not similarly adjusted.  Since this breaks the
contract established by java.lang.Object, I would like to propose that
hashCode() be modified to simply return uri.hashCode().

Attached is a proposed patch to Namespace.java to bring it back into
compliance with the Object interface.  It also simplifies the patch made
to equals() to simply return the result of uri.equals().

If this patch is acceptable, could a committer apply it to the
repository?

Regards,
Bryan.
--
Bryan Thale
Networks & Infrastructure Research, Motorola Labs
bryan.thale at motorola.com

Index: ./src/java/org/jdom/Namespace.java
===================================================================
RCS file: /home/cvspublic/jdom/src/java/org/jdom/Namespace.java,v
retrieving revision 1.27
diff -r1.27 Namespace.java
244,248c244
<             Namespace ns = (Namespace)ob;
<             // Compare URIs only
<             if (ns.getURI().equals(uri)) {
<                 return true;
<             }
---
>             return uri.equals(((Namespace)ob).uri);
276,278c272
<         // Since neither URI nor prefix are guaranteed to be unique,
<         // use the combination
<         return (prefix+uri).hashCode();
---
>         return uri.hashCode();

The command completed successfully.




More information about the jdom-interest mailing list