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


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

Re: Concurrent bidirectional one-to-many map?

Path csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!goblin2!goblin.stu.neva.ru!news.nask.pl!news.nask.org.pl!news.icm.edu.pl!news.onet.pl!.POSTED!not-for-mail
From Michal Kleczek <kleku75@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: Concurrent bidirectional one-to-many map?
Date Mon, 09 May 2011 16:42:53 +0200
Organization http://onet.pl
Lines 58
Message-ID <iq8uha$g2k$1@news.onet.pl> (permalink)
References <iq1kf0$ee2$1@news.albasani.net> <iq1mmc$hbv$1@dont-email.me> <iq348b$iv1$1@news.albasani.net>
NNTP-Posting-Host 77-252-124-164.ip.netia.com.pl
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Trace news.onet.pl 1304952170 16468 77.252.124.164 (9 May 2011 14:42:50 GMT)
X-Complaints-To niusy@onet.pl
NNTP-Posting-Date Mon, 9 May 2011 14:42:50 +0000 (UTC)
User-Agent KNode/4.4.9
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3856

Show key headers only | View raw


Sebastian wrote:

>
> Thanks for the idea. I do not yet see how to deal with the
> one-to-many aspect of my problem.
> 
> To give an example, I'm trying to solve a problem like this:
> Associate tasks with workspaces, where a workspace may hold many
> tasks,but a task may be associate with at most one workspace.
> 
> Idea:
> 
>     private ConcurrentMap<Item, Workspace> wsMap =
>               new ConcurrentHashMap<Item, Workspace>();
> 
>      public boolean isAssigned( Item item ) {
>          return wsMap.containsKey( item );
>      }
> 
>      public void assign( Item item, Workspace ws ) {
>          wsMap.putIfAbsent( item, ws );
>          if( !ws.equals( wsMap.get( item) ) ) {
>             throw new NotAssignableException();
>          }
>      }
> 
> 
> Now I want to be able to close a workspace, releasing all tasks
> to be assignable again to other workspaces.
> 
>      public void closeWorkspace( Workspace ws ) {
>        // how do this efficiently? iterate over all
>        // entries (holding a write lock) and remove it
>        // when the value equals ws?
>      }
> 

Maybe it is a dumb question but: is there any reason not to implement it 
simply as

class Item {
  private Workspace workspace;
  //getters setters
}

class Workspace {
  private Collection<Item> items;
  //getters setters

  public close() {
    for (final Item item : items) {
      //release item
    }
  }
}

-- 
Michal

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


Thread

Concurrent bidirectional one-to-many map? Sebastian <sebastian@undisclosed.invalid> - 2011-05-06 22:07 +0200
  Re: Concurrent bidirectional one-to-many map? markspace <-@.> - 2011-05-06 13:45 -0700
    Re: Concurrent bidirectional one-to-many map? Sebastian <sebastian@undisclosed.invalid> - 2011-05-07 11:43 +0200
      Re: Concurrent bidirectional one-to-many map? Lew <noone@lewscanon.com> - 2011-05-07 07:59 -0400
        Re: Concurrent bidirectional one-to-many map? Lew <noone@lewscanon.com> - 2011-05-07 12:49 -0400
          Re: Concurrent bidirectional one-to-many map? Sebastian <sebastian@undisclosed.invalid> - 2011-05-07 21:34 +0200
      Re: Concurrent bidirectional one-to-many map? Patricia Shanahan <pats@acm.org> - 2011-05-07 06:40 -0700
        Re: Concurrent bidirectional one-to-many map? Tom Anderson <twic@urchin.earth.li> - 2011-05-08 04:51 +0100
          Re: Concurrent bidirectional one-to-many map? Robert Klemme <shortcutter@googlemail.com> - 2011-05-09 06:43 -0700
            Re: Concurrent bidirectional one-to-many map? Tom Anderson <twic@urchin.earth.li> - 2011-05-09 18:28 +0100
              Re: Concurrent bidirectional one-to-many map? Sebastian <sebastian@undisclosed.invalid> - 2011-05-09 22:57 +0200
                Re: Concurrent bidirectional one-to-many map? Lew <noone@lewscanon.com> - 2011-05-09 18:36 -0400
                Re: Concurrent bidirectional one-to-many map? Tom Anderson <twic@urchin.earth.li> - 2011-05-10 08:34 +0100
                Re: Concurrent bidirectional one-to-many map? Sebastian <sebastian@undisclosed.invalid> - 2011-05-11 10:09 +0200
                Re: Concurrent bidirectional one-to-many map? Sebastian <sebastian@undisclosed.invalid> - 2011-05-11 10:51 +0200
                Re: Concurrent bidirectional one-to-many map? Robert Klemme <shortcutter@googlemail.com> - 2011-05-11 04:55 -0700
                Re: Concurrent bidirectional one-to-many map? Lew <noone@lewscanon.com> - 2011-05-11 09:00 -0400
                Re: Concurrent bidirectional one-to-many map? Sebastian <sebastian@undisclosed.invalid> - 2011-05-11 20:47 +0200
      Re: Concurrent bidirectional one-to-many map? markspace <-@.> - 2011-05-07 09:35 -0700
      Re: Concurrent bidirectional one-to-many map? Michal Kleczek <kleku75@gmail.com> - 2011-05-09 16:42 +0200
  Re: Concurrent bidirectional one-to-many map? Roedy Green <see_website@mindprod.com.invalid> - 2011-05-07 03:46 -0700

csiph-web