Example usage for com.google.common.collect ImmutableMultimap get

List of usage examples for com.google.common.collect ImmutableMultimap get

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableMultimap get.

Prototype

@Override
public abstract ImmutableCollection<V> get(K key);

Source Link

Document

Returns an immutable collection of the values for the given key.

Usage

From source file:com.github.brandtg.switchboard.LogServerPurgeTask.java

private static String getAndCheck(ImmutableMultimap<String, String> params, String name) {
    Collection<String> values = params.get(name);
    if (values == null || values.isEmpty()) {
        throw new IllegalArgumentException("Must provide " + name);
    }/*w  w  w  . j  ava 2 s .c  om*/
    return values.iterator().next();
}

From source file:pt.ua.tm.neji.core.parser.ParserSupport.java

public static List<ParserLevel> levelsSupportedByLanguage(ParserTool tool, ParserLanguage language) {
    ImmutableMultimap<ParserLanguage, ParserLevel> mapToUse = getMapforTool(tool);
    return Lists.newArrayList(mapToUse.get(language));
}

From source file:com.spectralogic.ds3client.helpers.strategy.StrategyUtils.java

public static ImmutableCollection<Range> getRangesForBlob(
        final ImmutableMap<String, ImmutableMultimap<BulkObject, Range>> rangesForBlobs,
        final BulkObject blob) {
    final ImmutableMultimap<BulkObject, Range> rangesForBlob = rangesForBlobs.get(blob.getName());

    if (rangesForBlob != null) {
        return rangesForBlob.get(blob);
    }//from   w  ww . j  a  v a 2s .c o  m

    return null;
}

From source file:com.google.doubleclick.openrtb.MapperUtil.java

@SuppressWarnings("unchecked")
public static <T> ImmutableSet<T>[] multimapIntToSets(ImmutableMultimap<Integer, T> mmap) {
    int iMax = Collections.max(mmap.keySet());
    ImmutableSet<T>[] setArray = new ImmutableSet[iMax + 1];
    for (Integer key : mmap.keySet()) {
        setArray[key] = ImmutableSet.copyOf(mmap.get(key));
    }// ww w .j a v  a 2 s.  com
    return setArray;
}

From source file:com.google.doubleclick.openrtb.MapperUtil.java

@SuppressWarnings("unchecked")
public static <E extends Enum<E>> ImmutableSet<E>[] multimapIntToEnumSets(ImmutableMultimap<Integer, E> mmap) {
    int iMax = Collections.max(mmap.keySet());
    ImmutableSet<E>[] setArray = new ImmutableSet[iMax + 1];
    for (Integer key : mmap.keySet()) {
        setArray[key] = Sets.immutableEnumSet(mmap.get(key));
    }//from ww w.j a  va 2s  . co  m
    return setArray;
}

From source file:com.google.doubleclick.openrtb.MapperUtil.java

@SuppressWarnings("unchecked")
public static <E extends Enum<E>, T> ImmutableSet<T>[] multimapEnumToSets(ImmutableMultimap<E, T> mmap) {
    E iMax = Collections.max(mmap.keySet());
    ImmutableSet<T>[] setArray = new ImmutableSet[iMax.ordinal() + 1];
    for (E key : mmap.keySet()) {
        setArray[key.ordinal()] = ImmutableSet.copyOf(mmap.get(key));
    }//w  ww. j  a  va2s . c o  m
    return setArray;
}

From source file:com.spectralogic.ds3client.helpers.ReadJobImpl.java

private static ImmutableCollection<Range> getRangesForBlob(
        final ImmutableMap<String, ImmutableMultimap<BulkObject, Range>> blobToRanges,
        final BulkObject ds3Object) {
    final ImmutableMultimap<BulkObject, Range> ranges = blobToRanges.get(ds3Object.getName());
    if (ranges == null)
        return null;
    return ranges.get(ds3Object);
}

From source file:com.facebook.buck.apple.xcode.RuleDependencyFinder.java

/**
 * Retrieve all rules related to the given roots in the given graph.
 *
 * "Related" is defined as:/*w  w w . j  a  v a 2s.  co  m*/
 * - The rules themselves
 * - Their transitive dependencies
 * - The tests of the above rules
 * - Any additional dependencies of the tests
 */
public static ImmutableSet<BuildRule> getAllRules(PartialGraph graph, Iterable<BuildTarget> initialTargets) {

    ImmutableList.Builder<BuildRule> initialRulesBuilder = ImmutableList.builder();
    for (BuildTarget target : initialTargets) {
        initialRulesBuilder.add(graph.getDependencyGraph().findBuildRuleByTarget(target));
    }

    ImmutableSet<BuildRule> buildRules = gatherTransitiveDependencies(initialRulesBuilder.build());
    ImmutableMultimap<BuildRule, BuildRule> ruleToTestRules = buildRuleToTestRulesMap(graph);

    // Extract the test rules for the initial rules and their dependencies.
    ImmutableSet.Builder<BuildRule> testRulesBuilder = ImmutableSet.builder();
    for (BuildRule rule : buildRules) {
        testRulesBuilder.addAll(ruleToTestRules.get(rule));
    }
    ImmutableSet<BuildRule> additionalBuildRules = gatherTransitiveDependencies(testRulesBuilder.build());

    return ImmutableSet.<BuildRule>builder().addAll(buildRules).addAll(additionalBuildRules).build();
}

From source file:com.facebook.buck.android.APKModuleGraph.java

/**
 * Group the classes in the input jars into a multimap based on the APKModule they belong to
 *
 * @param apkModuleToJarPathMap the mapping of APKModules to the path for the jar files
 * @param translatorFunction function used to translate obfuscated names
 * @param filesystem filesystem representation for resolving paths
 * @return The mapping of APKModules to the class names they contain
 * @throws IOException// w w  w.ja  v a2 s  .c om
 */
public static ImmutableMultimap<APKModule, String> getAPKModuleToClassesMap(
        final ImmutableMultimap<APKModule, Path> apkModuleToJarPathMap,
        final Function<String, String> translatorFunction, final ProjectFilesystem filesystem)
        throws IOException {
    final ImmutableMultimap.Builder<APKModule, String> builder = ImmutableMultimap.builder();
    if (!apkModuleToJarPathMap.isEmpty()) {
        for (final APKModule dexStore : apkModuleToJarPathMap.keySet()) {
            for (Path jarFilePath : apkModuleToJarPathMap.get(dexStore)) {
                ClasspathTraverser classpathTraverser = new DefaultClasspathTraverser();
                classpathTraverser.traverse(new ClasspathTraversal(ImmutableSet.of(jarFilePath), filesystem) {
                    @Override
                    public void visit(FileLike entry) {
                        if (!entry.getRelativePath().endsWith(".class")) {
                            // ignore everything but class files in the jar.
                            return;
                        }

                        builder.put(dexStore, translatorFunction.apply(entry.getRelativePath()));
                    }
                });
            }
        }
    }
    return builder.build();
}

From source file:com.facebook.buck.android.apkmodule.APKModuleGraph.java

/**
 * Group the classes in the input jars into a multimap based on the APKModule they belong to
 *
 * @param apkModuleToJarPathMap the mapping of APKModules to the path for the jar files
 * @param translatorFunction function used to translate the class names to obfuscated names
 * @param filesystem filesystem representation for resolving paths
 * @return The mapping of APKModules to the class names they contain
 * @throws IOException/* w  w  w .  j  av a 2s .co m*/
 */
public static ImmutableMultimap<APKModule, String> getAPKModuleToClassesMap(
        ImmutableMultimap<APKModule, Path> apkModuleToJarPathMap, Function<String, String> translatorFunction,
        ProjectFilesystem filesystem) throws IOException {
    ImmutableMultimap.Builder<APKModule, String> builder = ImmutableSetMultimap.builder();
    if (!apkModuleToJarPathMap.isEmpty()) {
        for (APKModule dexStore : apkModuleToJarPathMap.keySet()) {
            for (Path jarFilePath : apkModuleToJarPathMap.get(dexStore)) {
                ClasspathTraverser classpathTraverser = new DefaultClasspathTraverser();
                classpathTraverser.traverse(new ClasspathTraversal(ImmutableSet.of(jarFilePath), filesystem) {
                    @Override
                    public void visit(FileLike entry) {
                        if (!entry.getRelativePath().endsWith(".class")) {
                            // ignore everything but class files in the jar.
                            return;
                        }

                        String classpath = entry.getRelativePath().replaceAll("\\.class$", "");

                        if (translatorFunction.apply(classpath) != null) {
                            builder.put(dexStore, translatorFunction.apply(classpath));
                        }
                    }
                });
            }
        }
    }
    return builder.build();
}