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.facebook.buck.jvm.java.JavaLibraryClasspathProvider.java

/**
 * Given libraries that may contribute classpaths, visit them and collect the classpaths.
 *
 * This is used to generate transitive classpaths from library discovered in a previous traversal.
 *///from w  w  w  . ja  v  a  2  s  .com
public static ImmutableSet<Path> getClasspathsFromLibraries(Iterable<JavaLibrary> libraries) {
    ImmutableSet.Builder<Path> classpathEntries = ImmutableSet.builder();
    for (JavaLibrary library : libraries) {
        classpathEntries.addAll(library.getImmediateClasspaths());
    }
    return classpathEntries.build();
}

From source file:com.google.caliper.runner.EffectiveClassPath.java

private static ImmutableSet<File> getClassPathFiles(ClassLoader classLoader) {
    ImmutableSet.Builder<File> files = ImmutableSet.builder();
    @Nullable/*from  w  w  w. j a  va 2  s .  c  o  m*/
    ClassLoader parent = classLoader.getParent();
    if (parent != null) {
        files.addAll(getClassPathFiles(parent));
    }
    if (classLoader instanceof URLClassLoader) {
        URLClassLoader urlClassLoader = (URLClassLoader) classLoader;
        for (URL url : urlClassLoader.getURLs()) {
            try {
                files.add(new File(url.toURI()));
            } catch (URISyntaxException e) {
                // skip it then
            } catch (IllegalArgumentException e) {
                // skip it then
            }
        }
    }
    return files.build();
}

From source file:com.github.rinde.rinsim.central.GlobalStateObjects.java

static ImmutableSet<Parcel> assignedParcels(GlobalStateObject state) {
    final ImmutableSet.Builder<Parcel> set = ImmutableSet.builder();
    for (final VehicleStateObject vso : state.getVehicles()) {
        if (vso.getRoute().isPresent()) {
            set.addAll(vso.getRoute().get());
        }/*from  www . j  av  a  2  s  .co  m*/
    }
    return set.build();
}

From source file:com.tngtech.archunit.lang.syntax.Transformers.java

static ClassesTransformer<JavaConstructor> constructors() {
    return new AbstractClassesTransformer<JavaConstructor>("constructors") {
        @Override/*from  w ww  .  j a va 2s.co m*/
        public Iterable<JavaConstructor> doTransform(JavaClasses collection) {
            ImmutableSet.Builder<JavaConstructor> result = ImmutableSet.builder();
            for (JavaClass javaClass : collection) {
                result.addAll(javaClass.getConstructors());
            }
            return result.build();
        }
    };
}

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

static Iterable<PathFragment> datamodelDirs(Iterable<Artifact> xcdatamodels) {
    ImmutableSet.Builder<PathFragment> result = new ImmutableSet.Builder<>();
    for (Collection<Artifact> artifacts : byContainer(xcdatamodels).asMap().values()) {
        result.addAll(ObjcCommon.uniqueContainers(artifacts, FileType.of(".xcdatamodel")));
    }//from  www .j  a v a  2  s .  c o m
    return result.build();
}

From source file:io.prestosql.sql.planner.SymbolsExtractor.java

public static Set<Symbol> extractUnique(PlanNode node) {
    ImmutableSet.Builder<Symbol> uniqueSymbols = ImmutableSet.builder();
    extractExpressions(node).forEach(expression -> uniqueSymbols.addAll(extractUnique(expression)));

    return uniqueSymbols.build();
}

From source file:com.google.devtools.build.lib.runtime.BlazeCommandUtils.java

public static ImmutableSet<Class<? extends OptionsBase>> getCommonOptions(Iterable<BlazeModule> modules) {
    ImmutableSet.Builder<Class<? extends OptionsBase>> builder = ImmutableSet.builder();
    builder.addAll(COMMON_COMMAND_OPTIONS);
    for (BlazeModule blazeModule : modules) {
        builder.addAll(blazeModule.getCommonCommandOptions());
    }//from w w w.j a va 2 s .c om
    return builder.build();
}

From source file:com.google.caliper.runner.target.EffectiveClassPath.java

private static Set<File> getClassPathFiles(ClassLoader classLoader) {
    ImmutableSet.Builder<File> files = ImmutableSet.builder();
    @Nullable/*from  ww  w.  j av a 2  s  . c  o m*/
    ClassLoader parent = classLoader.getParent();
    if (parent != null) {
        files.addAll(getClassPathFiles(parent));
    }
    if (classLoader instanceof URLClassLoader) {
        URLClassLoader urlClassLoader = (URLClassLoader) classLoader;
        for (URL url : urlClassLoader.getURLs()) {
            try {
                files.add(new File(url.toURI()));
            } catch (URISyntaxException e) {
                // skip it then
            } catch (IllegalArgumentException e) {
                // skip it then
            }
        }
    }
    return files.build();
}

From source file:io.prestosql.sql.planner.SymbolsExtractor.java

public static Set<Symbol> extractUnique(PlanNode node, Lookup lookup) {
    ImmutableSet.Builder<Symbol> uniqueSymbols = ImmutableSet.builder();
    extractExpressions(node, lookup).forEach(expression -> uniqueSymbols.addAll(extractUnique(expression)));

    return uniqueSymbols.build();
}

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://from  w  ww. j  a  v  a2  s  .  com
 * - 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();
}