Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: Refactoring discovery Date: Wed, 30 Mar 2011 23:58:02 -0400 Organization: albasani.net Lines: 30 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net tFzLjd2i4Rz53Mfpqk3bjh10Xfuhz4I4IDanbbTMkK7pDIqqejeK3CArKM0oCp4mvXycnF2dwNVpm7kFq3PROg== NNTP-Posting-Date: Thu, 31 Mar 2011 03:57:56 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="sZ4o+jTespt4qZ+DoZIbAj01rr3f0Q0Puk/ngKhV6Xq/fH0MfUmcI3SPHyxgLtSspriC+jU1DbVRPSfeUgtr4RZi/xYH6JG0NfZxHDC03unOTMKDZD9mLkC9jes41twb"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 In-Reply-To: Cancel-Lock: sha1:DBibAtanWYlHiY8dMbr0G1+hRko= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:2631 Joshua Cranmer wrote: > Well, another way to implement this is: > > public boolean hasKey(Y y) { > LocPtr ptr = getWhereToInsert(y); > this.cachedPtr = ptr; > return ptr.valid(); > } > > public void addPair(Y y, Object obj) { > LocPtr ptr; > if (cachedPtr && cachedPtr.y == y) Umm, that won't compile in Java. > ptr = cachedPtr; > else > ptr = getWhereToInsert(y); > ptr.insert(obj); > } > > Which pretty much gets you the "benefit" of combining them into one single > operation without needing to provide all of the back-level predicate code > operations (set-if-present, set-if-not-present, etc.) Unless you're in multi-threaded land. In that case, don't think tacking 'synchronized' onto your method definitions will help. -- Lew