-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proper implementation of equals(Object) and hashCode() #3
Comments
Is this still on the roadmap? |
Kind of but in a slightly different way than described above. I want to approach this with an adapter class as described in dmfs/jems#182. This allows to compare URIs in different ways. For instance, a simple |
It would be nice to have a similar approach to toString, if there isn't one already. |
@gordom6 what exactly do you mean? There is a
|
I must have misunderstood you. I thought you were going to do composition so that the Uri instance has the methods (equals, hashCode toString), instead of relying on code like the above. So
Such that
Such that I love your library, but having to call a helper to get a string representation is awkward. I was thinking about doing something like the above for |
I don't consider A The same applies to |
In order to be able to check
Uri
s (and their components) for equality and put them intoSet
s or use them as keys in aMap
, as a developer I want proper support forequals(Object)
andhashCode()
.Before we can approach this we need to define the correct behavior. For instance as per RFC 3986, two URIs are considered to represent the same resource if their normalized forms are equal. What does this mean with respect to
equals(Object)
? Should we normalize theUri
s before we compare them or do we leave that to the developer?In general this could potentially result in a lot of duplicate code, if every implementation has its own
equals(Object)
andhashCode()
methods. So the idea is to create decorators or adapters that add the ability to useequals(Object)
andhashCode()
. Something likenew Hashable(uri)
ornew Equalable(uri)
. However since all other objects still have a default implementation of these methods a developer could easily do it wrong without noticing. The current idea to handle this is to throw anUnsupportedOperationException
inequals(Object)
andhashCode()
of objects which do not support hashing and comparison. The behavior would be similar to adding non-hashable objects to a set in Python. This could be achieved by inheriting from an abstract base object class.The text was updated successfully, but these errors were encountered: