List of usage examples for com.google.common.collect SetMultimap put
boolean put(@Nullable K key, @Nullable V value);
From source file:org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext.java
public EffectiveSchemaContext(final Set<Module> modules) { /*//ww w . j a va 2 s . com * Instead of doing this on each invocation of getModules(), pre-compute * it once and keep it around -- better than the set we got in. */ this.modules = ImmutableSet.copyOf(ModuleDependencySort.sort(modules.toArray(new Module[modules.size()]))); /* * The most common lookup is from Namespace->Module. * * RESTCONF performs lookups based on module name only, where it wants * to receive the latest revision * * Invest some quality time in building up lookup tables for both. */ final SetMultimap<URI, Module> nsMap = Multimaps.newSetMultimap(new TreeMap<>(), MODULE_SET_SUPPLIER); final SetMultimap<String, Module> nameMap = Multimaps.newSetMultimap(new TreeMap<>(), MODULE_SET_SUPPLIER); Set<ModuleIdentifier> modIdBuilder = new HashSet<>(); for (Module m : modules) { nameMap.put(m.getName(), m); nsMap.put(m.getNamespace(), m); modIdBuilder.add(ModuleIdentifierImpl.create(m.getName(), Optional.of(m.getNamespace()), Optional.of(m.getRevision()))); resolveSubmoduleIdentifiers(m.getSubmodules(), modIdBuilder); } namespaceToModules = ImmutableSetMultimap.copyOf(nsMap); nameToModules = ImmutableSetMultimap.copyOf(nameMap); moduleIdentifiers = ImmutableSet.copyOf(modIdBuilder); rootDeclaredStatements = ImmutableList.of(); rootEffectiveStatements = ImmutableList.of(); }
From source file:org.sonar.batch.DecoratorsSelector.java
private SetMultimap<Metric, Decorator> getDecoratorsByMetric(Collection<Decorator> pluginDecorators) { SetMultimap<Metric, Decorator> decoratorsByGeneratedMetric = HashMultimap.create(); for (Decorator decorator : pluginDecorators) { List dependents = batchExtDictionnary.getDependents(decorator); for (Object dependent : dependents) { if (dependent instanceof Metric) { decoratorsByGeneratedMetric.put((Metric) dependent, decorator); }/* w w w .ja va 2s . co m*/ } } return decoratorsByGeneratedMetric; }
From source file:org.onosproject.net.intent.impl.installer.LinkCollectionIntentInstaller.java
private List<Collection<FlowRuleOperation>> generateBatchOperations(LinkCollectionIntent intent, FlowRuleOperation.Type operation) { //TODO do we need a set here? SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create(); SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create(); for (Link link : intent.links()) { inputPorts.put(link.dst().deviceId(), link.dst().port()); outputPorts.put(link.src().deviceId(), link.src().port()); }/*from www . j a va 2s . c om*/ for (ConnectPoint ingressPoint : intent.ingressPoints()) { inputPorts.put(ingressPoint.deviceId(), ingressPoint.port()); } for (ConnectPoint egressPoint : intent.egressPoints()) { outputPorts.put(egressPoint.deviceId(), egressPoint.port()); } List<FlowRuleOperation> rules = Lists.newArrayList(); outputPorts.keys().stream().map(deviceId -> createBatchEntries(operation, intent, deviceId, inputPorts.get(deviceId), outputPorts.get(deviceId))).forEach(rules::addAll); return Lists.newArrayList(ImmutableSet.of(rules)); }
From source file:com.icosilune.fn.nodes.NodeGraph.java
/** * Returns a multimap of each node to its output nodes. *///ww w.ja v a 2s . c om private SetMultimap<AbstractNode, AbstractNode> getDownstreamConnections() { SetMultimap<AbstractNode, AbstractNode> downstreamConnections = HashMultimap.create(); for (AbstractNode node : allNodes) { for (Connection connection : node.getInputConnections().values()) { downstreamConnections.put(connection.getOutputNode(), connection.getInputNode()); } } return downstreamConnections; }
From source file:org.terasology.utilities.gson.SetMultimapTypeAdapter.java
@Override public SetMultimap<String, V> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { SetMultimap<String, V> result = HashMultimap.create(); JsonObject obj = json.getAsJsonObject(); for (Map.Entry<String, JsonElement> entry : obj.entrySet()) { if (entry.getValue().isJsonArray()) { for (JsonElement item : entry.getValue().getAsJsonArray()) { result.put(entry.getKey(), context.<V>deserialize(item, valueType)); }/*from w w w .j ava 2s .c om*/ } else { result.put(entry.getKey(), context.<V>deserialize(entry.getValue(), valueType)); } } return result; }
From source file:org.grouplens.lenskit.eval.traintest.JobGraphBuilder.java
private void addSharedNodeDependencies(DAGNode<Component, Dependency> graph, DAGNodeBuilder<JobGraph.Node, JobGraph.Edge> builder) { logger.debug("scanning for dependencies of {}", builder.getLabel()); SetMultimap<DAGNode<JobGraph.Node, JobGraph.Edge>, DAGNode<Component, Dependency>> edges; edges = HashMultimap.create();/*from ww w . ja v a 2 s . c o m*/ for (DAGNode<Component, Dependency> node : graph.getReachableNodes()) { if (seenNodes.containsKey(node)) { edges.put(seenNodes.get(node), node); } } for (DAGNode<JobGraph.Node, JobGraph.Edge> dep : edges.keySet()) { if (logger.isDebugEnabled()) { logger.debug("depends on {} for {} nodes", dep, edges.get(dep).size()); for (DAGNode<Component, Dependency> shared : edges.get(dep)) { logger.debug("reuses {}", shared); } } builder.addEdge(dep, JobGraph.edge(edges.get(dep))); } }
From source file:org.sosy_lab.cpachecker.core.reachedset.PseudoPartitionedReachedSet.java
@Override public void add(AbstractState pState, Precision pPrecision) { super.add(pState, pPrecision); Object key = getPartitionKey(pState); Comparable<?> pseudoKey = getPseudoPartitionKey(pState); Object pseudoHash = getPseudoHashCode(pState); SetMultimap<Object, AbstractState> states = partitionedReached.get(key, pseudoKey); if (states == null) { // create if not existent states = HashMultimap.create();/*from ww w . java 2s .c om*/ partitionedReached.put(key, pseudoKey, states); } states.put(pseudoHash, pState); }
From source file:dk.dma.dmiweather.service.ForecastContainer.java
/** * Reversed the map, but since several parameters can come from the same GRIB file, we get a multiMap *///from w w w. j a va 2 s .c o m private SetMultimap<GribFileWrapper, GridParameterType> groupByFile( Map<GridParameterType, GribFileWrapper> sources) { SetMultimap<GribFileWrapper, GridParameterType> multiMap = HashMultimap.create(); for (Map.Entry<GridParameterType, GribFileWrapper> entry : sources.entrySet()) { multiMap.put(entry.getValue(), entry.getKey()); } return multiMap; }
From source file:com.google.template.soy.types.proto.SoyProtoType.java
SoyProtoType(SoyTypeRegistry typeRegistry, Descriptor descriptor, Set<FieldDescriptor> extensions) { this.typeDescriptor = descriptor; ImmutableMap.Builder<String, Field> fields = ImmutableMap.builder(); for (FieldDescriptor fieldDescriptor : descriptor.getFields()) { if (Protos.shouldJsIgnoreField(fieldDescriptor)) { continue; }//from w w w . ja va 2 s . co m NormalField field = new NormalField(typeRegistry, fieldDescriptor); fields.put(field.getName(), field); } SetMultimap<String, ExtensionField> extensionsBySoyName = MultimapBuilder.hashKeys().hashSetValues() .build(); for (FieldDescriptor extension : extensions) { ExtensionField field = new ExtensionField(typeRegistry, extension); extensionsBySoyName.put(field.getName(), field); } for (Map.Entry<String, Set<ExtensionField>> group : Multimaps.asMap(extensionsBySoyName).entrySet()) { String fieldName = group.getKey(); Set<ExtensionField> ambiguousFields = group.getValue(); if (ambiguousFields.size() == 1) { fields.put(fieldName, Iterables.getOnlyElement(ambiguousFields)); } else { AmbiguousFieldSet value = new AmbiguousFieldSet(fieldName, ambiguousFields); logger.severe("Proto " + descriptor.getFullName() + " has multiple extensions with the name \"" + fieldName + "\": " + value.getFullFieldNames() + "\nThis field will not be accessible from soy"); fields.put(fieldName, value); } } this.fields = fields.build(); }
From source file:com.google.caliper.runner.worker.targetinfo.TargetInfoFromWorkerFactory.java
@Override public TargetInfo getTargetInfo() { SetMultimap<BenchmarkClassModel, Target> models = HashMultimap.create(); Map<Target, Host> hosts = new HashMap<>(); try {// w w w. j av a 2 s.c o m for (Target target : targets) { TargetInfoLogMessage logMessage = targetInfoComponentBuilder.get().target(target).build() .workerRunner().runWorker(); models.put(logMessage.model(), target); hosts.put(target, new Host.Builder().addAllProperties(logMessage.deviceProperties()).build()); } } catch (ProxyWorkerException e) { if (e.exceptionType().equals(UserCodeException.class.getName())) { throw new UserCodeException(e.message(), e); } else if (e.exceptionType().equals(InvalidBenchmarkException.class.getName())) { throw new InvalidBenchmarkException(e.message(), e); } throw e; } if (models.keySet().size() > 1) { throw new InvalidConfigurationException( "Different targets produced different models of the benchmark class. Please ensure " + "that the classpaths used for each type of target contain equivalent versions of " + "the benchmark class."); } return TargetInfo.create(Iterables.getOnlyElement(models.keySet()), hosts); }