List of usage examples for com.google.common.collect Multimap putAll
boolean putAll(@Nullable K key, Iterable<? extends V> values);
From source file:hu.bme.mit.trainbenchmark.benchmark.fourstore.driver.FourStoreDriver.java
public void insertEdgesWithVertex(final Multimap<String, String> edges, final String edgeType, final String targetVertexType) throws IOException { if (edges.isEmpty()) { return;/* www .j a v a 2s .co m*/ } final ArrayList<String> sourceVertices = new ArrayList<>(edges.keySet()); final List<List<String>> sourceVerticesPartitions = Lists.partition(sourceVertices, PARTITION_SIZE); for (final List<String> sourceVerticesPartition : sourceVerticesPartitions) { final Multimap<String, String> edgePartition = ArrayListMultimap.create(); for (final String sourceVertexURI : sourceVerticesPartition) { final Collection<String> targetVertexURIs = edges.get(sourceVertexURI); edgePartition.putAll(sourceVertexURI, targetVertexURIs); } insertEdgesWithVertexPartition(edgePartition, edgeType, targetVertexType); } }
From source file:org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory.java
protected Multimap<EObject, AbstractElement> computeCurrentModel(EObject currentModel, INode lastCompleteNode, Collection<AbstractElement> followElements) { Multimap<EObject, AbstractElement> result = LinkedHashMultimap.create(); ICompositeNode currentParserNode = NodeModelUtils.getNode(currentModel); if (currentParserNode == null) { result.putAll(currentModel, followElements); return result; }/*from w w w .j a v a 2 s .c o m*/ EObject currentGrammarElement = currentParserNode.getGrammarElement(); AbstractRule currentRule = getRule(currentGrammarElement); for (AbstractElement grammarElement : followElements) { AbstractRule rule = currentRule; ICompositeNode loopParserNode = currentParserNode; EObject loopLastGrammarElement = lastCompleteNode.getGrammarElement(); while (!canBeCalledAfter(rule, loopLastGrammarElement, lastCompleteNode.getText(), grammarElement) && loopParserNode.getParent() != null) { loopLastGrammarElement = loopParserNode.getGrammarElement(); loopParserNode = loopParserNode.getParent(); while (loopParserNode.getGrammarElement() == null && loopParserNode.getParent() != null) loopParserNode = loopParserNode.getParent(); EObject loopGrammarElement = loopParserNode.getGrammarElement(); rule = getRule(loopGrammarElement); } EObject context = loopParserNode.getSemanticElement(); result.put(context, grammarElement); } return result; }
From source file:org.tzi.use.gui.views.diagrams.statemachine.TransitionEdge.java
@Override protected void initializeProperties(Multimap<PropertyOwner, EdgeProperty> properties) { super.initializeProperties(properties); MTransition t = transitions.get(0);/*ww w . j a v a 2 s.c o m*/ this.labels = new ArrayList<TransitionLabel>(); this.labels.add(new TransitionLabel(t.toString(), t.toString(), this, (VertexNode) fSource, getSourceWayPoint(), (VertexNode) fTarget, getTargetWayPoint(), fOpt)); properties.putAll(PropertyOwner.EDGE, this.labels); }
From source file:uk.ac.ebi.apps.benchmark.ChemicalNameSearch.java
public void testMultiple() { System.out.println("Testing multiple"); Map<Class, NameService> services = new LinkedHashMap<Class, NameService>(); StringBuilder sb = new StringBuilder("Combined: "); for (String serviceName : getCommandLine().getOptionValues("service")) { sb.append(serviceName).append(", "); NameService service = getNameService(serviceName); service.startup();//from www .j a v a 2 s . c om services.put(service.getIdentifier().getClass(), service); } boolean greedy = has("g"); Multimap<String, Identifier> results = ArrayListMultimap.create(); long searchStart = System.currentTimeMillis(); for (String name : names) { boolean foundHit = false; for (NameService service : services.values()) { Collection hits = service.searchName(name, has("a")); results.putAll(name, hits); if (!hits.isEmpty()) { if (!foundHit) { found++; foundHit = true; } if (!greedy) break; } } } long searchEnd = System.currentTimeMillis(); Long searchTime = (searchEnd - searchStart); Multimap<String, Set<String>> nameResults = ArrayListMultimap.create(); long resolveStart = System.currentTimeMillis(); for (Map.Entry<String, Identifier> e : results.entries()) { Identifier id = e.getValue(); nameResults.put(e.getKey(), new HashSet<String>(services.get(id.getClass()).getNames(id))); } long resolveEnd = System.currentTimeMillis(); Long resolveTime = resolveEnd - resolveStart; int trueFound = getRealScore(nameResults, new ChemicalFingerprintEncoder(), null); SummaryStatistics statistics = getHitIndices(nameResults, new ChemicalFingerprintEncoder()); String[] row = new String[] { sb.toString(), searchTime.toString(), resolveTime.toString(), Integer.toString(found), Integer.toString(trueFound), Double.toString(statistics.getMax()), Double.toString(statistics.getMean()), Double.toString(statistics.getStandardDeviation()) }; System.out.println(Joiner.on("\t").join(row)); }
From source file:org.lealone.cluster.dht.RangeStreamer.java
/** * Get a map of all ranges and their respective sources that are candidates for streaming the given ranges * to us. For each range, the list of sources is sorted by proximity relative to the given destAddress. * * @throws java.lang.IllegalStateException when there is no source to get data streamed */// w w w. ja v a2 s . c o m // desiredRange?InetAddress private Multimap<Range<Token>, InetAddress> getAllRangesWithSourcesFor(Database db, Collection<Range<Token>> desiredRanges) { AbstractReplicationStrategy strat = ClusterMetaData.getReplicationStrategy(db); Multimap<Range<Token>, InetAddress> rangeAddresses = strat.getRangeAddresses(metadata.cloneOnlyTokenMap()); Multimap<Range<Token>, InetAddress> rangeSources = ArrayListMultimap.create(); for (Range<Token> desiredRange : desiredRanges) { for (Range<Token> range : rangeAddresses.keySet()) { if (range.contains(desiredRange)) { List<InetAddress> preferred = snitch.getSortedListByProximity(address, rangeAddresses.get(range)); rangeSources.putAll(desiredRange, preferred); break; } } if (!rangeSources.keySet().contains(desiredRange)) throw new IllegalStateException("No sources found for " + desiredRange); } return rangeSources; }
From source file:com.puppetlabs.geppetto.validation.runner.AllModulesState.java
/** * Returns an unmodifiable {@link Multimap} of Module -> unresolved names. * * @return// w w w . ja v a2 s. c o m */ public Multimap<File, String> getUnresolvedMap() { if (unresolvedImports == null) return EmptyUnresolved; Multimap<File, String> result = ArrayListMultimap.create(); for (File moduleFile : unresolvedImports.keySet()) { result.putAll(moduleFile, Iterables.transform(unresolvedImports.get(moduleFile), new Function<ImportedName, String>() { @Override public String apply(ImportedName from) { return from.getName(); } })); } return result; }
From source file:org.apache.cassandra.dht.RangeStreamer.java
/** * Get a map of all ranges and their respective sources that are candidates for streaming the given ranges * to us. For each range, the list of sources is sorted by proximity relative to the given destAddress. * * @throws java.lang.IllegalStateException when there is no source to get data streamed *//*from w ww . j a va 2 s.c om*/ private Multimap<Range<Token>, InetAddress> getAllRangesWithSourcesFor(String keyspaceName, Collection<Range<Token>> desiredRanges) { AbstractReplicationStrategy strat = Keyspace.open(keyspaceName).getReplicationStrategy(); Multimap<Range<Token>, InetAddress> rangeAddresses = strat.getRangeAddresses(metadata.cloneOnlyTokenMap()); Multimap<Range<Token>, InetAddress> rangeSources = ArrayListMultimap.create(); for (Range<Token> desiredRange : desiredRanges) { for (Range<Token> range : rangeAddresses.keySet()) { if (range.contains(desiredRange)) { List<InetAddress> preferred = snitch.getSortedListByProximity(address, rangeAddresses.get(range)); rangeSources.putAll(desiredRange, preferred); break; } } if (!rangeSources.keySet().contains(desiredRange)) throw new IllegalStateException("No sources found for " + desiredRange); } return rangeSources; }
From source file:com.spotify.helios.client.HeliosClient.java
/** * Returns a list of all hosts registered in the Helios cluster which match the given list of * host//w w w .jav a2 s . c o m * selectors. * <p> * For example, {@code listHosts(Arrays.asList("site=foo"))} will return all agents in the * cluster whose labels match the expression {@code site=foo}.</p> */ public ListenableFuture<List<String>> listHosts(final Set<String> unparsedHostSelectors) { final Multimap<String, String> query = HashMultimap.create(); query.putAll("selector", unparsedHostSelectors); return listHosts(query); }
From source file:com.bigdata.dastor.dht.BootStrapper.java
/** get potential sources for each range, ordered by proximity (as determined by EndPointSnitch) */ Multimap<Range, InetAddress> getRangesWithSources(String table) { assert tokenMetadata.sortedTokens().size() > 0; final AbstractReplicationStrategy strat = StorageService.instance.getReplicationStrategy(table); Collection<Range> myRanges = strat.getPendingAddressRanges(tokenMetadata, token, address, table); Multimap<Range, InetAddress> myRangeAddresses = ArrayListMultimap.create(); Multimap<Range, InetAddress> rangeAddresses = strat.getRangeAddresses(tokenMetadata, table); for (Range myRange : myRanges) { for (Range range : rangeAddresses.keySet()) { if (range.contains(myRange)) { List<InetAddress> preferred = DatabaseDescriptor.getEndPointSnitch(table) .getSortedListByProximity(address, rangeAddresses.get(range)); myRangeAddresses.putAll(myRange, preferred); break; }// w w w. j a v a2 s .c o m } assert myRangeAddresses.keySet().contains(myRange); } return myRangeAddresses; }
From source file:co.cask.cdap.etl.planner.ControlDag.java
private void flattenFrom(String node) { Set<String> outputs = outgoingConnections.get(node); if (outputs.isEmpty()) { return;/* w ww . j a v a 2s .co m*/ } if (outputs.size() == 1) { flattenFrom(outputs.iterator().next()); return; } Multimap<String, String> branchEndpointOutputs = HashMultimap.create(); // can't just use branchEndpointOutputs.keySet(), // because that won't track branch endpoints that had no output (sinks) Set<String> branchEndpoints = new HashSet<>(); for (String output : outputs) { String branchEndpoint = findBranchEnd(output); branchEndpoints.add(branchEndpoint); branchEndpointOutputs.putAll(branchEndpoint, outgoingConnections.get(branchEndpoint)); } // if all the branch endpoints connect to a single node, there is no need to add a join node Set<String> endpointOutputs = new HashSet<>(branchEndpointOutputs.values()); if (endpointOutputs.size() == 1) { flattenFrom(endpointOutputs.iterator().next()); return; } // add a connection from each branch endpoint to a newly added join node // then move all outgoing connections from each branch endpoint so that they are coming out of the new join node String newJoinNode = generateJoinNodeName(branchEndpoints); addNode(newJoinNode, branchEndpoints, endpointOutputs); // remove the outgoing connections from endpoints that aren't going to our new join node for (Map.Entry<String, String> endpointEntry : branchEndpointOutputs.entries()) { removeConnection(endpointEntry.getKey(), endpointEntry.getValue()); } /* have to trim again due to reshuffling of nodes. For example, if we have: |--> n3 |--> n2 --| | |--> n4 n1 --| | | v |--> n5 -----> n6 after we insert the new join node we'll have: |--> n2 --| |--> n3 | | | n1 --| |--> join --|--> n4 | | | | |--> n5 --| | v |--> n6 and we need to remove the connection from join -> n6, otherwise the algorithm will get messed up */ trim(); // then keep flattening from the new join node flattenFrom(newJoinNode); }