Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: v_borchert@despammed.com (Volker Borchert) Newsgroups: comp.lang.java.programmer Subject: Re: equals(), Sets, Maps, and degrees of equality Date: 10 Nov 2011 04:42:41 GMT Organization: Private site at Eddersheim, Germany Lines: 22 Distribution: world Message-ID: References: <24123649.762.1320892382934.JavaMail.geo-discussion-forums@vbmh5> <2011110922100694284-angrybaldguy@gmailcom> X-Trace: individual.net wLz5D6D6zRVzIpOG5E/1dAMq9RmJC0viO4oEuKktogVJFaZ9aO Cancel-Lock: sha1:BaVZJvrd4qPJ6cFs1KKDCaOjBBo= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9817 Owen Jacobson wrote: > > [ class to be used in multiple Maps with different equalities ] > > > > I suppose I could create a wrapper class for each purpose which only > > overrides equals() and hashcode(), but that seems very unsatisfying and > > inefficient. > > That's one option, and it's not as inefficient (at least in terms of > run time) as you might expect, unless you have several million wrappers > kicking around. It's clunky to write, true. > > Another option is the TreeSet and TreeMap classes, which have slightly > worse lookup and insertion complexity guarantees (amortized O(log n) vs > amortized O(1) on lookup, for example) but allow passing a Comparator > that also controls equality tests for that set or map. Yet another option is to write your own HashMap. -- "I'm a doctor, not a mechanic." Dr Leonard McCoy "I'm a mechanic, not a doctor." Volker Borchert