[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: SAX2 Namespace Support
David> David Megginson <URL:mailto:david@m...> 0> In article <m3r9fwtuv8.fsf@l...>, David wrote: David> In principle (the principle of least surprise), it's very bad David> behaviour for two objects to be == in C++ or equals() in Java David> if any of their publicly-accessible fields differ. Think of David> sets, for example. You could follow the example of java.lang.String and define equals() to compare all public data (as usual), and define an additional method equalsIgnorePrefix() which doesn't. The problem with this is that hashCode() has to be consistent with equals(), but sometimes you want to use a hashCode() based on equalsIgnorePrefix(). I've solved this in the past (for a case-insensitive String class) by making a wrapper that defines equals() in terms of equalsIgnoreCase(), and a corresponding hashCode(). I'm not sure I like this for SAX2 though, as we should be making the common case - ignoring the prefix - the simplest. public class QName { public String getPrefix(); public String getUri(); public String getLocal(); public int hashCode(); // based on prefix, URI, local public boolean hashCodeIgnorePrefix(Object o); // based on URI, local public boolean equals(Object o); // based on prefix, URI, local public boolean equalsIgnorePrefix(Object o); // based on URI, local } public class QNameIgnorePrefix { private QName name; public QNameIgnorePrefix(QName name) { this.name = name; } public String getUri() { return name.getUri(); } public String getLocal() { return name.getLocal(); } public int hashCode() { return name.hashCodeIgnorePrefix(); } public boolean equals(Object o); { return name.equalsIgnorePrefix(o); } } -- xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@i... Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ or CD-ROM/ISBN 981-02-3594-1 Please note: New list subscriptions now closed in preparation for transfer to OASIS.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|