List of usage examples for com.google.common.collect Multimap get
Collection<V> get(@Nullable K key);
From source file:org.ow2.proactive.inmemory_keyvalue_store.controller.KeyValueStoreRestController.java
@RequestMapping(value = "/channels", method = RequestMethod.GET) public Map<String, Collection<String>> listChannels() { ImmutableMap.Builder<String, Collection<String>> builder = ImmutableMap.builder(); Multimap<String, String> channels = keyValueStoreService.getChannels(); channels.keySet().forEach(k -> {//from ww w.jav a2 s. co m builder.put(k, channels.get(k)); }); return builder.build(); }
From source file:com.griddynamics.jagger.engine.e1.sessioncomparation.WorstCaseDecisionMaker.java
@Override public Decision makeDecision(Multimap<String, Verdict> verdicts) { Decision worstResult = Decision.OK;/*from ww w.java2 s.com*/ for (String feature : verdicts.keySet()) { for (Verdict verdict : verdicts.get(feature)) { Decision decision = verdict.getDecision(); if (decision.ordinal() > worstResult.ordinal()) { worstResult = decision; } } } return worstResult; }
From source file:com.google.devtools.build.lib.analysis.config.ConfigurationResolver.java
/** * Returns a copy of the output deps using the same key and value ordering as the input deps. * * @param originalDeps the input deps with the ordering to preserve * @param resolvedDeps the unordered output deps * @param attributesAndLabels collection of <attribute, depLabel> pairs guaranteed to match * the ordering of originalDeps.entries(). This is a performance optimization: see * {@link #resolveConfigurations#attributesAndLabels} for details. *//* w w w. ja v a 2 s . c om*/ private static OrderedSetMultimap<Attribute, Dependency> sortResolvedDeps( OrderedSetMultimap<Attribute, Dependency> originalDeps, Multimap<AttributeAndLabel, Dependency> resolvedDeps, ArrayList<AttributeAndLabel> attributesAndLabels) { Iterator<AttributeAndLabel> iterator = attributesAndLabels.iterator(); OrderedSetMultimap<Attribute, Dependency> result = OrderedSetMultimap.create(); for (Map.Entry<Attribute, Dependency> depsEntry : originalDeps.entries()) { AttributeAndLabel attrAndLabel = iterator.next(); if (depsEntry.getValue().hasExplicitConfiguration()) { result.put(attrAndLabel.attribute, depsEntry.getValue()); } else { Collection<Dependency> resolvedDepWithSplit = resolvedDeps.get(attrAndLabel); Verify.verify(!resolvedDepWithSplit.isEmpty()); if (resolvedDepWithSplit.size() > 1) { List<Dependency> sortedSplitList = new ArrayList<>(resolvedDepWithSplit); Collections.sort(sortedSplitList, SPLIT_DEP_ORDERING); resolvedDepWithSplit = sortedSplitList; } result.putAll(depsEntry.getKey(), resolvedDepWithSplit); } } return result; }
From source file:org.sonar.plugins.core.issue.notification.ChangesOnMyIssueNotificationDispatcher.java
private void addUserToContextIfSubscribed(Context context, @Nullable String user, Multimap<String, NotificationChannel> subscribedRecipients) { if (user != null) { Collection<NotificationChannel> channels = subscribedRecipients.get(user); for (NotificationChannel channel : channels) { context.addUser(user, channel); }// w w w. j av a 2s. c o m } }
From source file:grakn.core.graql.gremlin.RelationTypeInference.java
public static Set<Fragment> inferRelationTypes(TransactionOLTP tx, Set<Fragment> allFragments) { Set<Fragment> inferredFragments = new HashSet<>(); Map<Variable, Type> labelVarTypeMap = getLabelVarTypeMap(tx, allFragments); if (labelVarTypeMap.isEmpty()) return inferredFragments; Multimap<Variable, Type> instanceVarTypeMap = getInstanceVarTypeMap(allFragments, labelVarTypeMap); Multimap<Variable, Variable> relationRolePlayerMap = getRelationRolePlayerMap(allFragments, instanceVarTypeMap);/* w w w. jav a2 s . c om*/ if (relationRolePlayerMap.isEmpty()) return inferredFragments; // for each type, get all possible relation type it could be in Multimap<Type, RelationType> relationMap = HashMultimap.create(); labelVarTypeMap.values().stream().distinct().forEach(type -> addAllPossibleRelations(relationMap, type)); // inferred labels should be kept separately, even if they are already in allFragments set Map<Label, Statement> inferredLabels = new HashMap<>(); relationRolePlayerMap.asMap().forEach((relationVar, rolePlayerVars) -> { Set<Type> possibleRelationTypes = rolePlayerVars.stream().filter(instanceVarTypeMap::containsKey) .map(rolePlayer -> getAllPossibleRelationTypes(instanceVarTypeMap.get(rolePlayer), relationMap)) .reduce(Sets::intersection).orElse(Collections.emptySet()); //TODO: if possibleRelationTypes here is empty, the query will not match any data if (possibleRelationTypes.size() == 1) { Type relationType = possibleRelationTypes.iterator().next(); Label label = relationType.label(); // add label fragment if this label has not been inferred if (!inferredLabels.containsKey(label)) { Statement labelVar = var(); inferredLabels.put(label, labelVar); Fragment labelFragment = Fragments.label(new TypeProperty(label.getValue()), labelVar.var(), ImmutableSet.of(label)); inferredFragments.add(labelFragment); } // finally, add inferred isa fragments Statement labelVar = inferredLabels.get(label); IsaProperty isaProperty = new IsaProperty(labelVar); EquivalentFragmentSet isaEquivalentFragmentSet = EquivalentFragmentSets.isa(isaProperty, relationVar, labelVar.var(), relationType.isImplicit()); inferredFragments.addAll(isaEquivalentFragmentSet.fragments()); } }); return inferredFragments; }
From source file:edu.uci.ics.sourcerer.tools.java.component.identifier.internal.ClusterIdentifier.java
public static ClusterCollection identifyClusters(JarCollection jars) { TaskProgressLogger task = TaskProgressLogger.get(); task.start("Identifying core clusters in " + jars.size() + " jar files"); task.report("Compatibility threshold: " + COMPATIBILITY_THRESHOLD.getValue()); Multimap<VersionedFqnNode, Cluster> tempClusterMap = ArrayListMultimap.create(); task.start("Performing post-order traversal of FQN suffix tree", "FQN fragments visited", 100000); // Explore the tree in post-order int clusterCount = 0; for (VersionedFqnNode fragment : jars.getRoot().getPostOrderIterable()) { task.progress("%d FQN fragments visited (" + clusterCount + " clusters) in %s"); // If there are no children, then make it its own single-fqn library if (!fragment.hasChildren()) { Cluster cluster = Cluster.create(fragment); // Store it in the map for processing with the parent tempClusterMap.put(fragment, cluster); clusterCount++;//w w w .j av a2s . co m } else { // Start merging children for (VersionedFqnNode child : fragment.getChildren()) { for (Cluster childCluster : tempClusterMap.get(child)) { LinkedList<Cluster> candidates = new LinkedList<>(); // Check to see if it can be merged with any of the // libraries currently associated with the parent for (Cluster merge : tempClusterMap.get(fragment)) { if (areCompatible(merge, childCluster)) { candidates.add(merge); } } if (candidates.size() == 0) { // If nothing was found, promote the library tempClusterMap.put(fragment, childCluster); } else if (candidates.size() == 1) { // If one was found, merge in the child Cluster candidate = candidates.getFirst(); candidate.mergeCore(childCluster); clusterCount--; } else { // This else will never be hit for threshold 1 // TODO Change this for lower thresholds // If more than one was found, promote the library tempClusterMap.put(fragment, childCluster); } } // Clear the entry for this child fragment tempClusterMap.removeAll(child); } } } task.finish(); task.report("Identified " + clusterCount + " core clusters"); task.finish(); return ClusterCollection.create(tempClusterMap.get(jars.getRoot())); }
From source file:org.apache.flex.compiler.internal.as.codegen.LabelScopeControlFlowContext.java
/** * Finds all the {@link LabeledStatementNode}'s in this context with the * specified label name.//w w w .ja va2 s . c o m * * @param label Name of the {@link LabeledStatementNode}'s to search for. * @return All the {@link LabeledStatementNode}'s in this context with the * specified label name. */ Collection<LabeledStatementNode> getLabelNodes(String label) { Multimap<String, LabeledStatementNode> labelMap = getLabelMap(); return labelMap.get(label); }
From source file:sorcer.boot.util.ClassPathVerifier.java
public void verifyClassPaths(ClassLoader cl) { Multimap<ClassLoader, String> classPaths = HashMultimap.create(); for (ClassLoader classLoader : getClassLoaderTree(cl)) { classPaths.get(classLoader).addAll(getClassPath(classLoader)); }// w ww . j ava 2 s . com HashMultimap<String, ClassLoader> dest = HashMultimap.create(); Multimap<String, ClassLoader> classLoaders = Multimaps.invertFrom(classPaths, dest); for (String key : classLoaders.keySet()) { // don't check bootstrap classpath if (SorcerEnv.getRepoDir() == null || !key.contains(SorcerEnv.getRepoDir())) continue; if (classLoaders.get(key).size() > 1) { StringBuilder msg = new StringBuilder(key).append(" is loaded by multiple class loaders:\n"); for (ClassLoader kcl : classLoaders.get(key)) { msg.append("\t").append(kcl).append("\n"); } log.info("{}", msg); } } }
From source file:com.spotify.heroic.cluster.NodeRegistry.java
public List<ClusterNode> getNodesInShard(final Map<String, String> shard) { final Multimap<Map<String, String>, ClusterNode> shardToNode = buildShards(entries); final Collection<ClusterNode> nodesInShard = shardToNode.get(shard); final List<ClusterNode> result = Lists.newArrayList(); result.addAll(nodesInShard);/*www .ja v a2 s . c o m*/ return result; }
From source file:com.google.caliper.runner.EnvironmentGetter.java
private void getLinuxEnvironment(Map<String, String> propertyMap) { // the following probably doesn't work on ALL linux Multimap<String, String> cpuInfo = propertiesFromLinuxFile("/proc/cpuinfo"); propertyMap.put("host.cpus", Integer.toString(cpuInfo.get("processor").size())); String s = "cpu cores"; propertyMap.put("host.cpu.cores", describe(cpuInfo, s)); propertyMap.put("host.cpu.names", describe(cpuInfo, "model name")); propertyMap.put("host.cpu.cachesize", describe(cpuInfo, "cache size")); Multimap<String, String> memInfo = propertiesFromLinuxFile("/proc/meminfo"); // TODO redo memInfo.toString() so we don't get square brackets propertyMap.put("host.memory.physical", memInfo.get("MemTotal").toString()); propertyMap.put("host.memory.swap", memInfo.get("SwapTotal").toString()); }