users@jaxb.java.net

Re: equals() and hashCode()

From: <Andrew.Ferguson_at_arm.com>
Date: Tue, 18 Nov 2003 10:20:27 +0000

>In fact the problem of dealing with cycles were the primary reason why
>it's so hard to get this implementation right.
>
>Defining equality over cyclic graphs is possible, by the way. It's just
>isomorphism between two labeled graphs.

i thought graph isomorphism was np-complete though? so its likely that even
if the trouble of implementing this was gone through it wouldn't be worth
it in general (?)

What do you make of the argument that cyclic XML is such a rarity that it
would be reasonable to ignore it, at least for a first release of equals()
and hashCode() definitions? its a
very practical point of view that might catch most JAXB users problems.

(The code I'm working on needs to put a number of xml elements into a
java.util.Set - which fails without hashCode() implemented in some way or
another)

>> Has anyone tried the workarounds suggested? Performance isn't an issue
so
>> I'm happy to use Jakarta's reflective EqualsBuilder but wasn't sure that
>> all fields in JAXB generated classes should be processed by this. If all
>> fields should not be included as a definition of equality, is there some
>> automatic way to determine which should?
>
>I can't think of any case where you cannot compare all the fields.

thanks, thats very useful to know :)

>> *eg. if I understand correctly then unmarshalling couldn't produce an
>> object graph with cycles?
>
>Actually it can, if you think about ID/IDREF.

ah, I don't really know anything about those..

>> If a user creates an object graph with cycles and
>> tries to marshall it then its reasonable for the marshaller to go into a
>> loop - what else might the user mean?
>
>Again, it depends on the kind of cycles. And the marshaller will detect
>a cycle and complains, instead of dying with StackOverflowError.

So a third alternative (other than StackOverflowError/graph-isomorphism)
for implementing equality/hashCode would also be to detect and complain
also?

thanks,
Andrew



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net