/** * Decorates the specified map to add the MultiKeyMap API and fast query. * The map must not be null and must be empty. * * @param <K> the key type * @param <V> the value type * @param map the map to decorate, not null * @return a new multi key map * @throws NullPointerException if map is null * @throws IllegalArgumentException if the map is not empty * @since 4.0 */ public static <K, V> MultiKeyMap<K, V> multiKeyMap(final AbstractHashedMap<MultiKey<? extends K>, V> map) { if (map == null) { throw new NullPointerException("Map must not be null"); } if (map.size() > 0) { throw new IllegalArgumentException("Map must be empty"); } return new MultiKeyMap<>(map); }
/** * 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(final Object key1) { boolean modified = false; final MapIterator<MultiKey<? extends K>, V> it = mapIterator(); while (it.hasNext()) { final MultiKey<? extends K> multi = it.next(); if (multi.size() >= 1 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0)))) { it.remove(); modified = true; } } return modified; }
/** * 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 */ @Override public V put(final MultiKey<? extends K> key, final V value) { checkKey(key); return super.put(key, value); }
LegalPairs legalPairs, List<Node> c, List<Node> d, Graph graph, int maxPathLength) { HashSet<Node> reachable = new HashSet<>(); MultiKeyMap visited = new MultiKeyMap(); List<ReachabilityEdge> nextEdges = new LinkedList<>(); reachable.add(y); nextEdges.add(new ReachabilityEdge(x, y)); visited.put(x, y, Boolean.TRUE); if ((visited.get(y, z)) == Boolean.TRUE) { continue; visited.put(y, z, Boolean.TRUE);
/** * Add blog entries from the planet archive to a multi key map. * * @param mkm Map with blog entries stored with a key consisting of author name and rss feed link. * @param blogEntry Single blog entry retrieved from planet archive. */ protected void createMapEntry(MultiKeyMap<String, List<Node>> mkm, Node blogEntry) { List<Node> blogEntries = new ArrayList<Node>(); try { String author = PlanetUtil.formatName(blogEntry, "author"); String rssLink = PropertyUtil.getString(blogEntry, "rssLink", ""); if (mkm.containsKey(author, rssLink)) { blogEntries = mkm.get(author, rssLink); } if (blogEntry.hasProperty("pubDate")) { blogEntries.add(blogEntry); mkm.put(author, rssLink, blogEntries); } } catch (Exception e) { log.error("Could not add blog entry to statistics list: " + e.getMessage()); } }
/** * Get a ConfigMethod implementation appropriate for handling a * configuration interface method. Internally, this uses a cache so * that it can operate very efficiently. * * @param configInterface The configuration interface. * @param method The method. * @return The method implementation. */ @SuppressWarnings("unchecked") public static synchronized ConfigMethod getInstance(Class<?> configInterface, Method method) { ConfigMethod configMethod = (ConfigMethod) configMethods.get(configInterface, method); if (configMethod == null) { configMethod = newInstance(configInterface, method); configMethods.put(configInterface, method, configMethod); } return configMethod; } }
public void setEvaluationCondition(TimeStep step, Rule rule, Metier metier, boolean evalutionCondition) { this.evalutionCondition.put(step, rule, metier, evalutionCondition); }
public boolean getEvalutionCondition(TimeStep step, Rule rule, Metier metier) { return this.evalutionCondition.get(step, rule, metier); }
public void clear() { map.clear(); } }
/** * 联合多个Key来定位Value的HashMap. * * 普通HashMap,需要将多个Key拼装成一个字符串作为主键,因此MultiKeyMap尤其适合于这几个Key的类型不是String时. * * @param map 被包裹的底层HashMap,可先定义HashMap的初始大小和加载因子,可使用类型为LinkedMap */ public static <K, V> MultiKeyMap<K, V> multiKeyMap(final AbstractHashedMap<MultiKey<? extends K>, V> map) { return MultiKeyMap.multiKeyMap(map); }
public void add(int variable, int[] parents, double score) { Set<Integer> _parents = new HashSet<>(parents.length); for (int parent : parents) { _parents.add(parent); } map.put(variable, _parents, score); }
public double get(int variable, int[] parents) { Set<Integer> _parents = new HashSet<>(parents.length); for (int parent : parents) { _parents.add(parent); } Double _score = (Double) map.get(variable, _parents); return _score == null ? Double.NaN : (_score); }
/** * clear all data * * can be used at end of each simulation step */ public void clear() { list.clear(); forbiddenMetier.clear(); }
/** * 联合多个Key来定位Value的HashMap. * * 普通HashMap,需要将多个Key拼装成一个字符串作为主键,因此MultiKeyMap尤其适合于这几个Key的类型不是String时. * * @param map 被包裹的底层HashMap,可先定义HashMap的初始大小和加载因子,可使用类型为LinkedMap */ public static <K, V> MultiKeyMap<K, V> multiKeyMap(final AbstractHashedMap<MultiKey<? extends K>, V> map) { return MultiKeyMap.multiKeyMap(map); }
/** * 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(final Object key1, final Object key2, final Object key3) { boolean modified = false; final MapIterator<MultiKey<? extends K>, V> it = mapIterator(); while (it.hasNext()) { final MultiKey<? extends K> multi = 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; }
public void addLicence(Metier metier, int nbLicences, Month firstMonth, Month lastMonth) { if (!isLimitedPeriode(metier, firstMonth, lastMonth)) { Licence o = new Licence(); o.nbLicences = nbLicences; o.proportionMaxTotal = this.computeProportionMaxTotal(metier, nbLicences); for (Month i=firstMonth; i.compareTo(lastMonth) <= 0; i=i.next()) { o.proportionsMonth.put(i, computeProportionMonth(metier, i)); } this.list.put(metier, firstMonth, lastMonth, o); } else{ log.warn("il existe deja une licence touchant le metier: " + metier + " sur la periode:"+ firstMonth + "-" + lastMonth); } }
public LocalScoreCache() { map = new MultiKeyMap(); }
/** * Copies all of the keys and values from the specified map to this map. * Each key must be non-null and a MultiKey object. * * @param mapToCopy to this map * @throws NullPointerException if the mapToCopy or any key within is null * @throws ClassCastException if any key in mapToCopy is not a MultiKey */ @Override public void putAll(final Map<? extends MultiKey<? extends K>, ? extends V> mapToCopy) { for (final MultiKey<? extends K> key : mapToCopy.keySet()) { checkKey(key); } super.putAll(mapToCopy); }
/** * 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(final Object key1, final Object key2) { boolean modified = false; final MapIterator<MultiKey<? extends K>, V> it = mapIterator(); while (it.hasNext()) { final MultiKey<? extends K> multi = 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; }
Map reversedMap = new MultiKeyMap();