Example usage for com.google.common.collect ImmutableSet.Builder addAll

List of usage examples for com.google.common.collect ImmutableSet.Builder addAll

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSet.Builder addAll.

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

Usage

From source file:com.netflix.genie.web.controllers.DtoConverters.java

/**
 * Convert the V4 values supplied to how the tags would have looked in Genie V3.
 *
 * @param id   The id of the resource/* www.  j a va2s  . c  o m*/
 * @param name The name of the resource
 * @param tags The tags on the resource
 * @return The set of tags as they would have been in Genie 3
 */
public static ImmutableSet<String> toV3Tags(final String id, final String name, final Set<String> tags) {
    final ImmutableSet.Builder<String> v3Tags = ImmutableSet.builder();
    v3Tags.addAll(tags);
    v3Tags.add(GENIE_ID_PREFIX + id);
    v3Tags.add(GENIE_NAME_PREFIX + name);
    return v3Tags.build();
}

From source file:com.facebook.watchman.environment.ExecutableFinder.java

private static ImmutableSet<Path> getPaths(ImmutableMap<String, String> env) {
    ImmutableSet.Builder<Path> paths = ImmutableSet.builder();

    // Add the empty path so that when we iterate over it, we can check for the suffixed version of
    // a given path, be it absolute or not.
    paths.add(Paths.get(""));

    String pathEnv = env.get("PATH");
    if (pathEnv != null) {
        paths.addAll(FluentIterable.from(Splitter.on(pathSeparator).omitEmptyStrings().split(pathEnv))
                .transform(TO_PATH));/*w ww  . j  a v a 2s  .  c  o m*/
    }

    if (Platform.isMac()) {
        Path osXPaths = Paths.get("/etc/paths");
        if (Files.exists(osXPaths)) {
            try {
                paths.addAll(FluentIterable.from(Files.readAllLines(osXPaths, Charset.defaultCharset()))
                        .transform(TO_PATH));
            } catch (IOException e) {
            }
        }
    }

    return paths.build();
}

From source file:org.sosy_lab.cpachecker.cpa.invariants.InvariantsPrecision.java

private static ImmutableSet<CFAEdge> asImmutableRelevantEdges(Set<CFAEdge> pRelevantEdges) {
    if (pRelevantEdges == null) {
        return null;
    }/*  w  w w  .  ja v  a 2  s . c om*/
    ImmutableSet.Builder<CFAEdge> builder = ImmutableSet.builder();
    Queue<CFAEdge> waitlist = new ArrayDeque<>(pRelevantEdges);
    while (!waitlist.isEmpty()) {
        CFAEdge relevantEdge = waitlist.poll();
        builder.add(relevantEdge);
        if (relevantEdge.getEdgeType() == CFAEdgeType.MultiEdge) {
            builder.addAll(((MultiEdge) relevantEdge));
        }
    }
    return builder.build();
}

From source file:com.facebook.buck.python.PythonUtil.java

public static ImmutableSet<String> getPreloadNames(BuildRuleResolver resolver, CxxPlatform cxxPlatform,
        Iterable<BuildTarget> preloadDeps) throws NoSuchBuildTargetException {
    ImmutableSet.Builder<String> builder = ImmutableSortedSet.naturalOrder();
    for (NativeLinkable nativeLinkable : FluentIterable.from(preloadDeps).transform(resolver::getRule)
            .filter(NativeLinkable.class)) {
        builder.addAll(nativeLinkable.getSharedLibraries(cxxPlatform).keySet());
    }//from ww w .j a  v  a  2 s.  c om
    return builder.build();
}

From source file:com.google.devtools.build.lib.rules.java.JavaPluginInfoProvider.java

public static JavaPluginInfoProvider merge(Iterable<JavaPluginInfoProvider> providers) {
    ImmutableSet.Builder<String> processorClasses = ImmutableSet.builder();
    NestedSetBuilder<Artifact> processorClasspath = NestedSetBuilder.naiveLinkOrder();
    ImmutableSet.Builder<String> apiGeneratingProcessorClasses = ImmutableSet.builder();
    NestedSetBuilder<Artifact> apiGeneratingProcessorClasspath = NestedSetBuilder.naiveLinkOrder();

    for (JavaPluginInfoProvider provider : providers) {
        processorClasses.addAll(provider.getProcessorClasses());
        processorClasspath.addTransitive(provider.getProcessorClasspath());
        apiGeneratingProcessorClasses.addAll(provider.getApiGeneratingProcessorClasses());
        apiGeneratingProcessorClasspath.addTransitive(provider.getApiGeneratingProcessorClasspath());
    }/*from   www .  ja  v  a  2s .  c om*/
    return new JavaPluginInfoProvider(processorClasses.build(), processorClasspath.build(),
            apiGeneratingProcessorClasses.build(), apiGeneratingProcessorClasspath.build());
}

From source file:com.facebook.buck.features.python.PythonUtil.java

static ImmutableSet<String> getPreloadNames(ActionGraphBuilder graphBuilder, CxxPlatform cxxPlatform,
        Iterable<BuildTarget> preloadDeps) {
    ImmutableSet.Builder<String> builder = ImmutableSortedSet.naturalOrder();
    for (NativeLinkable nativeLinkable : FluentIterable.from(preloadDeps).transform(graphBuilder::getRule)
            .filter(NativeLinkable.class)) {
        builder.addAll(nativeLinkable.getSharedLibraries(cxxPlatform, graphBuilder).keySet());
    }//from ww  w .j  a va  2 s  .com
    return builder.build();
}

From source file:com.facebook.buck.android.toolchain.impl.AndroidPlatformTargetProducer.java

/**
 * Given the path to the Android SDK as well as the platform path within the Android SDK, find all
 * the files needed to create the {@link AndroidPlatformTarget}, assuming that the organization of
 * the Android SDK conforms to the ordinary directory structure.
 *///from  www.  j ava2 s.  c o m
@VisibleForTesting
static AndroidPlatformTarget createFromDefaultDirectoryStructure(ProjectFilesystem filesystem, String name,
        AndroidBuildToolsLocation androidBuildToolsLocation, AndroidSdkLocation androidSdkLocation,
        String platformDirectoryPath, Set<Path> additionalJarPaths, Optional<Supplier<Tool>> aaptOverride,
        Optional<Supplier<Tool>> aapt2Override) {
    Path androidSdkDir = androidSdkLocation.getSdkRootPath();
    if (!androidSdkDir.isAbsolute()) {
        throw new HumanReadableException("Path to Android SDK must be absolute but was: %s.", androidSdkDir);
    }

    Path platformDirectory = androidSdkDir.resolve(platformDirectoryPath);
    Path androidJar = platformDirectory.resolve("android.jar");

    // Add any libraries found in the optional directory under the Android SDK directory. These
    // go at the head of the bootclasspath before any additional jars.
    File optionalDirectory = platformDirectory.resolve("optional").toFile();
    if (optionalDirectory.exists() && optionalDirectory.isDirectory()) {
        String[] optionalDirList = optionalDirectory.list(new AddonFilter());
        if (optionalDirList != null) {
            Arrays.sort(optionalDirList);
            ImmutableSet.Builder<Path> additionalJars = ImmutableSet.builder();
            for (String file : optionalDirList) {
                additionalJars.add(optionalDirectory.toPath().resolve(file));
            }
            additionalJars.addAll(additionalJarPaths);
            additionalJarPaths = additionalJars.build();
        }
    }

    LinkedList<Path> bootclasspathEntries = Lists.newLinkedList(additionalJarPaths);

    // Make sure android.jar is at the front of the bootclasspath.
    bootclasspathEntries.addFirst(androidJar);

    // This is the directory under the Android SDK directory that contains the dx script, jack,
    // jill, and binaries.
    Path buildToolsDir = androidBuildToolsLocation.getBuildToolsPath();
    Path buildToolsBinDir = androidBuildToolsLocation.getBuildToolsBinPath();
    String version = buildToolsDir.getFileName().toString();

    Path zipAlignExecutable = androidSdkDir.resolve("tools/zipalign").toAbsolutePath();
    if (!zipAlignExecutable.toFile().exists()) {
        // Android SDK Build-tools >= 19.1.0 have zipalign under the build-tools directory.
        zipAlignExecutable = androidSdkDir.resolve(buildToolsBinDir).resolve("zipalign").toAbsolutePath();
    }

    Path androidFrameworkIdlFile = platformDirectory.resolve("framework.aidl");
    Path proguardJar = androidSdkDir.resolve("tools/proguard/lib/proguard.jar");
    Path proguardConfig = androidSdkDir.resolve("tools/proguard/proguard-android.txt");
    Path optimizedProguardConfig = androidSdkDir.resolve("tools/proguard/proguard-android-optimize.txt");

    return AndroidPlatformTarget
            .of(name, androidJar.toAbsolutePath(), bootclasspathEntries,
                    aaptOverride
                            .orElse(() -> VersionedTool
                                    .of(PathSourcePath.of(filesystem,
                                            androidSdkDir.resolve(androidBuildToolsLocation.getAaptPath())
                                                    .toAbsolutePath()),
                                            "aapt", version)),
                    aapt2Override.orElse(() -> VersionedTool.of(PathSourcePath.of(filesystem,
                            androidSdkDir.resolve(androidBuildToolsLocation.getAapt2Path()).toAbsolutePath()),
                            "aapt2", version)),
                    androidSdkDir.resolve("platform-tools/adb").toAbsolutePath(),
                    androidSdkDir.resolve(buildToolsBinDir).resolve("aidl").toAbsolutePath(),
                    zipAlignExecutable,
                    buildToolsDir.resolve(Platform.detect() == Platform.WINDOWS ? "dx.bat" : "dx")
                            .toAbsolutePath(),
                    androidFrameworkIdlFile, proguardJar, proguardConfig, optimizedProguardConfig);
}

From source file:org.gradle.workers.internal.DefaultWorkerExecutor.java

private static void addVisibilityFor(Class<?> visibleClass, ImmutableSet.Builder<File> classpathBuilder,
        ImmutableSet.Builder<String> sharedPackagesBuilder, boolean addToSharedPackages) {
    if (visibleClass.getClassLoader() != null) {
        classpathBuilder.addAll(ClasspathUtil.getClasspath(visibleClass.getClassLoader()).getAsFiles());
    }/*from w ww. j  a  va  2 s.  c om*/

    if (addToSharedPackages) {
        addVisiblePackage(visibleClass, sharedPackagesBuilder);
    }
}

From source file:com.facebook.buck.haskell.HaskellGhciRule.java

public static HaskellGhciRule from(BuildTarget buildTarget, ProjectFilesystem projectFilesystem,
        BuildRuleParams params, BuildRuleResolver resolver, HaskellSources srcs,
        ImmutableList<String> compilerFlags, Optional<BuildTarget> ghciBinDep, Optional<SourcePath> ghciInit,
        BuildRule omnibusSharedObject, ImmutableSortedMap<String, SourcePath> solibs,
        ImmutableSet<HaskellPackage> firstOrderHaskellPackages, ImmutableSet<HaskellPackage> haskellPackages,
        ImmutableSet<HaskellPackage> prebuiltHaskellPackages, boolean enableProfiling, Path ghciScriptTemplate,
        Path ghciBinutils, Path ghciGhc, Path ghciLib, Path ghciCxx, Path ghciCc, Path ghciCpp) {

    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    ImmutableSet.Builder<BuildRule> extraDeps = ImmutableSet.builder();

    extraDeps.add(omnibusSharedObject);// ww w .  j a  v a 2s  . co  m

    for (HaskellPackage pkg : haskellPackages) {
        extraDeps.addAll(pkg.getDeps(ruleFinder)::iterator);
    }

    for (HaskellPackage pkg : prebuiltHaskellPackages) {
        extraDeps.addAll(pkg.getDeps(ruleFinder)::iterator);
    }

    if (ghciBinDep.isPresent()) {
        extraDeps.add(resolver.getRule(ghciBinDep.get()));
    }

    extraDeps.addAll(ruleFinder.filterBuildRuleInputs(solibs.values()));

    return new HaskellGhciRule(buildTarget, projectFilesystem, params.copyAppendingExtraDeps(extraDeps.build()),
            resolver, srcs, compilerFlags, ghciBinDep, ghciInit, omnibusSharedObject, solibs,
            firstOrderHaskellPackages, haskellPackages, prebuiltHaskellPackages, enableProfiling,
            ghciScriptTemplate, ghciBinutils, ghciGhc, ghciLib, ghciCxx, ghciCc, ghciCpp);
}

From source file:com.publictransitanalytics.scoregenerator.workflow.DynamicProgrammingAlgorithm.java

private static Set<PointLocation> getRoundUpdates(final Set<? extends PointLocation> updateSet,
        final Map<PointLocation, DynamicProgrammingRecord> stateMap, final LocalDateTime cutoffTime,
        final TimeTracker timeTracker, final ReachabilityClient reachabilityClient,
        final RiderFactory riderFactory) throws InterruptedException {
    final ImmutableSet.Builder<PointLocation> updateSetBuilder = ImmutableSet.builder();
    for (final PointLocation priorLocation : updateSet) {

        final DynamicProgrammingRecord priorRecord = stateMap.get(priorLocation);
        final LocalDateTime currentTime = priorRecord.getReachTime();

        final ImmutableSet.Builder<ReachabilityOutput> reachabilitiesBuilder = ImmutableSet.builder();

        final FlatTransitRideVisitor transitRideVisitor = new FlatTransitRideVisitor(cutoffTime, cutoffTime,
                currentTime, riderFactory);
        priorLocation.accept(transitRideVisitor);
        final Set<ReachabilityOutput> transitRides = transitRideVisitor.getOutput();
        reachabilitiesBuilder.addAll(transitRides);

        if (!priorRecord.getMode().getType().equals(ModeType.WALKING)) {
            final FlatWalkVisitor walkVisitor = new FlatWalkVisitor(cutoffTime, currentTime, reachabilityClient,
                    timeTracker);//from w  w  w .j av a 2 s .c om
            priorLocation.accept(walkVisitor);
            final Set<ReachabilityOutput> walks = walkVisitor.getOutput();
            reachabilitiesBuilder.addAll(walks);
        }

        updateSetBuilder.addAll(updateRow(reachabilitiesBuilder.build(), stateMap, priorLocation, timeTracker));
    }

    return updateSetBuilder.build();
}