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.go.GoTestDescription.java

@Override
public Iterable<BuildTarget> findDepsForTargetFromConstructorArgs(BuildTarget buildTarget,
        CellPathResolver cellRoots, Arg constructorArg) {

    ImmutableSet.Builder<BuildTarget> targets = ImmutableSet.builder();

    // Add the C/C++ linker parse time deps.
    GoPlatform goPlatform = goBuckConfig.getPlatformFlavorDomain().getValue(buildTarget)
            .orElse(goBuckConfig.getDefaultPlatform());
    Optional<CxxPlatform> cxxPlatform = goPlatform.getCxxPlatform();
    if (cxxPlatform.isPresent()) {
        targets.addAll(CxxPlatforms.getParseTimeDeps(cxxPlatform.get()));
    }//from  w w w . j  a v a2  s.c  o  m

    return targets.build();
}

From source file:org.apache.sentry.provider.file.SimpleFileProviderBackend.java

/**
 * {@inheritDoc}//from  w ww.jav  a2  s . c om
 */
@Override
public ImmutableSet<String> getPrivileges(Set<String> groups, ActiveRoleSet roleSet,
        Authorizable... authorizableHierarchy) {
    if (!initialized) {
        throw new IllegalStateException("Backend has not been properly initialized");
    }
    ImmutableSet.Builder<String> resultBuilder = ImmutableSet.builder();
    for (String groupName : groups) {
        for (Map.Entry<String, Set<String>> row : groupRolePrivilegeTable.row(groupName).entrySet()) {
            if (roleSet.containsRole(row.getKey())) {
                resultBuilder.addAll(row.getValue());
            }
        }
    }
    return resultBuilder.build();
}

From source file:grakn.core.graql.executor.QueryExecutor.java

public Stream<ConceptMap> insert(GraqlInsert query) {
    int createExecSpanId = ServerTracing.startScopedChildSpan("QueryExecutor.insert create executors");

    Collection<Statement> statements = query.statements().stream()
            .flatMap(statement -> statement.innerStatements().stream()).collect(Collectors.toList());

    ImmutableSet.Builder<PropertyExecutor.Writer> executors = ImmutableSet.builder();
    for (Statement statement : statements) {
        for (VarProperty property : statement.properties()) {
            executors.addAll(PropertyExecutor.insertable(statement.var(), property).insertExecutors());
        }//from  w  w w  .  j a  v  a2  s  . c  om
    }

    ServerTracing.closeScopedChildSpan(createExecSpanId);

    int answerStreamSpanId = ServerTracing.startScopedChildSpan("QueryExecutor.insert create answer stream");

    Stream<ConceptMap> answerStream;
    if (query.match() != null) {
        MatchClause match = query.match();
        Set<Variable> matchVars = match.getSelectedNames();
        Set<Variable> insertVars = statements.stream().map(statement -> statement.var())
                .collect(ImmutableSet.toImmutableSet());

        LinkedHashSet<Variable> projectedVars = new LinkedHashSet<>(matchVars);
        projectedVars.retainAll(insertVars);

        Stream<ConceptMap> answers = transaction.stream(match.get(projectedVars), infer);
        answerStream = answers.map(answer -> WriteExecutor.create(transaction, executors.build()).write(answer))
                .collect(toList()).stream();
    } else {
        answerStream = Stream.of(WriteExecutor.create(transaction, executors.build()).write(new ConceptMap()));
    }

    ServerTracing.closeScopedChildSpan(answerStreamSpanId);

    return answerStream;
}

From source file:org.apache.flex.compiler.internal.targets.AppSWFTarget.java

/**
 * Creates a {@link SWFFrameInfo} for the main frame.
 * /* w ww  .  j a  v a2 s  .  c  om*/
 * @return A new {@link SWFFrameInfo}.
 * @throws InterruptedException
 */
private SWFFrameInfo createMainFrameInfo() throws InterruptedException {
    final ImmutableSet.Builder<ICompilationUnit> compilationUnits = ImmutableSet.<ICompilationUnit>builder();

    ICompilationUnit rootCU = getRootClassCompilationUnit();

    compilationUnits.add(rootCU);
    final Iterable<ICompilationUnit> includesCompilationUnits = getIncludesCompilationUnits();
    compilationUnits.addAll(includesCompilationUnits);

    final Iterable<ICompilationUnit> includeLibrariesCompilationUnits = getIncludeLibrariesCompilationUnits();
    compilationUnits.addAll(includeLibrariesCompilationUnits);

    compilationUnits.addAll(additionalRootedCompilationUnits);

    Collection<ICompilerProblem> externallyVisibleDefinitionProblems = rootCU.getFileScopeRequest().get()
            .checkExternallyVisibleDefinitions(targetSettings.getRootClassName());

    final SWFFrameInfo mainFrameInfo = new SWFFrameInfo(compilationUnits.build(),
            externallyVisibleDefinitionProblems);
    return mainFrameInfo;
}

From source file:com.facebook.buck.android.exopackage.ExopackageInstaller.java

public void finishExoFileInstallation(ImmutableSortedSet<Path> presentFiles, ExopackageInfo exoInfo)
        throws Exception {
    ImmutableSet.Builder<Path> wantedPaths = ImmutableSet.builder();
    ImmutableMap.Builder<Path, String> metadata = ImmutableMap.builder();

    if (exoInfo.getDexInfo().isPresent()) {
        DexExoHelper dexExoHelper = new DexExoHelper(pathResolver, projectFilesystem,
                exoInfo.getDexInfo().get());
        wantedPaths.addAll(dexExoHelper.getFilesToInstall().keySet());
        metadata.putAll(dexExoHelper.getMetadataToInstall());
    }//www .j a v a 2  s.  com

    if (exoInfo.getNativeLibsInfo().isPresent()) {
        NativeExoHelper nativeExoHelper = new NativeExoHelper(() -> {
            try {
                return device.getDeviceAbis();
            } catch (Exception e) {
                throw new HumanReadableException("Unable to communicate with device", e);
            }
        }, pathResolver, projectFilesystem, exoInfo.getNativeLibsInfo().get());
        wantedPaths.addAll(nativeExoHelper.getFilesToInstall().keySet());
        metadata.putAll(nativeExoHelper.getMetadataToInstall());
    }

    if (exoInfo.getResourcesInfo().isPresent()) {
        ResourcesExoHelper resourcesExoHelper = new ResourcesExoHelper(pathResolver, projectFilesystem,
                exoInfo.getResourcesInfo().get());
        wantedPaths.addAll(resourcesExoHelper.getFilesToInstall().keySet());
        metadata.putAll(resourcesExoHelper.getMetadataToInstall());
    }

    if (exoInfo.getModuleInfo().isPresent()) {
        ModuleExoHelper moduleExoHelper = new ModuleExoHelper(pathResolver, projectFilesystem,
                exoInfo.getModuleInfo().get());
        wantedPaths.addAll(moduleExoHelper.getFilesToInstall().keySet());
        metadata.putAll(moduleExoHelper.getMetadataToInstall());
    }

    deleteUnwantedFiles(presentFiles, wantedPaths.build());
    installMetadata(metadata.build());
}

From source file:com.netflix.metacat.main.presto.metadata.MetadataManager.java

/**
 * Lists schema names.//from   w  w w. j a  v  a  2s.  c o  m
 * @param session session
 * @param catalogName catalog name
 * @return schema names
 */
public List<String> listSchemaNames(final Session session, final String catalogName) {
    MetadataUtil.checkCatalogName(catalogName);
    final ImmutableSet.Builder<String> schemaNames = ImmutableSet.builder();
    for (ConnectorMetadataEntry entry : allConnectorsFor(catalogName)) {
        schemaNames.addAll(entry.getMetadata().listSchemaNames(session.toConnectorSession(entry.getCatalog())));
    }
    return ImmutableList.copyOf(schemaNames.build());
}

From source file:com.facebook.buck.thrift.ThriftLibraryDescription.java

/**
 * Create the build rules which compile the input thrift sources into their respective
 * language specific sources.//w  w  w  .  j ava  2 s. c  o m
 */
@VisibleForTesting
protected ImmutableMap<String, ThriftCompiler> createThriftCompilerBuildRules(BuildRuleParams params,
        BuildRuleResolver resolver, CompilerType compilerType, ImmutableList<String> flags, String language,
        ImmutableSet<String> options, ImmutableMap<String, SourcePath> srcs,
        ImmutableSortedSet<ThriftLibrary> deps,
        ImmutableMap<String, ImmutableSortedSet<String>> generatedSources) {

    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    Tool compiler = thriftBuckConfig.getCompiler(compilerType, resolver);

    // Build up the include roots to find thrift file deps and also the build rules that
    // generate them.
    ImmutableMap.Builder<Path, SourcePath> includesBuilder = ImmutableMap.builder();
    ImmutableSortedSet.Builder<HeaderSymlinkTree> includeTreeRulesBuilder = ImmutableSortedSet.naturalOrder();
    ImmutableList.Builder<Path> includeRootsBuilder = ImmutableList.builder();
    ImmutableSet.Builder<Path> headerMapsBuilder = ImmutableSet.builder();
    for (ThriftLibrary dep : deps) {
        includesBuilder.putAll(dep.getIncludes());
        includeTreeRulesBuilder.add(dep.getIncludeTreeRule());
        includeRootsBuilder.add(dep.getIncludeTreeRule().getIncludePath());
        headerMapsBuilder.addAll(OptionalCompat.asSet(dep.getIncludeTreeRule().getHeaderMap()));
    }
    ImmutableMap<Path, SourcePath> includes = includesBuilder.build();
    ImmutableSortedSet<HeaderSymlinkTree> includeTreeRules = includeTreeRulesBuilder.build();
    ImmutableList<Path> includeRoots = includeRootsBuilder.build();
    ImmutableSet<Path> headerMaps = headerMapsBuilder.build();

    // For each thrift source, add a thrift compile rule to generate it's sources.
    ImmutableMap.Builder<String, ThriftCompiler> compileRules = ImmutableMap.builder();
    for (ImmutableMap.Entry<String, SourcePath> ent : srcs.entrySet()) {
        String name = ent.getKey();
        SourcePath source = ent.getValue();
        ImmutableSortedSet<String> genSrcs = Preconditions.checkNotNull(generatedSources.get(name));

        BuildTarget target = createThriftCompilerBuildTarget(params.getBuildTarget(), name);
        Path outputDir = getThriftCompilerOutputDir(params.getProjectFilesystem(), params.getBuildTarget(),
                name);

        compileRules.put(name, new ThriftCompiler(
                params.copyWithChanges(target, Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder()
                        .addAll(compiler.getDeps(ruleFinder))
                        .addAll(ruleFinder.filterBuildRuleInputs(ImmutableList.<SourcePath>builder().add(source)
                                .addAll(includes.values()).build()))
                        .addAll(includeTreeRules).build()), Suppliers.ofInstance(ImmutableSortedSet.of())),
                compiler, flags, outputDir, source, language, options, includeRoots, headerMaps, includes,
                genSrcs));
    }

    return compileRules.build();
}

From source file:com.google.javascript.jscomp.newtypes.RawNominalType.java

ImmutableSet<String> getAllPropsOfInterface() {
    Preconditions.checkState(isInterface);
    Preconditions.checkState(this.isRawTypeFinalized);
    if (allProps == null) {
        ImmutableSet.Builder<String> builder = ImmutableSet.builder();
        if (interfaces != null) {
            for (NominalType interf : interfaces) {
                builder.addAll(interf.getAllPropsOfInterface());
            }//w  ww .j  a v a  2 s.  c o m
        }
        allProps = builder.addAll(protoProps.keySet()).build();
    }
    return allProps;
}

From source file:com.facebook.buck.rules.BuildInfoRecorder.java

/**
 * Creates a zip file of the metadata and recorded artifacts and stores it in the artifact cache.
 *//*from  w ww  .  jav a2  s  . c  o m*/
public void performUploadToArtifactCache(ArtifactCache artifactCache, BuckEventBus eventBus) {
    // Skip all of this if caching is disabled. Although artifactCache.store() will be a noop,
    // building up the zip is wasted I/O.
    if (!artifactCache.isStoreSupported()) {
        return;
    }

    ImmutableSet.Builder<Path> pathsToIncludeInZipBuilder = ImmutableSet.<Path>builder()
            .addAll(Iterables.transform(metadataToWrite.keySet(), new Function<String, Path>() {
                @Override
                public Path apply(String key) {
                    return pathToMetadataDirectory.resolve(key);
                }
            })).addAll(pathsToOutputFiles);

    try {
        for (Path outputDirectory : pathsToOutputDirectories) {
            pathsToIncludeInZipBuilder.addAll(getEntries(outputDirectory));
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    ImmutableSet<Path> pathsToIncludeInZip = pathsToIncludeInZipBuilder.build();
    File zip;
    try {
        zip = File.createTempFile(buildTarget.getFullyQualifiedName().replace('/', '_'), ".zip");
        projectFilesystem.createZip(pathsToIncludeInZip, zip);
    } catch (IOException e) {
        eventBus.post(LogEvent.info("Failed to create zip for %s containing:\n%s", buildTarget,
                Joiner.on('\n').join(ImmutableSortedSet.copyOf(pathsToIncludeInZip))));
        e.printStackTrace();
        return;
    }
    artifactCache.store(ruleKey, zip);
    zip.delete();
}

From source file:org.eclipse.tracecompass.ctf.core.trace.CTFTraceReader.java

/**
 * Gets an iterable of the stream input readers, useful for foreaches
 *
 * @return the iterable of the stream input readers
 *///  ww  w  . j av  a 2  s  .  c o  m
public Iterable<IEventDeclaration> getEventDeclarations() {
    ImmutableSet.Builder<IEventDeclaration> builder = new Builder<>();
    for (CTFStreamInputReader sir : fStreamInputReaders) {
        builder.addAll(sir.getEventDeclarations());
    }
    return builder.build();
}