List of usage examples for com.google.common.collect Multimap get
Collection<V> get(@Nullable K key);
From source file:edu.byu.nlp.crowdsourcing.EmpiricalMeasurementProvider.java
/** * Annotates based on historical data for the annotator set in the * constructor. Returns the first annotation for this instance * that has not been returned before. // w w w.j a va 2 s .c o m */ private Measurement nextAnnotation(Multimap<Integer, FlatInstance<D, Integer>> instanceAnnotations) { // return next unused annotation for this annotator List<FlatInstance<D, Integer>> annotationList = Lists.newArrayList(instanceAnnotations.get(annotatorId)); Datasets.sortAnnotationsInPlace(annotationList); for (FlatInstance<D, Integer> ann : annotationList) { if (!usedAnnotations.contains(ann)) { // return earliest annotation that hasn't already been used usedAnnotations.add(ann); return ann.getMeasurement(); } } return null; }
From source file:org.openscore.engine.queue.services.assigner.ExecutionAssignerServiceImpl.java
private String chooseWorker(String groupName, Multimap<String, String> groupWorkersMap, Random randIntGenerator) { Collection<String> workerNames = groupWorkersMap.get(groupName); if (workerNames == null || workerNames.size() == 0) { // this returns a worker UUID in case of the group defined on specific worker (private group) if (groupName.startsWith("Worker_")) { return groupName.substring("Worker_".length()); } else {//from ww w . j a va2s . co m return null; } } Object[] workerArr = workerNames.toArray(); // we assign the worker using random algorithm int groupIndex = randIntGenerator.nextInt(workerArr.length); groupIndex = groupIndex % workerArr.length; return (String) workerArr[groupIndex]; }
From source file:com.onboard.service.websocket.impl.WebSocketServiceImpl.java
@Override public void broadcastOne(String user, String message) { Multimap<String, MessageInbound> syncMap = Multimaps.synchronizedMultimap(userPagesMap); Collection<MessageInbound> mis = syncMap.get(user); synchronized (syncMap) { if (mis != null) { Iterator<MessageInbound> it = mis.iterator(); while (it.hasNext()) { MessageInbound inbound = it.next(); try { sendToPage(inbound, message); } catch (IOException e) { // userPagesMap.remove(user, inbound); logger.info("The WebSocket connection has been closed: " + inbound.toString()); }/*from w w w.j a v a 2s.c o m*/ } } } }
From source file:org.lealone.cluster.locator.NetworkTopologyStrategy.java
private boolean hasSufficientReplicas(String dc, Map<String, Set<InetAddress>> dcReplicas, Multimap<String, InetAddress> allEndpoints) { return dcReplicas.get(dc).size() >= Math.min(allEndpoints.get(dc).size(), getReplicationFactor(dc)); }
From source file:org.apache.storm.streams.Node.java
Set<Node> getParents(String stream) { Multimap<String, Node> rev = Multimaps.invertFrom(parentStreams, ArrayListMultimap.<String, Node>create()); return new HashSet<>(rev.get(stream)); }
From source file:com.android.tools.idea.gradle.project.LibraryAttachments.java
public void addUrlsTo(@NotNull Library.ModifiableModel libraryModel) { for (OrderRootType type : myAttachementsByType.keySet()) { Multimap<String, String> attachmentsByLibraryName = myAttachementsByType.get(type); if (attachmentsByLibraryName != null) { Collection<String> attachments = attachmentsByLibraryName.get(libraryModel.getName()); addUrlsToLibrary(type, libraryModel, attachments); }/* ww w . ja va2s.c o m*/ } }
From source file:org.apache.hadoop.hive.ql.optimizer.calcite.cost.HiveVolcanoPlanner.java
/** * The method extends the logic of the super method to decrease * the cost of the plan if it contains materialized views * (heuristic)./* w w w . j av a 2 s. c o m*/ */ public RelOptCost getCost(RelNode rel, RelMetadataQuery mq) { assert rel != null : "pre-condition: rel != null"; if (rel instanceof RelSubset) { // Get cost of the subset, best rel may have been chosen or not RelSubset subset = (RelSubset) rel; if (subset.getBest() != null) { return getCost(subset.getBest(), mq); } return costFactory.makeInfiniteCost(); } if (rel.getTraitSet().getTrait(ConventionTraitDef.INSTANCE) == Convention.NONE) { return costFactory.makeInfiniteCost(); } // We get the cost of the operator RelOptCost cost = mq.getNonCumulativeCost(rel); if (!costFactory.makeZeroCost().isLt(cost)) { // cost must be positive, so nudge it cost = costFactory.makeTinyCost(); } // If this operator has a materialized view below, // we make its cost tiny and adjust the cost of its // inputs boolean usesMaterializedViews = false; Multimap<Class<? extends RelNode>, RelNode> nodeTypes = mq.getNodeTypes(rel); for (RelNode scan : nodeTypes.get(TableScan.class)) { if (((RelOptHiveTable) scan.getTable()).getHiveTableMD().isMaterializedView()) { usesMaterializedViews = true; break; } } if (isHeuristic && usesMaterializedViews) { // If a child of this expression uses a materialized view, // then we decrease its cost by a certain factor. This is // useful for e.g. partial rewritings, where a part of plan // does not use the materialization, but we still want to // decrease its cost so it is chosen instead of the original // plan cost = cost.multiplyBy(RelOptUtil.EPSILON); if (!costFactory.makeZeroCost().isLt(cost)) { // cost must be positive, so nudge it cost = costFactory.makeTinyCost(); } for (RelNode input : rel.getInputs()) { cost = cost.plus(getCost(input, mq)); } } else { // No materialized view or not heuristic approach, normal costing for (RelNode input : rel.getInputs()) { cost = cost.plus(getCost(input, mq)); } } return cost; }
From source file:org.sonar.server.computation.task.projectanalysis.filemove.FileMoveDetectionStep.java
private static void electMatches(@Nullable List<Match> matches, ElectedMatches electedMatches, Multimap<String, Match> matchesPerFileForScore) { // no match for this score value, ignore if (matches == null) { return;//from www . j ava 2 s.co m } List<Match> matchesToValidate = electedMatches.filter(matches); if (matchesToValidate.isEmpty()) { return; } if (matchesToValidate.size() == 1) { Match match = matchesToValidate.get(0); electedMatches.add(match); } else { matchesPerFileForScore.clear(); for (Match match : matchesToValidate) { matchesPerFileForScore.put(match.getDbKey(), match); matchesPerFileForScore.put(match.getReportKey(), match); } // validate non ambiguous matches (ie. the match is the only match of either the db file and the report file) for (Match match : matchesToValidate) { int dbFileMatchesCount = matchesPerFileForScore.get(match.getDbKey()).size(); int reportFileMatchesCount = matchesPerFileForScore.get(match.getReportKey()).size(); if (dbFileMatchesCount == 1 && reportFileMatchesCount == 1) { electedMatches.add(match); } } } }
From source file:org.sentilo.platform.server.handler.impl.CatalogAlertHandler.java
protected void validateAuthorization(final CatalogAlertInputMessage inputMessage, final SentiloRequest request) throws ForbiddenAccessException { // Internal alerts only could be inserted/updated by catalog entity final Multimap<String, CatalogAlert> groups = groupAlertsByType(inputMessage.getAlerts()); if (groups.get("INTERNAL").size() > 0 && !getCatalogId().equals(request.getEntitySource())) { final String errorMessage = String.format("You are not authorized to insert/update internal alerts."); throw new ForbiddenAccessException(errorMessage); }//from ww w. j a va 2 s .co m }
From source file:it.units.malelab.ege.benchmark.symbolicregression.MathUtils.java
public static Map<String, double[]> combinedValuesMap(Map<String, double[]> flatMap) { String[] names = new String[flatMap.keySet().size()]; int[] counters = new int[flatMap.keySet().size()]; Multimap<String, Double> multimap = ArrayListMultimap.create(); //init/*from www . j a va 2 s . c o m*/ int y = 0; for (String name : flatMap.keySet()) { names[y] = name; counters[y] = 0; y = y + 1; } //fill map while (true) { for (int i = 0; i < names.length; i++) { multimap.put(names[i], flatMap.get(names[i])[counters[i]]); } for (int i = 0; i < counters.length; i++) { counters[i] = counters[i] + 1; if ((i < counters.length - 1) && (counters[i] == flatMap.get(names[i]).length)) { counters[i] = 0; } else { break; } } if (counters[counters.length - 1] == flatMap.get(names[counters.length - 1]).length) { break; } } //transform Map<String, double[]> map = new LinkedHashMap<>(); for (String key : multimap.keySet()) { double[] values = new double[multimap.get(key).size()]; int i = 0; for (Double value : multimap.get(key)) { values[i] = value; i = i + 1; } map.put(key, values); } return map; }