Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.21.MISMATCH!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: equals(), Sets, Maps, and degrees of equality Date: Fri, 11 Nov 2011 14:21:43 -0800 (PST) Organization: http://groups.google.com Lines: 37 Message-ID: <364616.2083.1321050103231.JavaMail.geo-discussion-forums@prms22> References: <24123649.762.1320892382934.JavaMail.geo-discussion-forums@vbmh5> <663d43b1-2c58-40ea-90d5-d46b8ae821e5@cc2g2000vbb.googlegroups.com> <5a705514-4b5e-48c2-8984-83e3b62b23b9@y7g2000vbe.googlegroups.com> <0ac33ed5-19cc-4654-ba74-8df90262cd51@cu3g2000vbb.googlegroups.com> Reply-To: comp.lang.java.programmer@googlegroups.com NNTP-Posting-Host: 2620:0:1000:2404:224:d7ff:fe69:5838 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1321050462 431 127.0.0.1 (11 Nov 2011 22:27:42 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 11 Nov 2011 22:27:42 +0000 (UTC) In-Reply-To: <0ac33ed5-19cc-4654-ba74-8df90262cd51@cu3g2000vbb.googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2620:0:1000:2404:224:d7ff:fe69:5838; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 X-Google-Web-Client: true Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9858 Sean Mitchell wrote: ... > I think, fundamentally, that is the problem. I don't think that Dog > or any subclass of Dog should have to be in any way concerned with > how I want to use him in a collection. Although IMO it is reasonable > for Dog to know whether or nor he is the same as another Dog in all > the ways that are important to Dogs. >=20 > The core of the issue for me is that the most commonly used > implementations of Set (possibly Map was a poor example, as has been > illustrated by Andreas and others) rely solely on the object's > equals() to determine equivalence. The core of the issue is that you want to use the wrong entity as your key. The fault, dear Brutus, lies not in our 'equals()' method but in ourselves. > TreeSet will take a Comparator as pointed out, and so probably this > is good enough, but it seems a little hackish to use a Comparator, > and a SortedSet to solve a problem of equality (or perhaps, > equivalency). "Seems"? That's a pretty subjective statement without any engineering basi= s. What is "hackish"? That is the standard solution and why 'Comparator' = exists in the API. The burden of proof is on the one claiming "hackishness= ", along with the burden of definition for such a vague, subjective term, e= specially when paired with the hand-waving, responsibility-ducking "seems". I'm here to tell you, there's nothing hackish about using a 'Comparator'. = That's a strange sentiment coming from someone who wants to hackishly use t= he 'Dog' class for a key where he means 'Breed'. Maybe if your model wasn'= t so tangled and illogical you'd have an easier time of it. --=20 Lew