FHIR Chat · equals and hashcode in fhir.core classes · hapi

Stream: hapi

Topic: equals and hashcode in fhir.core classes


view this post on Zulip Patrick Werner (Apr 28 2021 at 09:38):

I asked about this topic already in the implementer stream:
https://chat.fhir.org/#narrow/stream/179166-implementers/topic/Java.20FHIR.20lib.3A.20equals.20.26.20hashcode

view this post on Zulip Patrick Werner (Apr 28 2021 at 09:40):

As equals and hashcode aren't overriden in the FHIR Model classes, many functions (i wanted to use stream().distinct(), and ArrayList.containsAll()) aren't working as expected.
I proposed to override equals with the already existing deepEquals() function, which is currently considered.

view this post on Zulip Patrick Werner (Apr 28 2021 at 09:40):

This thread was started to inform the community and ask for feedback about this intended change.

view this post on Zulip Patrick Werner (Apr 28 2021 at 09:41):

@Mark Iantorno @James Agnew

view this post on Zulip Oliver Egger (Apr 28 2021 at 10:46):

:+1:

view this post on Zulip Grahame Grieve (Apr 28 2021 at 20:50):

I use equals widely in the core code, when I'm using Maps. I'll have to review the Map usages extensively to see whether a change to equals() will break things

view this post on Zulip Grahame Grieve (Apr 28 2021 at 20:50):

and sets

view this post on Zulip Patrick Werner (Apr 29 2021 at 10:59):

so you are using the equals() from the Java.Objects?
I think the simple check: if (this == otherObject) { return true;
should be included in the equals method (but also in the shallow and deepEquals). As this should speed up checking when comparing the same object to itself.

view this post on Zulip Grahame Grieve (Apr 29 2021 at 20:15):

that's true, but it wasn't the speed we were concerned about

view this post on Zulip Grahame Grieve (Apr 29 2021 at 20:16):

HashMap<N, V> uses .equals on N. (as opposed to IdentityHashMap<N,V>) I will have to review all the Maps I use. And I suspect that everyone else will as well, if we make this change

view this post on Zulip Jens Villadsen (May 03 2021 at 18:08):

This should be fixed ASAP!

view this post on Zulip Patrick Werner (Jul 24 2021 at 17:23):

any updates?


Last updated: Apr 12 2022 at 19:14 UTC