Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #2631

Re: Refactoring discovery

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail
From Lew <noone@lewscanon.com>
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 <in0u43$8ib$1@news.albasani.net> (permalink)
References <kbgoo6dfrkh58r3ogel9nb6rekrs258it2@4ax.com> <imi0cq$ah4$1@dont-email.me> <imjjus$2cj$1@lust.ihug.co.nz> <e7Mkp.1468$0s5.314@newsfe17.iad> <in07ga$g5q$1@dont-email.me>
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 <in07ga$g5q$1@dont-email.me>
Cancel-Lock sha1:DBibAtanWYlHiY8dMbr0G1+hRko=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:2631

Show key headers only | View raw


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

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar


Thread

Re: Refactoring discovery David Lamb <dalamb@cs.queensu.ca> - 2011-03-30 16:10 -0400
  Re: Refactoring discovery David Lamb <dalamb@cs.queensu.ca> - 2011-03-30 16:25 -0400
  Re: Refactoring discovery Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-03-30 17:31 -0400
    Re: Refactoring discovery markspace <-@.> - 2011-03-30 15:52 -0700
    Re: Refactoring discovery Lew <noone@lewscanon.com> - 2011-03-30 23:58 -0400

csiph-web