protected void addCachedBatchEnd(MarkovVertex start, MarkovEdge e, MarkovVertex v, Statement catalog_stmt, int idx, PartitionSet partitions, PartitionSet past_partitions) { ConcurrentHashMap<MultiKey<String>, Pair<MarkovEdge, MarkovVertex>> m = cache_batchEnd.get(start); if (m == null) { synchronized (this.cache_batchEnd) { m = this.cache_batchEnd.get(start); if (m == null) { m = new ConcurrentHashMap<MultiKey<String>, Pair<MarkovEdge, MarkovVertex>>(); this.cache_batchEnd.put(start, m); } } // SYNCH } MultiKey<String> cache_key = new MultiKey<String>(CatalogKey.createKey(catalog_stmt), Integer.toString(idx), partitions.toString(), past_partitions.toString()); m.putIfAbsent(cache_key, Pair.of(e, v)); }
@Override public void graphIntersection(Collection<INode> vertices, Collection<IConnection> edges) { final Collection<INode> filteredNodes = getGraph().getVertices().stream().filter(node -> !vertices.contains(node)).collect(Collectors.toList()); //existingNodes.values().removeAll(filteredNodes); //getGraph().getVertices() filteredNodes.stream().forEach(deleteNode -> { //final Collection<IConnection> incident = delegate.getGraph().getIncidentEdges(deleteNode); getGraph().removeVertex(deleteNode); idNodeMap.remove(deleteNode.getAddress()); }); final Collection<IConnection> filteredEdges = getGraph().getEdges().stream().filter(edge -> !edges.contains(edge)).collect(Collectors.toList()); filteredEdges.stream().forEach(deleteEdge -> { final MultiKey<IAddress> connectionKey = new MultiKey<>(deleteEdge.getSrc().getAddress(), deleteEdge.getDest().getAddress()); //final IConnection existing = idConnectionMap.get(connectionKey); getGraph().removeEdge(deleteEdge); idConnectionMap.remove(connectionKey); }); }
@Override public void writeConnection(IConnection connection) { final MultiKey<IAddress> connectionKey = new MultiKey<>(connection.getSrc().getAddress(), connection.getDest().getAddress()); final IConnection existing = idConnectionMap.get(connectionKey); /* if (existing != null) { existing.update(connection, replayUpdater); return; }*/ delegate.getGraph().addVertex(connection.getSrc()); delegate.getGraph().addVertex(connection.getDest()); delegate.getGraph().addEdge(connection, connection.getSrc(), connection.getDest()); idConnectionMap.put(connectionKey, connection); }
/** * Stores the value against the specified multi-key. * * @param value the value to store * @param keys the keys * @return the value previously mapped to this combined key, null if none */ public V putMultiKey(V value, K... keys) { int hashCode = hash(keys); int index = map.hashIndex(hashCode, map.data.length); AbstractHashedMap.HashEntry<MultiKey<K>, V> entry = map.data[index]; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, keys)) { V oldValue = entry.getValue(); map.updateEntry(entry, value); return oldValue; } entry = entry.next; } map.addMapping(index, hashCode, new MultiKey<K>(keys), value); return null; }
/** * Removes the specified multi-key from this map. * * @param keys the keys * @return the value mapped to the removed key, null if key not in map */ public Object remove(K... keys) { int hashCode = hash(keys); int index = map.hashIndex(hashCode, map.data.length); AbstractHashedMap.HashEntry<MultiKey<K>, V> entry = map.data[index]; AbstractHashedMap.HashEntry<MultiKey<K>, V> previous = null; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, keys)) { Object oldValue = entry.getValue(); map.removeMapping(entry, index, previous); return oldValue; } previous = entry; entry = entry.next; } return null; }
/** * Constructor * @param p_estimator * @param mappings * @param markovs */ public MarkovEstimator(CatalogContext catalogContext, PartitionEstimator p_estimator, MarkovGraphsContainer markovs) { super(p_estimator); this.catalogContext = catalogContext; this.markovs = markovs; this.cache_batchEnd = new HashMap<MarkovVertex, ConcurrentHashMap<MultiKey<String>,Pair<MarkovEdge,MarkovVertex>>>(); if (this.markovs != null && this.markovs.getHasher() == null) this.markovs.setHasher(this.hasher); // Create all of our parameter manglers this.manglers = new ParameterMangler[this.catalogContext.procedures.size() + 1]; for (Procedure catalog_proc : this.catalogContext.procedures) { if (catalog_proc.getSystemproc()) continue; this.manglers[catalog_proc.getId()] = ParameterMangler.singleton(catalog_proc); } // FOR if (debug.val) LOG.debug("Creating MarkovPathEstimator Object Pool"); TypedPoolableObjectFactory<MarkovPathEstimator> m_factory = new MarkovPathEstimator.Factory(this.catalogContext, this.p_estimator); this.pathEstimatorsPool = new TypedObjectPool<MarkovPathEstimator>(m_factory, hstore_conf.site.pool_pathestimators_idle); if (debug.val) LOG.debug("Creating MarkovEstimatorState Object Pool"); TypedPoolableObjectFactory<MarkovEstimatorState> s_factory = new MarkovEstimatorState.Factory(this.catalogContext); int num_idle = (int)(hstore_conf.site.network_incoming_limit_txns * hstore_conf.site.pool_scale_factor); this.statesPool = new TypedObjectPool<MarkovEstimatorState>(s_factory, num_idle); if (hstore_conf.site.markov_profiling) { this.profiler = new MarkovEstimatorProfiler(); } else { this.profiler = null; } }
protected Pair<MarkovEdge, MarkovVertex> getCachedBatchEnd(MarkovVertex start, Statement catalog_stmt, int idx, PartitionSet partitions, PartitionSet past_partitions) { Map<MultiKey<String>, Pair<MarkovEdge, MarkovVertex>> m = this.cache_batchEnd.get(start); Pair<MarkovEdge, MarkovVertex> found = null; if (m != null) { MultiKey<String> cache_key = new MultiKey<String>(CatalogKey.createKey(catalog_stmt), Integer.toString(idx), partitions.toString(), past_partitions.toString()); found = m.get(cache_key); } return (found); }
/** * Decorates the specified map to add the MultiKeyMap API and fast query. * The map must not be null and must be empty. * * @param map the map to decorate, not null * @throws IllegalArgumentException if the map is null or not empty */ public static <K,V> MultiKeyMap<K, V> decorate(AbstractHashedMap<MultiKey<K>, V> map) { if (map == null) { throw new IllegalArgumentException("Map must not be null"); } if (map.size() > 0) { throw new IllegalArgumentException("Map must be empty"); } return new MultiKeyMap<K, V>(map); }
/** * Gets the value mapped to the specified multi-key. * * @param keys the keys * @return the mapped value, null if no match */ public V get(K... keys) { int hashCode = hash(keys); AbstractHashedMap.HashEntry<MultiKey<K>, V> entry = map.data[map.hashIndex(hashCode, map.data.length)]; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, keys)) { return entry.getValue(); } entry = entry.next; } return null; }
/** * Checks whether the map contains the specified multi-key. * * @param keys the keys * @return true if the map contains the key */ public boolean containsKey(K... keys) { int hashCode = hash(keys); AbstractHashedMap.HashEntry<MultiKey<K>, V> entry = map.data[map.hashIndex(hashCode, map.data.length)]; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, keys)) { return true; } entry = entry.next; } return false; }
/** * Is the key equal to the combined key. * * @param entry the entry to compare to * @param keys the keys * @return true if the key matches */ protected boolean isEqualKey(AbstractHashedMap.HashEntry<MultiKey<K>, V> entry, K... keys) { MultiKey multi = (MultiKey) entry.getKey(); if (multi.size() != keys.length) { return false; } else { for (int i = 0; i < keys.length; i++) { K key = keys[i]; if ((key == null ? multi.getKey(i) != null : !key.equals(multi.getKey(i)))) { return false; } } } return true; }
/** * Removes all mappings where the first key is that specified. * <p/> * This method removes all the mappings where the <code>MultiKey</code> * has one or more keys, and the first matches that specified. * * @param key1 the first key * @return true if any elements were removed */ public boolean removeAll(Object key1) { boolean modified = false; MapIterator it = mapIterator(); while (it.hasNext()) { MultiKey multi = (MultiKey) it.next(); if (multi.size() >= 1 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0)))) { it.remove(); modified = true; } } return modified; }
/** * Removes all mappings where the first two keys are those specified. * <p/> * This method removes all the mappings where the <code>MultiKey</code> * has two or more keys, and the first two match those specified. * * @param key1 the first key * @param key2 the second key * @return true if any elements were removed */ public boolean removeAll(Object key1, Object key2) { boolean modified = false; MapIterator it = mapIterator(); while (it.hasNext()) { MultiKey multi = (MultiKey) it.next(); if (multi.size() >= 2 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) && (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1)))) { it.remove(); modified = true; } } return modified; }
/** * Removes all mappings where the first three keys are those specified. * <p/> * This method removes all the mappings where the <code>MultiKey</code> * has three or more keys, and the first three match those specified. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @return true if any elements were removed */ public boolean removeAll(Object key1, Object key2, Object key3) { boolean modified = false; MapIterator it = mapIterator(); while (it.hasNext()) { MultiKey multi = (MultiKey) it.next(); if (multi.size() >= 3 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) && (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1))) && (key3 == null ? multi.getKey(2) == null : key3.equals(multi.getKey(2)))) { it.remove(); modified = true; } } return modified; }
/** * Removes all mappings where the first four keys are those specified. * <p/> * This method removes all the mappings where the <code>MultiKey</code> * has four or more keys, and the first four match those specified. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @param key4 the fourth key * @return true if any elements were removed */ public boolean removeAll(Object key1, Object key2, Object key3, Object key4) { boolean modified = false; MapIterator it = mapIterator(); while (it.hasNext()) { MultiKey multi = (MultiKey) it.next(); if (multi.size() >= 4 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) && (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1))) && (key3 == null ? multi.getKey(2) == null : key3.equals(multi.getKey(2))) && (key4 == null ? multi.getKey(3) == null : key4.equals(multi.getKey(3)))) { it.remove(); modified = true; } } return modified; }
public void testMultiKeyRemoveAll1() { resetFull(); MultiKeyMap multimap = (MultiKeyMap) map; assertEquals(12, multimap.size()); multimap.removeAll(I1); assertEquals(8, multimap.size()); for (MapIterator it = multimap.mapIterator(); it.hasNext();) { MultiKey key = (MultiKey) it.next(); assertEquals(false, I1.equals(key.getKey(0))); } }
public void testMultiKeyRemoveAll2() { resetFull(); MultiKeyMap multimap = (MultiKeyMap) map; assertEquals(12, multimap.size()); multimap.removeAll(I2, I3); assertEquals(9, multimap.size()); for (MapIterator it = multimap.mapIterator(); it.hasNext();) { MultiKey key = (MultiKey) it.next(); assertEquals(false, I2.equals(key.getKey(0)) && I3.equals(key.getKey(1))); } }
public void testMultiKeyRemoveAll3() { resetFull(); MultiKeyMap multimap = (MultiKeyMap) map; assertEquals(12, multimap.size()); multimap.removeAll(I1, I1, I2); assertEquals(9, multimap.size()); for (MapIterator it = multimap.mapIterator(); it.hasNext();) { MultiKey key = (MultiKey) it.next(); assertEquals(false, I1.equals(key.getKey(0)) && I1.equals(key.getKey(1)) && I2.equals(key.getKey(2))); } }
public void testMultiKeyRemoveAll4() { resetFull(); MultiKeyMap multimap = (MultiKeyMap) map; assertEquals(12, multimap.size()); multimap.removeAll(I1, I1, I2, I3); assertEquals(10, multimap.size()); for (MapIterator it = multimap.mapIterator(); it.hasNext();) { MultiKey key = (MultiKey) it.next(); assertEquals(false, I1.equals(key.getKey(0)) && I1.equals(key.getKey(1)) && I2.equals(key.getKey(2)) && key.size() >= 4 && I3.equals(key.getKey(3))); } }
public void testClone() { MultiKeyMap map = new MultiKeyMap(); map.put(new MultiKey(I1, I2), "1-2"); Map cloned = (Map) map.clone(); assertEquals(map.size(), cloned.size()); assertSame(map.get(new MultiKey(I1, I2)), cloned.get(new MultiKey(I1, I2))); }
/** * Constructs a new MultiKeyMap that decorates a <code>HashedMap</code>. */ public MultiKeyMap() { super(); map = new HashedMap<MultiKey<K>, V>(); }
private MultiKey[] getMultiKeyKeys() { return new MultiKey[]{new MultiKey(I1, I2), new MultiKey(I2, I3), new MultiKey(I3, I4), new MultiKey(I1, I1, I2), new MultiKey(I2, I3, I4), new MultiKey(I3, I7, I6), new MultiKey(I1, I1, I2, I3), new MultiKey(I2, I4, I5, I6), new MultiKey(I3, I6, I7, I8), new MultiKey(I1, I1, I2, I3, I4), new MultiKey(I2, I3, I4, I5, I6), new MultiKey(I3, I5, I6, I7, I8), }; }
public Object[] getOtherKeys() { return new Object[]{new MultiKey(I1, I7), new MultiKey(I1, I8), new MultiKey(I2, I4), new MultiKey(I2, I5), }; }
public void testMultiKeyGet() { resetFull(); MultiKeyMap multimap = (MultiKeyMap) map; MultiKey[] keys = getMultiKeyKeys(); Object[] values = getSampleValues(); for (int i = 0; i < keys.length; i++) { MultiKey key = keys[i]; Object value = values[i]; switch (key.size()) { case 2: assertEquals(value, multimap.get(key.getKey(0), key.getKey(1))); assertEquals(null, multimap.get(null, key.getKey(1))); assertEquals(null, multimap.get(key.getKey(0), null)); assertEquals(null, multimap.get(null, null)); assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), null)); assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), null, null)); assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), null, null, null)); break; case 3: assertEquals(value, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2))); assertEquals(null, multimap.get(null, key.getKey(1), key.getKey(2))); assertEquals(null, multimap.get(key.getKey(0), null, key.getKey(2))); assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), null)); assertEquals(null, multimap.get(null, null, null)); assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), null)); assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), null, null)); break; case 4: assertEquals(value, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))); assertEquals(null, multimap.get(null, key.getKey(1), key.getKey(2), key.getKey(3))); assertEquals(null, multimap.get(key.getKey(0), null, key.getKey(2), key.getKey(3))); assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), null, key.getKey(3))); assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), null)); assertEquals(null, multimap.get(null, null, null, null)); assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), null)); break; case 5: assertEquals(value, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); assertEquals(null, multimap.get(null, key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); assertEquals(null, multimap.get(key.getKey(0), null, key.getKey(2), key.getKey(3), key.getKey(4))); assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), null, key.getKey(3), key.getKey(4))); assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), null, key.getKey(4))); assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), null)); assertEquals(null, multimap.get(null, null, null, null, null)); break; default: fail("Invalid key size"); } } }
public void testMultiKeyContainsKey() { resetFull(); MultiKeyMap multimap = (MultiKeyMap) map; MultiKey[] keys = getMultiKeyKeys(); Object[] values = getSampleValues(); for (int i = 0; i < keys.length; i++) { MultiKey key = keys[i]; Object value = values[i]; switch (key.size()) { case 2: assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1))); assertEquals(false, multimap.containsKey(null, key.getKey(1))); assertEquals(false, multimap.containsKey(key.getKey(0), null)); assertEquals(false, multimap.containsKey(null, null)); assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), null)); assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), null, null)); assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), null, null, null)); break; case 3: assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2))); assertEquals(false, multimap.containsKey(null, key.getKey(1), key.getKey(2))); assertEquals(false, multimap.containsKey(key.getKey(0), null, key.getKey(2))); assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), null)); assertEquals(false, multimap.containsKey(null, null, null)); assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), null)); assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), null, null)); break; case 4: assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))); assertEquals(false, multimap.containsKey(null, key.getKey(1), key.getKey(2), key.getKey(3))); assertEquals(false, multimap.containsKey(key.getKey(0), null, key.getKey(2), key.getKey(3))); assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), null, key.getKey(3))); assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), null)); assertEquals(false, multimap.containsKey(null, null, null, null)); assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), null)); break; case 5: assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); assertEquals(false, multimap.containsKey(null, key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); assertEquals(false, multimap.containsKey(key.getKey(0), null, key.getKey(2), key.getKey(3), key.getKey(4))); assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), null, key.getKey(3), key.getKey(4))); assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), null, key.getKey(4))); assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), null)); assertEquals(false, multimap.containsKey(null, null, null, null, null)); break; default: fail("Invalid key size"); } } }
public void testMultiKeyPut() { MultiKey[] keys = getMultiKeyKeys(); Object[] values = getSampleValues(); for (int i = 0; i < keys.length; i++) { MultiKeyMap multimap = new MultiKeyMap(); MultiKey key = keys[i]; Object value = values[i]; int oldkey = hash(key.getKey(0), key.getKey(1)); switch (key.size()) { case 2: assertEquals(null, multimap.put(key.getKey(0), key.getKey(1), value)); assertEquals(1, multimap.size()); assertEquals(value, multimap.get(key.getKey(0), key.getKey(1))); assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1))); assertEquals(true, multimap.containsKey(new MultiKey(key.getKey(0), key.getKey(1)))); assertEquals(value, multimap.put(key.getKey(0), key.getKey(1), null)); assertEquals(1, multimap.size()); assertEquals(null, multimap.get(key.getKey(0), key.getKey(1))); assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1))); break; case 3: assertEquals(null, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), value)); assertEquals(1, multimap.size()); assertEquals(value, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2))); assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2))); assertEquals(true, multimap.containsKey(new MultiKey(key.getKey(0), key.getKey(1), key.getKey(2)))); assertEquals(value, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), null)); assertEquals(1, multimap.size()); assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2))); assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2))); break; case 4: assertEquals(null, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), value)); assertEquals(1, multimap.size()); assertEquals(value, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))); assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))); assertEquals(true, multimap.containsKey(new MultiKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3)))); assertEquals(value, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), null)); assertEquals(1, multimap.size()); assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))); assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))); break; case 5: assertEquals(null, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4), value)); assertEquals(1, multimap.size()); assertEquals(value, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); assertEquals(true, multimap.containsKey(new MultiKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4)))); assertEquals(value, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4), null)); assertEquals(1, multimap.size()); assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); break; default: fail("Invalid key size"); } } }
public void testMultiKeyRemove() { MultiKey[] keys = getMultiKeyKeys(); Object[] values = getSampleValues(); for (int i = 0; i < keys.length; i++) { resetFull(); MultiKeyMap multimap = (MultiKeyMap) map; int size = multimap.size(); MultiKey key = keys[i]; Object value = values[i]; switch (key.size()) { case 2: assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1))); assertEquals(value, multimap.remove(key.getKey(0), key.getKey(1))); assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1))); assertEquals(size - 1, multimap.size()); assertEquals(null, multimap.remove(key.getKey(0), key.getKey(1))); assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1))); break; case 3: assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2))); assertEquals(value, multimap.remove(key.getKey(0), key.getKey(1), key.getKey(2))); assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2))); assertEquals(size - 1, multimap.size()); assertEquals(null, multimap.remove(key.getKey(0), key.getKey(1), key.getKey(2))); assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2))); break; case 4: assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))); assertEquals(value, multimap.remove(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))); assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))); assertEquals(size - 1, multimap.size()); assertEquals(null, multimap.remove(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))); assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))); break; case 5: assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); assertEquals(value, multimap.remove(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); assertEquals(size - 1, multimap.size()); assertEquals(null, multimap.remove(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); break; default: fail("Invalid key size"); } } }
/** * Puts all the keys and values into this map. * Each key must be non-null and a MultiKey object. * * @param mapToCopy the map to copy in. * @throws NullPointerException if the mapToCopy or any key within is null * @throws ClassCastException if any key is not a MultiKey */ public void putAll(Map<? extends MultiKey<K>, ? extends V> mapToCopy) { for (Iterator it = mapToCopy.keySet().iterator(); it.hasNext();) { Object key = it.next(); checkKey(key); } map.putAll(mapToCopy); }
/** * Constructor that decorates the specified map and is called from * {@link #decorate(AbstractHashedMap)}. * The map must not be null and should be empty or only contain valid keys. * This constructor performs no validation. * * @param map the map to decorate */ protected MultiKeyMap(AbstractHashedMap<MultiKey<K>, V> map) { super(); this.map = map; }
/** * Puts the key and value into the map, where the key must be a non-null * MultiKey object. * * @param key the non-null MultiKey object * @param value the value to store * @return the previous value for the key * @throws NullPointerException if the key is null * @throws ClassCastException if the key is not a MultiKey */ public V put(MultiKey<K> key, V value) { checkKey(key); return map.put(key, value); }