List of usage examples for com.google.common.collect Multimap putAll
boolean putAll(@Nullable K key, Iterable<? extends V> values);
From source file:org.elasticsearch.cassandra.cluster.routing.PrimaryFirstSearchStrategy.java
@Override public AbstractSearchStrategy.Result topology(String ksName, Collection<InetAddress> startedShards) { Predicate<InetAddress> isLocalDC = new Predicate<InetAddress>() { String localDC = DatabaseDescriptor.getEndpointSnitch() .getDatacenter(FBUtilities.getBroadcastAddress()); public boolean apply(InetAddress address) { String remoteDC = DatabaseDescriptor.getEndpointSnitch().getDatacenter(address); return remoteDC.equals(localDC); }/*from www .j av a 2 s .c om*/ }; Set<InetAddress> localLiveNodes = Sets .newHashSet(Collections2.filter(Gossiper.instance.getLiveTokenOwners(), isLocalDC)); Set<InetAddress> localUnreachableNodes = Sets .newHashSet(Collections2.filter(Gossiper.instance.getUnreachableTokenOwners(), isLocalDC)); Map<Range<Token>, List<InetAddress>> allRanges = StorageService.instance .getRangeToAddressMapInLocalDC(ksName); Multimap<InetAddress, Range<Token>> topo = ArrayListMultimap.create(); Set<Range<Token>> orphanRanges = new HashSet<Range<Token>>(); boolean consistent = true; // get live primary token ranges for (InetAddress node : localLiveNodes) { if (startedShards.contains(node)) { topo.putAll(node, StorageService.instance.getPrimaryRangeForEndpointWithinDC(ksName, node)); } else { localUnreachableNodes.add(node); } } if (logger.isDebugEnabled()) { logger.debug("keyspace={} live nodes={}, primary ranges map = {}", ksName, localLiveNodes, topo); } // pickup random live replica for primary range owned by unreachable or not started nodes. if (localUnreachableNodes.size() > 0) { if (logger.isDebugEnabled()) { logger.debug("unreachableNodes = {} ", localUnreachableNodes); } Random rnd = new Random(); for (InetAddress node : localUnreachableNodes) { for (Range<Token> orphanRange : StorageService.instance.getPrimaryRangeForEndpointWithinDC(ksName, node)) { Set<InetAddress> replicaEndPoints = new HashSet<InetAddress>(); for (Range range : allRanges.keySet()) { if (range.contains(orphanRange)) { replicaEndPoints.addAll(allRanges.get(range)); } } replicaEndPoints.removeAll(localUnreachableNodes); if (replicaEndPoints.size() == 0) { consistent = false; orphanRanges.add(orphanRange); logger.warn("Inconsistent search for keyspace {}, no alive node having range {}", ksName, orphanRange); } else { InetAddress[] replicas = replicaEndPoints.toArray(new InetAddress[replicaEndPoints.size()]); InetAddress liveReplica = replicas[rnd.nextInt(replicas.length)]; topo.put(liveReplica, orphanRange); logger.debug("orphanRanges {} available on = {} ", orphanRanges, liveReplica); } } } } if (logger.isDebugEnabled()) { logger.debug("topology for keyspace {} = {}, consistent={} unreachableNodes={} orphanRanges={}", ksName, topo.asMap(), consistent, localUnreachableNodes, orphanRanges); } return new AbstractSearchStrategy.Result(topo.asMap(), orphanRanges, localUnreachableNodes, allRanges); }
From source file:blackboard.plugin.hayabusa.provider.ModuleItemProvider.java
@Override public Iterable<Command> getCommands() { try {// w w w .jav a 2s . c o m // TODO wire these dependencies as fields/constructor inject ModuleDbLoader moduleLoader = ModuleDbLoader.Default.getInstance(); NavigationItemDbLoader niLoader = NavigationItemDbLoader.Default.getInstance(); Multimap<Module, NavigationItemControl> nicByModule = ArrayListMultimap.create(); for (Module module : moduleLoader.heavyLoadByModuleType("bb/admin")) { String subgroup = module.getPortalExtraInfo().getExtraInfo().getValue("subgroup"); List<NavigationItemControl> nics = NavigationItemControl .createList(niLoader.loadBySubgroup(subgroup)); nicByModule.putAll(module, nics); } Set<Command> commands = Sets.newTreeSet(); for (Module module : nicByModule.keys()) { Collection<NavigationItemControl> nics = nicByModule.get(module); for (NavigationItemControl nic : nics) { if (!nic.userHasAccess()) { continue; } String title = String.format("%s: %s", module.getTitle(), nic.getLabel()); String url = FramesetUtil.getTabGroupUrl(blackboard.data.navigation.Tab.TabType.admin, nic.getUrl()); commands.add(new SimpleCommand(title, url, Category.SYSTEM_ADMIN)); } } return commands; } catch (PersistenceException e) { throw new PersistenceRuntimeException(e); } }
From source file:com.griddynamics.jagger.engine.e1.sessioncomparation.ConfigurableSessionComparator.java
@Override @SuppressWarnings("unchecked") public SessionVerdict compare(String currentSession, String baselineSession) { log.info("Comparing of sessions requested"); log.info("Feature comparators chain {}", comparatorChain); Multimap<String, Verdict> details = ArrayListMultimap.create(); for (FeatureComparator featureComparator : comparatorChain) { String feature = featureComparator.getDescription(); log.debug("Going to compare feature {}", feature); List<Verdict> verdicts = featureComparator.compare(currentSession, baselineSession); log.debug("Verdicts for feature {} are {}", feature, verdicts); details.putAll(feature, verdicts); }//w ww.j a v a2 s. com Decision decision = decisionMaker.makeDecision(details); log.info("Sessions compared. Decision {}", decision); return new SessionVerdict(decision, details); }
From source file:org.eclipse.incquery.runtime.evm.api.RuleBase.java
public Multimap<RuleSpecification<?>, EventFilter<?>> getRuleSpecificationMultimap() { final Multimap<RuleSpecification<?>, EventFilter<?>> ruleMap = HashMultimap.create(); final Map<RuleSpecification<?>, Map<EventFilter<?>, RuleInstance<?>>> rowMap = ruleInstanceTable.rowMap(); for (final Entry<RuleSpecification<?>, Map<EventFilter<?>, RuleInstance<?>>> entry : rowMap.entrySet()) { ruleMap.putAll(entry.getKey(), entry.getValue().keySet()); }// www. j a v a 2s .c o m return ruleMap; }
From source file:com.matthewmitchell.peercoinj.wallet.KeyChainGroup.java
private static Multimap<DeterministicKey, DeterministicKeyChain> extractFollowingKeychains( List<DeterministicKeyChain> chains) { // look for following key chains and map them to the watch keys of followed keychains Multimap<DeterministicKey, DeterministicKeyChain> followingKeychains = HashMultimap.create(); List<DeterministicKeyChain> followingChains = new ArrayList<DeterministicKeyChain>(); for (Iterator<DeterministicKeyChain> it = chains.iterator(); it.hasNext();) { DeterministicKeyChain chain = it.next(); if (chain.isFollowing()) { followingChains.add(chain);//from ww w . j av a 2 s. c om it.remove(); } else if (!followingChains.isEmpty()) { followingKeychains.putAll(chain.getWatchingKey(), followingChains); followingChains.clear(); } } return followingKeychains; }
From source file:com.google.devtools.build.lib.rules.java.JavaOptions.java
@Override public void addAllLabels(Multimap<String, Label> labelMap) { addOptionalLabel(labelMap, "jdk", javaBase); addOptionalLabel(labelMap, "jdk", hostJavaBase); if (javaLauncher != null) { labelMap.put("java_launcher", javaLauncher); }// ww w . j a v a 2 s.c om labelMap.put("java_toolchain", javaToolchain); labelMap.putAll("translation", getTranslationLabels()); }
From source file:com.github.kryptohash.kryptohashj.wallet.KeyChainGroup.java
private static Multimap<DeterministicEd25519Key, DeterministicKeyChain> extractFollowingKeychains( List<DeterministicKeyChain> chains) { // look for following key chains and map them to the watch keys of followed keychains Multimap<DeterministicEd25519Key, DeterministicKeyChain> followingKeychains = HashMultimap.create(); List<DeterministicKeyChain> followingChains = new ArrayList<DeterministicKeyChain>(); for (Iterator<DeterministicKeyChain> it = chains.iterator(); it.hasNext();) { DeterministicKeyChain chain = it.next(); if (chain.isFollowing()) { followingChains.add(chain);/*from w ww . j a v a 2s .co m*/ it.remove(); } else if (!followingChains.isEmpty()) { followingKeychains.putAll(chain.getWatchingKey(), followingChains); followingChains.clear(); } } return followingKeychains; }
From source file:com.facebook.buck.cli.AuditClasspathCommand.java
@VisibleForTesting int printJsonClasspath(PartialGraph partialGraph) throws IOException { DependencyGraph graph = partialGraph.getDependencyGraph(); List<BuildTarget> targets = partialGraph.getTargets(); Multimap<String, String> targetClasspaths = LinkedHashMultimap.create(); for (BuildTarget target : targets) { BuildRule rule = graph.findBuildRuleByTarget(target); HasClasspathEntries hasClasspathEntries = getHasClasspathEntriesFrom(rule); if (hasClasspathEntries == null) { continue; }/*from www .ja va 2 s. c o m*/ targetClasspaths.putAll(target.getFullyQualifiedName(), Iterables.transform( hasClasspathEntries.getTransitiveClasspathEntries().values(), Functions.toStringFunction())); } ObjectMapper mapper = new ObjectMapper(); // Note: using `asMap` here ensures that the keys are sorted mapper.writeValue(console.getStdOut(), targetClasspaths.asMap()); return 0; }
From source file:edu.cmu.lti.oaqa.baseqa.document.rerank.scorers.LuceneDocumentScorer.java
@Override public void prepare(JCas jcas) throws AnalysisEngineProcessException { uri2conf2score = HashBasedTable.create(); uri2conf2rank = HashBasedTable.create(); List<String> tokens = TypeUtil.getOrderedTokens(jcas).stream().map(Token::getCoveredText) .map(QueryParser::escape).filter(name -> !name.isEmpty() && !stoplist.contains(name.toLowerCase())) .collect(toList());//from w w w .j av a2s. co m Multimap<String, String> ctype2names = HashMultimap.create(); for (Concept concept : TypeUtil.getConcepts(jcas)) { Set<String> ctypes = TypeUtil.getConceptTypes(concept).stream().map(ConceptType::getAbbreviation) .collect(toSet()); String cnames = TypeUtil.getConceptNames(concept).stream().map(LuceneDocumentScorer::normalizeQuoteName) .distinct().collect(joining(" ")); ctypes.stream().filter(t -> !FORBIDDEN_CTYPES.contains(t)) .forEach(ctype -> ctype2names.put(ctype, cnames)); } Multimap<String, String> ctypepre2names = HashMultimap.create(); ctype2names.asMap().entrySet().forEach(e -> ctypepre2names.putAll(e.getKey().split(":")[0], e.getValue())); Multimap<String, String> ctype2mentions = HashMultimap.create(); for (Concept concept : TypeUtil.getConcepts(jcas)) { Set<String> ctypes = TypeUtil.getConceptTypes(concept).stream().map(ConceptType::getAbbreviation) .collect(toSet()); String cmentions = TypeUtil.getConceptMentions(concept).stream().map(ConceptMention::getMatchedName) .map(LuceneDocumentScorer::normalizeQuoteName).distinct().collect(joining(" ")); ctypes.stream().filter(t -> !FORBIDDEN_CTYPES.contains(t)) .forEach(ctype -> ctype2mentions.put(ctype, cmentions)); } Multimap<String, String> ctypepre2mentions = HashMultimap.create(); ctypepre2mentions.asMap().entrySet() .forEach(e -> ctypepre2mentions.putAll(e.getKey().split(":")[0], e.getValue())); LOG.debug("Query strings"); ExecutorService service = Executors.newCachedThreadPool(); // execute against all tokens service.submit(() -> { String concatTokens = String.join(" ", tokens); LOG.debug(" - Concatenated tokens: {}", concatTokens); for (String field : fields) { searchInField(concatTokens, field, "tokens_concatenated@" + field); } searchAllField(concatTokens, "tokens_concatenated@all"); }); // execute against concatenated concept names service.submit(() -> { String concatCnames = String.join(" ", ctype2names.values()); LOG.debug(" - Concatenated concept names: {}", concatCnames); for (String field : fields) { searchInField(concatCnames, field, "cnames_concatenated@" + field); } searchAllField(concatCnames, "cnames_concatenated@all"); }); // execute against concatenated concept mentions service.submit(() -> { String concatCmentions = String.join(" ", ctype2mentions.values()); LOG.debug(" - Concatenated concept mentions: {}", concatCmentions); for (String field : fields) { searchInField(concatCmentions, field, "cmentions_concatenated@" + field); } searchAllField(concatCmentions, "cmentions_concatenated@"); }); // execute against concept names for each concept service.submit(() -> { for (String cnames : ImmutableSet.copyOf(ctype2names.values())) { LOG.debug(" - Concatenated concept names: {}", cnames); for (String field : fields) { searchInField(cnames, field, "cnames_individual@" + field); } searchAllField(cnames, "cnames_individual@all"); } }); // execute against concept names for each concept type service.submit(() -> { for (String ctype : ctype2names.keySet()) { String concatCnames = String.join(" ", ctype2names.get(ctype)); LOG.debug(" - Concatenated concept names for {}: {}", ctype, concatCnames); for (String field : fields) { searchInField(concatCnames, field, "cnames@" + ctype + "@" + field); } searchAllField(concatCnames, "cnames@" + ctype + "@all"); } }); // execute against concept names for each concept type prefix service.submit(() -> { for (String ctypepre : ctypepre2names.keySet()) { String concatCnames = String.join(" ", ctypepre2names.get(ctypepre)); LOG.debug(" - Concatenated concept names for {}: {}", ctypepre, concatCnames); for (String field : fields) { searchInField(concatCnames, field, "cnames@" + ctypepre + "@" + field); } searchAllField(concatCnames, "cnames@" + ctypepre + "@all"); } }); // execute against concept mentions for each concept service.submit(() -> { for (String cmentions : ImmutableSet.copyOf(ctype2mentions.values())) { LOG.debug(" - Concatenated concept mentions: {}", cmentions); for (String field : fields) { searchInField(cmentions, field, "cmentions_individual@" + field); } searchAllField(cmentions, "cmentions_individual@all"); } }); // execute against concept mentions for each concept type service.submit(() -> { for (String ctype : ctype2mentions.keySet()) { String concatCmentions = String.join(" ", ctype2mentions.get(ctype)); LOG.debug(" - Concatenated concept mentions for {}: {}", ctype, concatCmentions); for (String field : fields) { searchInField(concatCmentions, field, "cmentions@" + ctype + "@" + field); } searchAllField(concatCmentions, "cmentions@" + ctype + "@all"); } }); // execute against concept mentions for each concept type prefix service.submit(() -> { for (String ctypepre : ctypepre2mentions.keySet()) { String concatCmentions = String.join(" ", ctypepre2mentions.get(ctypepre)); LOG.debug(" - Concatenated concept mentions for {}: {}", ctypepre, concatCmentions); for (String field : fields) { searchInField(concatCmentions, field, "cmentions@" + ctypepre + "@" + field); } searchAllField(concatCmentions, "cmentions@" + ctypepre + "@all"); } }); service.shutdown(); try { service.awaitTermination(1, TimeUnit.MINUTES); } catch (InterruptedException e) { throw new AnalysisEngineProcessException(e); } confs = new HashSet<>(uri2conf2score.columnKeySet()); // to avoid ConcurrentModificationException }
From source file:com.google.caliper.ScenarioSelection.java
private Multimap<String, String> computeUserParameters() { Multimap<String, String> result = LinkedHashMultimap.create(); for (String key : suite.parameterNames()) { // first check if the user has specified values Collection<String> userValues = userParameterArguments.get(key); if (!userValues.isEmpty()) { result.putAll(key, userValues); // TODO: type convert 'em to validate? } else { // otherwise use the default values from the suite Set<String> values = suite.parameterValues(key); if (values.isEmpty()) { throw new ConfigurationException(key + " has no values. " + "Did you forget a -D" + key + "=<value> command line argument?"); }//from ww w . j a v a 2 s .com result.putAll(key, values); } } return result; }