1

I have created subclasses of XOM Element and would like to use them with Containers such as Set or HashMap. However these require an equals(Object obj) method. I have implemented an algorithm for equality but cannot use it as XOM.Node() declares equals(Object obj) to be final. Is there any way I can easily overcome this? [I could create a wrapper / delegate if that is the only way].

peter.murray.rust
  • 37,407
  • 44
  • 153
  • 217

1 Answers1

1

All XOM nodes have equals methods and hashCode methods, as do all Java objects, use them with Containers such as Set or HashMap. The decision to support only identity equality was deliberate, and that's why the equals method is final. The question is why do you need to use a different notion of equality? E.g. if two nodes look the same but are in different positions, or are in different documents, they are usually considered to be different elements. What's the use case for treating them as the same?

  • Thanks Eliotte. I agree with the "usually". I wish to compare (and index on) elements which have equivalent representations for my problem (there may be lexical differences in - say - floating point numbers or dates or some other fields). Serialization won't do this. I have written the equality methods that work for my purposes. For example I may wish to exclude elements that are identical for me. I shall probably create my own containers to manage them. – peter.murray.rust Apr 24 '13 at 14:37