List of usage examples for com.google.common.collect ImmutableSetMultimap builder
public static <K, V> Builder<K, V> builder()
From source file:com.facebook.presto.execution.NodeScheduler.java
public NodeSelector createNodeSelector(String dataSourceName) { // this supplier is thread-safe. TODO: this logic should probably move to the scheduler since the choice of which node to run in should be // done as close to when the the split is about to be scheduled Supplier<NodeMap> nodeMap = Suppliers.memoizeWithExpiration(() -> { ImmutableSetMultimap.Builder<HostAddress, Node> byHostAndPort = ImmutableSetMultimap.builder(); ImmutableSetMultimap.Builder<InetAddress, Node> byHost = ImmutableSetMultimap.builder(); Set<Node> nodes; if (dataSourceName != null) { nodes = nodeManager.getActiveDatasourceNodes(dataSourceName); } else {//from w w w. j a v a2 s . c o m nodes = nodeManager.getActiveNodes(); } for (Node node : nodes) { try { byHostAndPort.put(node.getHostAndPort(), node); InetAddress host = InetAddress.getByName(node.getHttpUri().getHost()); byHost.put(host, node); } catch (UnknownHostException e) { // ignore } } Set<String> coordinatorNodeIds = nodeManager.getCoordinators().stream().map(Node::getNodeIdentifier) .collect(toImmutableSet()); return new NodeMap(byHostAndPort.build(), byHost.build(), coordinatorNodeIds); }, 5, TimeUnit.SECONDS); return new NodeSelector(nodeMap); }
From source file:co.runrightfast.vertx.orientdb.verticle.OrientDBVerticle.java
private ImmutableSetMultimap<String, Class<? extends DocumentObject>> databaseClassesForHealthCheck() { final ImmutableSetMultimap.Builder<String /* database name */, Class<? extends DocumentObject>> set = ImmutableSetMultimap .builder();/*from w ww.java 2s. co m*/ config.getDatabasePoolConfigs().stream().forEach(databasePoolConfig -> { databasePoolConfig.getDocumentClasses() .forEach(clazz -> set.put(databasePoolConfig.getDatabaseName(), clazz)); }); return set.build(); }
From source file:dagger2.internal.codegen.SourceFiles.java
/** * Allows dependency requests to be grouped by the key they're requesting. * This is used by factory generation in order to minimize the number of parameters * required in the case where a given key is requested more than once. This expects * unresolved dependency requests, otherwise we may generate factories based on * a particular usage of a class as opposed to the generic types of the class. *//*from w ww.ja v a 2 s . c om*/ static ImmutableSetMultimap<BindingKey, DependencyRequest> indexDependenciesByKey( Iterable<? extends DependencyRequest> dependencies) { ImmutableSetMultimap.Builder<BindingKey, DependencyRequest> dependenciesByKeyBuilder = new ImmutableSetMultimap.Builder<BindingKey, DependencyRequest>() .orderValuesBy(DEPENDENCY_ORDERING); for (DependencyRequest dependency : dependencies) { dependenciesByKeyBuilder.put(dependency.bindingKey(), dependency); } return dependenciesByKeyBuilder.build(); }
From source file:com.google.template.soy.soytree.TemplateRegistry.java
/** * Constructor.//from w w w. j av a2 s . c om * @param soyTree The Soy tree from which to build a template registry. */ public TemplateRegistry(SoyFileSetNode soyTree, ErrorReporter errorReporter) { // ------ Iterate through all templates to collect data. ------ ImmutableList.Builder<TemplateNode> allTemplatesBuilder = ImmutableList.builder(); Map<String, TemplateBasicNode> basicTemplates = new LinkedHashMap<>(); ImmutableSetMultimap.Builder<String, DelTemplateKey> delTemplateBuilder = ImmutableSetMultimap.builder(); Map<DelTemplateKey, Map<Priority, Map<String, TemplateDelegateNode>>> tempDelTemplatesMap = new LinkedHashMap<>(); for (SoyFileNode soyFile : soyTree.getChildren()) { for (TemplateNode template : soyFile.getChildren()) { allTemplatesBuilder.add(template); if (template instanceof TemplateBasicNode) { // Case 1: Basic template. TemplateBasicNode prev = basicTemplates.put(template.getTemplateName(), (TemplateBasicNode) template); if (prev != null) { errorReporter.report(template.getSourceLocation(), DUPLICATE_BASIC_TEMPLATES, template.getTemplateName(), prev.getSourceLocation()); } } else { // Case 2: Delegate template. TemplateDelegateNode delTemplate = (TemplateDelegateNode) template; DelTemplateKey delTemplateKey = delTemplate.getDelTemplateKey(); // Add to tempDelTemplateNameToKeysMap. String delTemplateName = delTemplate.getDelTemplateName(); delTemplateBuilder.put(delTemplateName, delTemplateKey); // Add to tempDelTemplatesMap. Priority delPriority = delTemplate.getDelPriority(); String delPackageName = delTemplate.getDelPackageName(); Map<Priority, Map<String, TemplateDelegateNode>> tempDivisions = tempDelTemplatesMap .get(delTemplateKey); if (tempDivisions == null) { tempDivisions = new EnumMap<>(Priority.class); tempDelTemplatesMap.put(delTemplateKey, tempDivisions); } Map<String, TemplateDelegateNode> tempDivision = tempDivisions.get(delPriority); if (tempDivision == null) { tempDivision = new LinkedHashMap<>(); tempDivisions.put(delPriority, tempDivision); } if (tempDivision.containsKey(delPackageName)) { TemplateDelegateNode prevTemplate = tempDivision.get(delPackageName); if (delPackageName == null) { errorReporter.report(delTemplate.getSourceLocation(), DUPLICATE_DEFAULT_DELEGATE_TEMPLATES, delTemplateName, prevTemplate.getSourceLocation()); } else { errorReporter.report(delTemplate.getSourceLocation(), DUPLICATE_DELEGATE_TEMPLATES_IN_DELPACKAGE, delTemplateName, delPackageName, prevTemplate.getSourceLocation()); } } tempDivision.put(delPackageName, delTemplate); } } } // ------ Build the final data structures. ------ basicTemplatesMap = ImmutableMap.copyOf(basicTemplates); ImmutableListMultimap.Builder<DelTemplateKey, DelegateTemplateDivision> delTemplatesMapBuilder = ImmutableListMultimap .builder(); for (DelTemplateKey delTemplateKey : tempDelTemplatesMap.keySet()) { Map<Priority, Map<String, TemplateDelegateNode>> tempDivisions = tempDelTemplatesMap .get(delTemplateKey); ImmutableList.Builder<DelegateTemplateDivision> divisionsBuilder = ImmutableList.builder(); // Note: List should be in decreasing priority order. Map<String, TemplateDelegateNode> highPriorityTemplates = tempDivisions.get(Priority.HIGH_PRIORITY); if (highPriorityTemplates != null) { divisionsBuilder.add(new DelegateTemplateDivision(highPriorityTemplates)); } Map<String, TemplateDelegateNode> standardPriorityTemplates = tempDivisions.get(Priority.STANDARD); if (standardPriorityTemplates != null) { divisionsBuilder.add(new DelegateTemplateDivision(standardPriorityTemplates)); } delTemplatesMapBuilder.putAll(delTemplateKey, divisionsBuilder.build()); } delTemplatesMap = delTemplatesMapBuilder.build(); delTemplateNameToKeysMap = delTemplateBuilder.build(); allTemplates = allTemplatesBuilder.build(); }
From source file:uk.ac.ebi.atlas.experimentimport.analyticsindex.differential.MicroArrayDiffAnalyticsIndexerService.java
private ImmutableSetMultimap<String, String> expandOntologyTerms( ImmutableSetMultimap<String, String> termIdsByAssayAccession) { ImmutableSetMultimap.Builder<String, String> builder = ImmutableSetMultimap.builder(); for (String assayAccession : termIdsByAssayAccession.keys()) { Set<String> expandedOntologyTerms = new HashSet<>(); expandedOntologyTerms/*from w w w.jav a2 s .c o m*/ .addAll(efoParentsLookupService.getAllParents(termIdsByAssayAccession.get(assayAccession))); expandedOntologyTerms.addAll(termIdsByAssayAccession.get(assayAccession)); builder.putAll(assayAccession, expandedOntologyTerms); } return builder.build(); }
From source file:com.google.devtools.build.xcode.xcodegen.AggregateReferenceType.java
/** * Groups a sequence of items according to their {@link #aggregateKey(Path)}. *///w w w. j a v a2s . c o m public SetMultimap<AggregateKey, Path> aggregates(Iterable<Path> paths) { ImmutableSetMultimap.Builder<AggregateKey, Path> result = new ImmutableSetMultimap.Builder<>(); for (Path path : paths) { AggregateKey key = aggregateKey(path); Path referencePath = key.isStandalone() ? path : pathInAggregate(path); result.put(key, referencePath); } return result.build(); }
From source file:zipkin2.storage.cassandra.v1.Indexer.java
void index(Span span, List<Call<Void>> calls) { // First parse each span into partition keys used to support query requests Builder<PartitionKeyToTraceId, Long> parsed = ImmutableSetMultimap.builder(); long timestamp = span.timestampAsLong(); if (timestamp == 0L) return;//from w w w.j a va2 s .c o m for (String partitionKey : index.partitionKeys(span)) { parsed.put(new PartitionKeyToTraceId(index.table(), partitionKey, span.traceId()), 1000 * (timestamp / 1000)); // index precision is millis } // The parsed results may include inserts that already occur, or are redundant as they don't // impact QueryRequest.endTs or QueryRequest.loopback. For example, a parsed timestamp could // be between timestamps of rows that already exist for a particular trace. ImmutableSetMultimap<PartitionKeyToTraceId, Long> maybeInsert = parsed.build(); if (maybeInsert.isEmpty()) return; ImmutableSetMultimap<PartitionKeyToTraceId, Long> toInsert; if (sharedState == null) { // special-case when caching is disabled. toInsert = maybeInsert; } else { // Optimized results will be smaller when the input includes traces with local spans, or when // other threads indexed the same trace. toInsert = entriesThatIncreaseGap(sharedState, maybeInsert); if (maybeInsert.size() > toInsert.size() && LOG.isDebugEnabled()) { int delta = maybeInsert.size() - toInsert.size(); LOG.debug("optimized out {}/{} inserts into {}", delta, maybeInsert.size(), index.table()); } } // For each entry, insert a new row in the index table asynchronously for (Map.Entry<PartitionKeyToTraceId, Long> entry : toInsert.entries()) { long traceId = HexCodec.lowerHexToUnsignedLong(entry.getKey().traceId); calls.add(new IndexCall(traceId, entry.getValue(), entry.getKey().partitionKey)); } }
From source file:com.google.caliper.json.ImmutableMultimapTypeAdapterFactory.java
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public <T> TypeAdapter<T> create(Gson gson, com.google.gson.reflect.TypeToken<T> typeToken) { if (ImmutableListMultimap.class.isAssignableFrom(typeToken.getRawType())) { TypeToken<Map<?, List<?>>> mapToken = getMapOfListsToken((TypeToken) TypeToken.of(typeToken.getType())); final TypeAdapter<Map<?, List<?>>> adapter = (TypeAdapter<Map<?, List<?>>>) gson .getAdapter(com.google.gson.reflect.TypeToken.get(mapToken.getType())); return new TypeAdapter<T>() { @Override/*from w ww . j a va2 s. co m*/ public void write(JsonWriter out, T value) throws IOException { ImmutableListMultimap<?, ?> multimap = (ImmutableListMultimap<?, ?>) value; adapter.write(out, (Map) multimap.asMap()); } @Override public T read(JsonReader in) throws IOException { Map<?, List<?>> value = adapter.read(in); ImmutableListMultimap.Builder builder = ImmutableListMultimap.builder(); for (Entry<?, List<?>> entry : value.entrySet()) { builder.putAll(entry.getKey(), entry.getValue()); } return (T) builder.build(); } }; } else if (ImmutableSetMultimap.class.isAssignableFrom(typeToken.getRawType())) { TypeToken<Map<?, Set<?>>> mapToken = getMapOfSetsToken((TypeToken) TypeToken.of(typeToken.getType())); final TypeAdapter<Map<?, Set<?>>> adapter = (TypeAdapter<Map<?, Set<?>>>) gson .getAdapter(com.google.gson.reflect.TypeToken.get(mapToken.getType())); return new TypeAdapter<T>() { @Override public void write(JsonWriter out, T value) throws IOException { ImmutableSetMultimap<?, ?> multimap = (ImmutableSetMultimap<?, ?>) value; adapter.write(out, (Map) multimap.asMap()); } @Override public T read(JsonReader in) throws IOException { Map<?, Set<?>> value = adapter.read(in); ImmutableSetMultimap.Builder builder = ImmutableSetMultimap.builder(); for (Entry<?, Set<?>> entry : value.entrySet()) { builder.putAll(entry.getKey(), entry.getValue()); } return (T) builder.build(); } }; } else { return null; } }
From source file:com.google.devtools.build.android.ZipFilterAction.java
@VisibleForTesting static Multimap<String, Long> getEntriesToOmit(Collection<Path> filterZips, Collection<String> filterTypes) throws IOException { // Escape filter types to prevent regex abuse Set<String> escapedFilterTypes = new HashSet<>(); for (String filterType : filterTypes) { escapedFilterTypes.add(Pattern.quote(filterType)); }// ww w. j a v a 2 s .co m // Match any string that ends with any of the filter file types String filterRegex = String.format(".*(%s)$", Joiner.on("|").join(escapedFilterTypes)); ImmutableSetMultimap.Builder<String, Long> entriesToOmit = ImmutableSetMultimap.builder(); for (Path filterZip : filterZips) { try (ZipReader zip = new ZipReader(filterZip.toFile())) { for (ZipFileEntry entry : zip.entries()) { if (filterTypes.isEmpty() || entry.getName().matches(filterRegex)) { entriesToOmit.put(entry.getName(), entry.getCrc()); } } } } return entriesToOmit.build(); }
From source file:uk.ac.ebi.atlas.bioentity.GeneSetPageController.java
@Override protected void initBioentityPropertyService(String identifier) { String species = speciesResult.isSingleSpecies() ? speciesResult.firstSpecies() : ""; SortedSetMultimap<String, String> propertyValuesByType = TreeMultimap.create(); ImmutableSetMultimap.Builder<Integer, GoPoTerm> builder = new ImmutableSetMultimap.Builder<>(); ImmutableSetMultimap<Integer, GoPoTerm> goTermsByDepth = builder.build(); ImmutableSetMultimap<Integer, GoPoTerm> poTermsByDepth = builder.build(); identifier = identifier.toUpperCase(); if (GeneSetUtil.isReactome(identifier)) { propertyValuesByType.put("reactome", identifier); propertyValuesByType.put(BioEntityPropertyService.PROPERTY_TYPE_DESCRIPTION, reactomeClient.fetchPathwayNameFailSafe(identifier)); } else if (GeneSetUtil.isGeneOntology(identifier)) { String termName = goTermTrader.getTermName(identifier); propertyValuesByType.put("go", identifier); propertyValuesByType.put(BioEntityPropertyService.PROPERTY_TYPE_DESCRIPTION, termName); goTermsByDepth = mapGoTermsByDepth(propertyValuesByType.get("go")); } else if (GeneSetUtil.isPlantOntology(identifier)) { String termName = poTermTrader.getTermName(identifier); propertyValuesByType.put("po", identifier); propertyValuesByType.put(BioEntityPropertyService.PROPERTY_TYPE_DESCRIPTION, termName); poTermsByDepth = mapPoTermsByDepth(propertyValuesByType.get("po")); } else if (GeneSetUtil.isInterPro(identifier)) { String term = interProTermTrader.getTerm(identifier); propertyValuesByType.put("interpro", identifier); propertyValuesByType.put(BioEntityPropertyService.PROPERTY_TYPE_DESCRIPTION, term); } else if (GeneSetUtil.isPlantReactome(identifier)) { propertyValuesByType.put("plant_reactome", identifier); }//from w w w .j ava 2 s . c o m SortedSet<String> names = Sets.newTreeSet(); names.add(identifier); bioEntityPropertyService.init(species, propertyValuesByType, goTermsByDepth, poTermsByDepth, names, identifier); }