BandedUpdater { public int addItem(K key, V item) { UpdateGroup ug = null; synchronized(pending_updates) { if (pending_updates.containsKey(key)) { ug = pending_updates.get(key); } else { ug = new UpdateGroup(); pending_updates.put(key, ug); } ug.items.add(item); } try { to_check.put(key); ug.await(); } catch(java.lang.InterruptedException e) { throw new RuntimeException(e); } return ug.new_size; } BandedUpdater(Map<K, HashSet<V> > map, int threads); int addItem(K key, V item);  }
@Test public void testBasic() { TreeMap<String, HashSet<String> > map=new TreeMap<String, HashSet<String>>(); BandedUpdater<String, String> bu = new BandedUpdater<String,String>(map,2); bu.addItem("a","cow"); bu.addItem("a","wolf"); bu.addItem("a","tomato"); Assert.assertEquals(1, map.size()); Assert.assertEquals(3, map.get("a").size()); bu.addItem("b","tomato"); Assert.assertEquals(2, map.size()); }