-
Notifications
You must be signed in to change notification settings - Fork 11k
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
customizable equals/hashCode for Maps/Collections #188
Comments
Original comment posted by kevinb9n on 2009-06-10 at 03:43 PM We have an experimental version of this internally. It has a single interface with |
Original comment posted by zeitlinger on 2009-06-11 at 07:25 AM A discussion on Artima brought this up (in the discussion). |
Original comment posted by Ben.Lings on 2009-06-17 at 11:54 AM Dot Net has something similar: http://msdn.microsoft.com/en-us/library/ms132151.aspx (IEqualityComparer<T>) and its default implementation, EqualityComparer<T>.Default http://msdn.microsoft.com/en-us/library/ms224763.aspx The default implementation will use IEquatable<T>.Equals(T other) if T implements All Dot Net collection implementations that use a hashcode (Dictionary<TKey, TValue> Having used the Dot Net version, I would suggest changing the names of the methods so |
Original comment posted by ray.a.conner on 2009-08-03 at 08:03 PM Implementations need not be exposed, so it wouldn't be too much bloat. I think you
If you want, you can add a constant Equivalence implementation using reference |
Original comment posted by stephen.kestle on 2009-08-10 at 04:27 AM I had a conversation here about this a year ago (about Equators - either mailing list I created an issue for this at apache commons collections: https://issues.apache.org/jira/browse/COLLECTIONS-242 As in that ticket, there are times you want to equate objects under a different |
Original comment posted by kevinb9n on 2009-08-13 at 02:49 PM (No comment entered for this change.) Status: |
Original comment posted by kevinb9n on 2009-09-17 at 05:45 PM (No comment entered for this change.) Labels: - |
Original comment posted by kevinb9n on 2009-09-17 at 05:57 PM (No comment entered for this change.) Labels: |
Original comment posted by kevinb@google.com on 2010-04-23 at 08:40 PM At best we will consider this for MapMaker -- bug 337. I'm extremely reluctant to Status: |
Original comment posted by earwin on 2010-04-23 at 09:00 PM But there's a whole bunch of collections with Comparator-based equivalence which are |
Original comment posted by kevinb@google.com on 2010-04-23 at 09:16 PM Such comparators should be consistent with equals(): "Note that the ordering maintained by a sorted map (whether or not an explicit So that satisfies me as well. I'm just saying, to the extent you want to make this case, focus on making it for |
Original comment posted by stephen.kestle on 2010-10-12 at 09:54 PM I guess our spec is rather different from .Net, which has had this since version 2: http://msdn.microsoft.com/en-us/library/system.collections.iequalitycomparer.aspx. I comment again, as this again causes us significant pain as I'm supporting a project which has at least 3 ways of equating each different object type. I guess overall I'm thankful for google's spec-api approach after the headaches I had with apache-collection's "helpers" |
Original issue created by zeitlinger on 2009-06-10 at 07:54 AM
TreeMap has the advantage that one can specify which objects are equal
using a Comparator.
It would be useful to be able to specify this for HashMaps and generally
all collections that work with equals/hash
public interface Equalator/Equator<T> {
boolean equals(T left, T right);
}
public interface Hasher<T> extends Equalator<T> {
int hashCode(T t);
}
Apache collections allows you to override AbstractHashedMap.hash/isEqualKey
The text was updated successfully, but these errors were encountered: