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.android.dalvik.DalvikStatsTool.java

/** CLI wrapper to run against every class in a set of JARs. */
public static void main(String[] args) throws IOException {
    ImmutableSet.Builder<DalvikMemberReference> allFields = ImmutableSet.builder();

    for (String fname : args) {
        try (ZipFile inJar = new ZipFile(fname)) {
            for (ZipEntry entry : Collections.list(inJar.entries())) {
                if (!entry.getName().endsWith(".class")) {
                    continue;
                }//ww  w  .  j  a  v  a2 s. com
                InputStream rawClass = inJar.getInputStream(entry);
                Stats stats = getEstimate(rawClass);
                System.out
                        .println(stats.estimatedLinearAllocSize + "\t" + entry.getName().replace(".class", ""));
                allFields.addAll(stats.fieldReferences);
            }
        }
    }

    // Uncomment to debug fields.
    //    System.out.println();
    //
    //    for (DalvikMemberReference field : allFields.build()) {
    //      System.out.println(field);
    //    }
}

From source file:org.bitcoinj.params.Networks.java

public static void register(Collection<? extends NetworkParameters> networks) {
    ImmutableSet.Builder<NetworkParameters> builder = ImmutableSet.builder();
    builder.addAll(Networks.networks);
    builder.addAll(networks);/*  w ww. j a  v a  2  s.  co m*/
    Networks.networks = builder.build();
}

From source file:com.stackframe.sarariman.Utilities.java

public static <K, V extends Object> Set<K> allKeys(Iterable<Map<K, V>> maps) {
    ImmutableSet.Builder<K> builder = ImmutableSet.<K>builder();
    for (Map<K, V> map : maps) {
        builder.addAll(map.keySet());
    }// w ww  .j av a2 s.c  om

    return builder.build();
}

From source file:org.terasology.util.Varargs.java

/**
 * Combines a single value and array into an immutable set. Iteration of the set maintains the order of the items.
 * This is intended to aid methods using the mandatory-first optional-additional varargs trick.
 *
 * @param first      The first, single value
 * @param additional Any additional values
 * @param <T>        The type of the items
 * @return A set of the combined values//from  w  w w.  j a v  a2 s.c  o  m
 */
@SafeVarargs
public static <T> ImmutableSet<T> combineToSet(T first, T... additional) {
    ImmutableSet.Builder<T> builder = ImmutableSet.builder();
    builder.add(first);
    builder.addAll(Arrays.asList(additional));
    return builder.build();
}

From source file:com.google.template.soy.jssrc.dsl.Call.java

static Call create(CodeChunk.WithValue receiver, ImmutableList<CodeChunk.WithValue> args) {
    ImmutableSet.Builder<CodeChunk> builder = ImmutableSet.builder();
    builder.addAll(receiver.initialStatements());
    for (CodeChunk.WithValue arg : args) {
        builder.addAll(arg.initialStatements());
    }// w w  w.ja va2  s  .  co m
    return new AutoValue_Call(builder.build(), receiver, args);
}

From source file:com.facebook.buck.features.ocaml.OcamlUtil.java

static Iterable<BuildTarget> getParseTimeDeps(OcamlPlatform platform) {
    ImmutableSet.Builder<BuildTarget> deps = ImmutableSet.builder();
    deps.addAll(platform.getCCompiler().getParseTimeDeps());
    deps.addAll(platform.getCxxCompiler().getParseTimeDeps());
    deps.addAll(platform.getCPreprocessor().getParseTimeDeps());
    deps.addAll(CxxPlatforms.getParseTimeDeps(platform.getCxxPlatform()));
    return deps.build();
}

From source file:com.facebook.presto.sql.planner.optimizations.AggregationNodeUtils.java

public static Set<Symbol> extractUnique(AggregationNode.Aggregation aggregation) {
    ImmutableSet.Builder<Symbol> builder = ImmutableSet.builder();
    aggregation.getArguments().forEach(argument -> builder.addAll(SymbolsExtractor.extractAll(argument)));
    aggregation.getFilter().ifPresent(filter -> builder.addAll(SymbolsExtractor.extractAll(filter)));
    aggregation.getOrderBy().ifPresent(orderingScheme -> builder.addAll(orderingScheme.getOrderBy().stream()
            .map(VariableReferenceExpression::getName).map(Symbol::new).collect(toImmutableSet())));
    return builder.build();
}

From source file:com.google.template.soy.jssrc.dsl.ArrayLiteral.java

static ArrayLiteral create(ImmutableList<? extends CodeChunk.WithValue> elements) {
    ImmutableSet.Builder<CodeChunk> builder = ImmutableSet.builder();
    for (CodeChunk.WithValue element : elements) {
        builder.addAll(element.initialStatements());
    }//from w w w. j  a v a 2s.c  om
    return new AutoValue_ArrayLiteral(builder.build(), elements);
}

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

public static ImmutableSet<JavaLibrary> getTransitiveClasspathDeps(JavaLibrary javaLibrary) {
    ImmutableSet.Builder<JavaLibrary> classpathDeps = ImmutableSet.builder();

    classpathDeps.addAll(getClasspathDeps(javaLibrary.getDepsForTransitiveClasspathEntries()));

    // Only add ourselves to the classpath if there's a jar to be built or if we're a maven dep.
    if (javaLibrary.getPathToOutput() != null || javaLibrary.getMavenCoords().isPresent()) {
        classpathDeps.add(javaLibrary);//from  w  w  w.  j av a  2 s . c  o m
    }

    // Or if there are exported dependencies, to be consistent with getTransitiveClasspaths.
    if (javaLibrary instanceof ExportDependencies
            && !((ExportDependencies) javaLibrary).getExportedDeps().isEmpty()) {
        classpathDeps.add(javaLibrary);
    }

    return classpathDeps.build();
}

From source file:com.facebook.presto.sql.planner.optimizations.AggregationNodeUtils.java

public static Set<VariableReferenceExpression> extractUniqueVariables(AggregationNode.Aggregation aggregation,
        TypeProvider types) {//from   w  ww  .  j  a  v  a2 s. com
    ImmutableSet.Builder<VariableReferenceExpression> builder = ImmutableSet.builder();
    aggregation.getArguments()
            .forEach(argument -> builder.addAll(SymbolsExtractor.extractAllVariable(argument, types)));
    aggregation.getFilter()
            .ifPresent(filter -> builder.addAll(SymbolsExtractor.extractAllVariable(filter, types)));
    aggregation.getOrderBy().ifPresent(orderingScheme -> builder.addAll(orderingScheme.getOrderBy()));
    return builder.build();
}