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

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

Introduction

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

Prototype

@Override
public ImmutableSet<K> keySet() 

Source Link

Document

Returns an immutable set of the distinct keys in this multimap, in the same order as they appear in this multimap.

Usage

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  w w  .jav  a  2 s .  c  om*/
    return setArray;
}

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.ja v a  2 s.c  om
    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 www . j a  v  a 2 s  .com
    return setArray;
}

From source file:com.facebook.buck.jvm.java.intellij.IjModuleFactory.java

private static void addDeps(ImmutableMultimap<Path, Path> foldersToInputsIndex, TargetNode<?, ?> targetNode,
        DependencyType dependencyType, ModuleBuildContext context) {
    context.addDeps(foldersToInputsIndex.keySet(), targetNode.getDeps(), dependencyType);
}

From source file:com.facebook.buck.java.intellij.IjModuleFactory.java

private static void addDepsAndSources(TargetNode<?> targetNode, boolean isTest, boolean wantsPackagePrefix,
        ModuleBuildContext context) {//from w  w  w .  j a v a  2 s. c o m
    ImmutableMultimap<Path, Path> foldersToInputsIndex = getSourceFoldersToInputsIndex(targetNode.getInputs());
    addSourceFolders(foldersToInputsIndex, isTest ? IjFolder.Type.TEST_FOLDER : IjFolder.Type.SOURCE_FOLDER,
            wantsPackagePrefix, context);
    context.addDeps(foldersToInputsIndex.keySet(), targetNode.getDeps(),
            isTest ? IjModuleGraph.DependencyType.TEST : IjModuleGraph.DependencyType.PROD);
}

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// www.jav a  2  s. co m
 */
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  a va  2 s  .c  o  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();
}

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

@SuppressWarnings("PMD.PrematureDeclaration")
static NativeLibraryMergeEnhancementResult enhance(CxxBuckConfig cxxBuckConfig, BuildRuleResolver ruleResolver,
        SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder, BuildRuleParams buildRuleParams,
        ImmutableMap<NdkCxxPlatforms.TargetCpuType, NdkCxxPlatform> nativePlatforms,
        Map<String, List<Pattern>> mergeMap, Optional<BuildTarget> nativeLibraryMergeGlue,
        ImmutableMultimap<APKModule, NativeLinkable> linkables,
        ImmutableMultimap<APKModule, NativeLinkable> linkablesAssets) throws NoSuchBuildTargetException {
    NativeLibraryMergeEnhancer.ruleFinder = ruleFinder;

    NativeLibraryMergeEnhancementResult.Builder builder = NativeLibraryMergeEnhancementResult.builder();

    ImmutableSet<APKModule> modules = ImmutableSet.<APKModule>builder().addAll(linkables.keySet())
            .addAll(linkablesAssets.keySet()).build();

    ImmutableSortedMap.Builder<String, String> sonameMapBuilder = ImmutableSortedMap.naturalOrder();

    for (APKModule module : modules) {
        // Sort by build target here to ensure consistent behavior.
        Iterable<NativeLinkable> allLinkables = FluentIterable
                .from(Iterables.concat(linkables.get(module), linkablesAssets.get(module)))
                .toSortedList(HasBuildTarget.BUILD_TARGET_COMPARATOR);

        final ImmutableSet<NativeLinkable> linkableAssetSet = ImmutableSet.copyOf(linkablesAssets.get(module));
        Map<NativeLinkable, MergedNativeLibraryConstituents> linkableMembership = makeConstituentMap(
                buildRuleParams, mergeMap, allLinkables, linkableAssetSet);

        sonameMapBuilder.putAll(makeSonameMap(
                // sonames can *theoretically* differ per-platform, but right now they don't on Android,
                // so just pick the first platform and use that to get all the sonames.
                nativePlatforms.values().iterator().next().getCxxPlatform(), linkableMembership));

        Iterable<MergedNativeLibraryConstituents> orderedConstituents = getOrderedMergedConstituents(
                buildRuleParams, linkableMembership);

        Optional<NativeLinkable> glueLinkable = Optional.empty();
        if (nativeLibraryMergeGlue.isPresent()) {
            BuildRule rule = ruleResolver.getRule(nativeLibraryMergeGlue.get());
            if (!(rule instanceof NativeLinkable)) {
                throw new RuntimeException("Native library merge glue " + rule.getBuildTarget()
                        + " for application " + buildRuleParams.getBuildTarget() + " is not linkable.");
            }/*from   w w  w . jav  a 2 s .c  o  m*/
            glueLinkable = Optional.of(((NativeLinkable) rule));
        }

        Set<MergedLibNativeLinkable> mergedLinkables = createLinkables(cxxBuckConfig, ruleResolver,
                pathResolver, buildRuleParams, glueLinkable, orderedConstituents);

        for (MergedLibNativeLinkable linkable : mergedLinkables) {
            if (Collections.disjoint(linkable.constituents.getLinkables(), linkableAssetSet)) {
                builder.putMergedLinkables(module, linkable);
            } else if (linkableAssetSet.containsAll(linkable.constituents.getLinkables())) {
                builder.putMergedLinkablesAssets(module, linkable);
            }
        }
    }
    builder.setSonameMapping(sonameMapBuilder.build());
    return builder.build();
}

From source file:com.facebook.buck.features.project.intellij.lang.java.JavaTestModuleRule.java

@Override
public void apply(TargetNode<JavaTestDescription.CoreArg> target, ModuleBuildContext context) {
    Optional<Path> presetResourcesRoot = target.getConstructorArg().getResourcesRoot();
    ImmutableSortedSet<SourcePath> resources = target.getConstructorArg().getResources();
    ImmutableSet<Path> resourcePaths;
    if (presetResourcesRoot.isPresent()) {
        resourcePaths = getResourcePaths(target.getConstructorArg().getResources(), presetResourcesRoot.get());
        addResourceFolders(IjResourceFolderType.JAVA_TEST_RESOURCE, resourcePaths, presetResourcesRoot.get(),
                context);//from   w  w  w.j  a v a2 s  . co  m
    } else {
        resourcePaths = getResourcePaths(resources);
        ImmutableMultimap<Path, Path> resourcesRootsToResources = getResourcesRootsToResources(packageFinder,
                resourcePaths);
        for (Path resourcesRoot : resourcesRootsToResources.keySet()) {
            addResourceFolders(IjResourceFolderType.JAVA_TEST_RESOURCE,
                    resourcesRootsToResources.get(resourcesRoot), resourcesRoot, context);
        }
    }
    addDepsAndTestSources(target, true /* wantsPackagePrefix */, context, resourcePaths);
    JavaLibraryRuleHelper.addCompiledShadowIfNeeded(projectConfig, target, context);
    context.setJavaLanguageLevel(JavaLibraryRuleHelper.getLanguageLevel(projectConfig, target));
}

From source file:com.facebook.buck.features.project.intellij.lang.java.JavaLibraryModuleRule.java

@Override
public void apply(TargetNode<JavaLibraryDescription.CoreArg> target, ModuleBuildContext context) {
    Optional<Path> presetResourcesRoot = target.getConstructorArg().getResourcesRoot();
    ImmutableSortedSet<SourcePath> resources = target.getConstructorArg().getResources();
    ImmutableSet<Path> resourcePaths;
    if (presetResourcesRoot.isPresent()) {
        resourcePaths = getResourcePaths(resources, presetResourcesRoot.get());
        addResourceFolders(IjResourceFolderType.JAVA_RESOURCE, resourcePaths, presetResourcesRoot.get(),
                context);//from  w w w  . j av a  2  s  .  c  o  m
    } else {
        resourcePaths = getResourcePaths(resources);
        ImmutableMultimap<Path, Path> resourcesRootsToResources = getResourcesRootsToResources(packageFinder,
                resourcePaths);
        for (Path resourcesRoot : resourcesRootsToResources.keySet()) {
            addResourceFolders(IjResourceFolderType.JAVA_RESOURCE, resourcesRootsToResources.get(resourcesRoot),
                    resourcesRoot, context);
        }
    }

    addDepsAndSources(target, true /* wantsPackagePrefix */, context, resourcePaths);
    JavaLibraryRuleHelper.addCompiledShadowIfNeeded(projectConfig, target, context);
    JavaLibraryRuleHelper.addNonSourceBuildTargets(target, context);
    context.setJavaLanguageLevel(JavaLibraryRuleHelper.getLanguageLevel(projectConfig, target));
    context.setCompilerOutputPath(moduleFactoryResolver.getCompilerOutputPath(target));
}