Example usage for com.google.common.collect ImmutableSetMultimap builder

List of usage examples for com.google.common.collect ImmutableSetMultimap builder

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSetMultimap builder.

Prototype

public static <K, V> Builder<K, V> builder() 

Source Link

Document

Returns a new Builder .

Usage

From source file:uk.ac.ebi.atlas.model.ExperimentDesign.java

public ImmutableSetMultimap<String, String> getAllOntologyTermIdsByAssayAccession() {
    ImmutableSetMultimap.Builder<String, String> builder = ImmutableSetMultimap.builder();

    addFactorOntologyTerms(builder);//from   ww  w  .j a v a 2  s  . c om
    addCharacteristicOntologyTerms(builder);

    return builder.build();
}

From source file:dagger.internal.codegen.FrameworkDependency.java

/**
 * Groups a binding's dependency requests by their binding key.
 *
 * @param transformer applied to each dependency before inserting into the group
 *//* w w w .j  a v a  2 s .  c  o  m*/
private static ImmutableList<Collection<DependencyRequest>> groupByKey(Binding binding,
        Function<DependencyRequest, DependencyRequest> transformer) {
    ImmutableSetMultimap.Builder<BindingKey, DependencyRequest> dependenciesByKeyBuilder = ImmutableSetMultimap
            .builder();
    for (DependencyRequest dependency : binding.implicitDependencies()) {
        dependenciesByKeyBuilder.put(dependency.bindingKey(), transformer.apply(dependency));
    }
    return ImmutableList.copyOf(
            dependenciesByKeyBuilder.orderValuesBy(SourceFiles.DEPENDENCY_ORDERING).build().asMap().values());
}

From source file:com.facebook.buck.jvm.java.JavaSymbolFinder.java

/**
 * Figure out the build targets that provide a set of Java symbols.
 * @param symbols The set of symbols (e.g. "com.example.foo.Bar") to find defining targets for.
 *                This is taken as a collection, rather than as an individual string, because
 *                instantiating a ProjectBuildFileParser is expensive (it spawns a Python
 *                subprocess), and we don't want to encourage the caller to do it more than once.
 * @return A multimap of symbols to the targets that define them, of the form:
 *         {"com.example.a.A": set("//com/example/a:a", "//com/another/a:a")}
 *///from  w w  w.  j ava 2s  .  c om
public ImmutableSetMultimap<String, BuildTarget> findTargetsForSymbols(Set<String> symbols)
        throws InterruptedException, IOException {
    // TODO(oconnor663): Handle files that aren't included in any rule.

    // First find all the source roots in the current project.
    Collection<Path> srcRoots;
    try {
        srcRoots = srcRootsFinder.getAllSrcRootPaths(config.getView(JavaBuckConfig.class).getSrcRoots());
    } catch (IOException e) {
        buckEventBus.post(ThrowableConsoleEvent.create(e, "Error while searching for source roots."));
        return ImmutableSetMultimap.of();
    }

    // Now collect all the code files that define our symbols.
    Multimap<String, Path> symbolsToSourceFiles = HashMultimap.create();
    for (String symbol : symbols) {
        symbolsToSourceFiles.putAll(symbol, getDefiningPaths(symbol, srcRoots));
    }

    // Now find all the targets that define all those code files. We do this in one pass because we
    // don't want to instantiate a new parser subprocess for every symbol.
    Set<Path> allSourceFilePaths = ImmutableSet.copyOf(symbolsToSourceFiles.values());
    Multimap<Path, BuildTarget> sourceFilesToTargets = getTargetsForSourceFiles(allSourceFilePaths);

    // Now build the map from from symbols to build targets.
    ImmutableSetMultimap.Builder<String, BuildTarget> symbolsToTargets = ImmutableSetMultimap.builder();
    for (String symbol : symbolsToSourceFiles.keySet()) {
        for (Path sourceFile : symbolsToSourceFiles.get(symbol)) {
            symbolsToTargets.putAll(symbol, sourceFilesToTargets.get(sourceFile));
        }
    }

    return symbolsToTargets.build();
}

From source file:uk.ac.ebi.atlas.model.ExperimentDesign.java

private void addCharacteristicOntologyTerms(ImmutableSetMultimap.Builder<String, String> builder) {
    for (Map.Entry<String, SampleCharacteristics> sampleEntry : samples.entrySet()) {
        String runOrAssay = sampleEntry.getKey();
        SampleCharacteristics sampleCharacteristics = sampleEntry.getValue();

        for (SampleCharacteristic sampleCharacteristic : sampleCharacteristics.values()) {
            for (OntologyTerm valueOntologyTerm : sampleCharacteristic.valueOntologyTerms()) {
                builder.put(runOrAssay, valueOntologyTerm.id());
            }/*w  ww.  j ava2  s  .c om*/
        }

    }
}

From source file:com.publictransitanalytics.scoregenerator.environment.StoredGrid.java

private static ImmutableSetMultimap<GridPoint, Sector> getPointSectorMap(final String gridId,
        final Map<String, Sector> sectorIdMap,
        final RangedStore<GridPointAssociationKey, GridPointAssociation> store) throws InterruptedException {
    final GridPointAssociationKey min = GridPointAssociationKey.getMinKey(gridId);
    final GridPointAssociationKey max = GridPointAssociationKey.getMaxKey(gridId);
    final ImmutableSetMultimap.Builder<GridPoint, Sector> builder = ImmutableSetMultimap.builder();
    try {//from  ww w  .ja  v a  2 s  . co m
        for (final GridPointAssociation association : store.getValuesInRange(min, max).values()) {
            final GridPoint gridPoint = new GridPoint(GeoPoint.parsRadianString(association.getPointString()),
                    association.getId());
            final Sector sector = sectorIdMap.get(association.getSectorId());
            builder.put(gridPoint, sector);
        }
        return builder.build();
    } catch (final BitvantageStoreException e) {
        throw new ScoreGeneratorFatalException(e);
    }
}

From source file:org.gradle.api.internal.tasks.properties.DefaultPropertyMetadataStore.java

private static Multimap<Class<? extends Annotation>, Class<? extends Annotation>> collectAnnotationOverrides(
        Iterable<PropertyAnnotationHandler> allAnnotationHandlers) {
    ImmutableSetMultimap.Builder<Class<? extends Annotation>, Class<? extends Annotation>> builder = ImmutableSetMultimap
            .builder();//from ww  w  . j a v a2  s  . c om
    for (PropertyAnnotationHandler handler : allAnnotationHandlers) {
        if (handler instanceof OverridingPropertyAnnotationHandler) {
            builder.put(((OverridingPropertyAnnotationHandler) handler).getOverriddenAnnotationType(),
                    handler.getAnnotationType());
        }
    }
    return builder.build();
}

From source file:com.google.walkaround.wave.server.googleimport.TaskDispatcher.java

public Multimap<Pair<SourceInstance, WaveletName>, ImportSharingMode> waveletImportsInProgress(
        List<ImportTask> tasksInProgress) {
    ImmutableSetMultimap.Builder<Pair<SourceInstance, WaveletName>, ImportSharingMode> out = ImmutableSetMultimap
            .builder();// ww  w.jav a  2s  . c  o  m
    for (ImportTask task : tasksInProgress) {
        if (task.getPayload().hasFindWavesTask()) {
            // nothing
        } else if (task.getPayload().hasFindWaveletsTask()) {
            // nothing
        } else {
            ImportWaveletTask t;
            if (task.getPayload().hasFetchAttachmentsTask()) {
                t = task.getPayload().getFetchAttachmentsTask().getOriginalImportTask();
            } else if (task.getPayload().hasImportWaveletTask()) {
                t = task.getPayload().getImportWaveletTask();
            } else {
                throw new AssertionError("Unknown task payload type: " + task);
            }
            out.put(Pair.of(sourceInstanceFactory.parseUnchecked(t.getInstance()),
                    WaveletName.of(WaveId.deserialise(t.getWaveId()), WaveletId.deserialise(t.getWaveletId()))),
                    t.getSettings().getSharingMode());
        }
    }
    return out.build();
}

From source file:com.google.errorprone.bugpatterns.RemoveUnusedImports.java

private static ImmutableSetMultimap<ImportTree, Symbol> getImportedSymbols(
        CompilationUnitTree compilationUnitTree, VisitorState state) {
    ImmutableSetMultimap.Builder<ImportTree, Symbol> builder = ImmutableSetMultimap.builder();
    for (ImportTree importTree : compilationUnitTree.getImports()) {
        builder.putAll(importTree, getImportedSymbols(importTree, state));
    }/* w  w  w .  j a  v  a2  s.co  m*/
    return builder.build();
}

From source file:com.facebook.buck.java.JavaSymbolFinder.java

/**
 * For all the possible BUCK files above each of the given source files, parse them to JSON to
 * find the targets that actually include these source files, and return a map of them. We do this
 * over a collection of source files, rather than a single file at a time, because instantiating
 * the BUCK file parser is expensive. (It spawns a Python subprocess.)
 *///from   w  ww.j  a  v  a2 s . co  m
private ImmutableMultimap<Path, BuildTarget> getTargetsForSourceFiles(Collection<Path> sourceFilePaths)
        throws InterruptedException {
    Map<Path, List<Map<String, Object>>> parsedBuildFiles = Maps.newHashMap();
    ImmutableSetMultimap.Builder<Path, BuildTarget> sourceFileTargetsMultimap = ImmutableSetMultimap.builder();
    try (ProjectBuildFileParser parser = projectBuildFileParserFactory.createParser(console, environment,
            buckEventBus)) {
        for (Path sourceFile : sourceFilePaths) {
            for (Path buckFile : possibleBuckFilesForSourceFile(sourceFile)) {
                List<Map<String, Object>> rules;
                // Avoid parsing the same BUCK file twice.
                if (parsedBuildFiles.containsKey(buckFile)) {
                    rules = parsedBuildFiles.get(buckFile);
                } else {
                    rules = parser.getAll(buckFile);
                    parsedBuildFiles.put(buckFile, rules);
                }

                for (Map<String, Object> ruleMap : rules) {
                    String type = (String) ruleMap.get(BuckPyFunction.TYPE_PROPERTY_NAME);
                    if (javaRuleTypes.contains(type)) {
                        @SuppressWarnings("unchecked")
                        List<String> srcs = (List<String>) Preconditions.checkNotNull(ruleMap.get("srcs"));
                        if (isSourceFilePathInSrcsList(sourceFile, srcs, buckFile.getParent())) {
                            Path buckFileDir = buckFile.getParent();
                            String baseName = "//"
                                    + (buckFileDir != null ? MorePaths.pathWithUnixSeparators(buckFileDir)
                                            : "");
                            String shortName = (String) Preconditions.checkNotNull(ruleMap.get("name"));
                            sourceFileTargetsMultimap.put(sourceFile,
                                    BuildTarget.builder(baseName, shortName).build());
                        }
                    }
                }
            }
        }
    } catch (BuildFileParseException e) {
        buckEventBus.post(ThrowableConsoleEvent.create(e, "Error while searching for targets."));
    }
    return sourceFileTargetsMultimap.build();
}

From source file:uk.ac.ebi.atlas.experimentimport.analyticsindex.baseline.BaselineAnalyticsIndexerService.java

ImmutableSetMultimap<String, String> buildConditionSearchTermsByAssayGroupId(BaselineExperiment experiment,
        SetMultimap<String, String> ontologyTermIdsByAssayAccession) {

    Collection<Condition> conditions = baselineConditionsBuilder.buildProperties(experiment,
            ontologyTermIdsByAssayAccession);

    ImmutableSetMultimap.Builder<String, String> builder = ImmutableSetMultimap.builder();

    for (Condition condition : conditions) {
        builder.putAll(condition.getAssayGroupId(), condition.getValues());
    }/*from  ww  w.  j a va 2  s. c  o  m*/

    return builder.build();

}