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


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

Re: Refactoring discovery

From Lew <noone@lewscanon.com>
Newsgroups comp.lang.java.programmer
Subject Re: Refactoring discovery
Date 2011-03-30 23:58 -0400
Organization albasani.net
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>

Show all headers | 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