Example usage for com.google.common.collect ImmutableSortedSet.Builder add

List of usage examples for com.google.common.collect ImmutableSortedSet.Builder add

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Adds the specified element to this set if it is not already present (optional operation).

Usage

From source file:com.facebook.buck.apple.AppleBinaryDescription.java

private <A extends AppleBinaryDescription.Arg> BuildRule createBinary(TargetGraph targetGraph,
        BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {

    if (AppleDescriptions.flavorsDoNotAllowLinkerMapMode(params)) {
        params = params.withoutFlavor(LinkerMapMode.NO_LINKER_MAP.getFlavor());
    }/*from   w w  w .  j a  v a 2s . c  om*/

    Optional<MultiarchFileInfo> fatBinaryInfo = MultiarchFileInfos.create(platformFlavorsToAppleCxxPlatforms,
            params.getBuildTarget());
    if (fatBinaryInfo.isPresent()) {
        if (shouldUseStubBinary(params)) {
            BuildTarget thinTarget = Iterables.getFirst(fatBinaryInfo.get().getThinTargets(), null);
            return requireThinBinary(targetGraph, params.copyWithBuildTarget(thinTarget), resolver, args);
        }

        ImmutableSortedSet.Builder<BuildRule> thinRules = ImmutableSortedSet.naturalOrder();
        for (BuildTarget thinTarget : fatBinaryInfo.get().getThinTargets()) {
            Optional<BuildRule> existingThinRule = resolver.getRuleOptional(thinTarget);
            if (existingThinRule.isPresent()) {
                thinRules.add(existingThinRule.get());
                continue;
            }
            BuildRule thinRule = requireThinBinary(targetGraph, params.copyWithBuildTarget(thinTarget),
                    resolver, args);
            resolver.addToIndex(thinRule);
            thinRules.add(thinRule);
        }
        return MultiarchFileInfos.requireMultiarchRule(params, resolver, fatBinaryInfo.get(),
                thinRules.build());
    } else {
        return requireThinBinary(targetGraph, params, resolver, args);
    }
}

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

/**
 * Trims the set of known flag-value pairs to the given set.
 *
 * <p>Each target which participates in manual trimming will call this method (via
 * ConfigFeatureFlagTaggedTrimmingTransitionFactory) with its set of requested flags. This set
 * typically comes straight from the user via the transitive_configs attribute. For feature
 * flags themselves, this will be a singleton set containing the feature flag's own label.
 *
 * <p>At the top level, or when there is also a transition which calls replaceFlagValues (e.g.,
 * ConfigFeatureFlagValuesTransition, created by ConfigFeatureFlagTransitionFactory and used by
 * android_binary among others), the configuration will start off untrimmed (knownDefaultFlags is
 * null). In this case:/*  w  w w  .  jav a  2s. co m*/
 *
 * <ul>
 *   <li>Any map entries from flagValues whose keys are in requiredFlags will be retained in
 *       flagValues; all other entries of flagValues will be discarded.</li>
 *   <li>All other elements of requiredFlags will be put into knownDefaultFlags.</li>
 *   <li>unknownFlags will always be set to the empty set; its old value will be discarded.</li>
 * </ul>
 *
 * <p>At any place other than the top level and the aforementioned replaceFlagValues transitions,
 * the source configuration is already trimmed (knownDefaultFlags is not null). In this case:
 *
 * <ul>
 *   <li>Any map entries from flagValues which have keys that are in requiredFlags will be
 *       retained in flagValues; all other entries of flagValues will be discarded.</li>
 *   <li>Any elements of knownDefaultFlags which are also in requiredFlags will be retained in
 *       knownDefaultFlags; all other elements of knownDefaultFlags will be discarded.</li>
 *   <li>unknownFlags will be set to contain all other elements of requiredFlags; its old value
 *       will be discarded.</li>
 * </ul>
 *
 * <p>If requiredFlags is empty, then flagValues, knownDefaultFlags, and unknownFlags will all be
 * set to empty values.
 *
 * <p>After this method is called, regardless of circumstances:
 *
 * <ul>
 *   <li>knownDefaultValues will be non-null, and thus isTrimmed will return true, indicating that
 *       the configuration is trimmed.</li>
 *   <li>If unknownFlags is set non-empty, this indicates that the target this configuration is
 *       for has been reached via a path which mistakenly trimmed out one or more of the flags it
 *       needs, and thus there isn't enough information to evaluate it.</li>
 * </ul>
 */
public void trimFlagValues(Set<Label> requiredFlags) {
    ImmutableSortedMap.Builder<Label, String> flagValuesBuilder = ImmutableSortedMap.naturalOrder();
    ImmutableSortedSet.Builder<Label> knownDefaultFlagsBuilder = ImmutableSortedSet.naturalOrder();
    ImmutableSortedSet.Builder<Label> unknownFlagsBuilder = ImmutableSortedSet.naturalOrder();

    for (Label label : requiredFlags) {
        if (this.flagValues.containsKey(label)) {
            flagValuesBuilder.put(label, flagValues.get(label));
        } else if (!this.isTrimmed() || this.knownDefaultFlags.contains(label)) {
            knownDefaultFlagsBuilder.add(label);
        } else {
            unknownFlagsBuilder.add(label);
        }
    }

    this.flagValues = flagValuesBuilder.build();
    this.knownDefaultFlags = knownDefaultFlagsBuilder.build();
    this.unknownFlags = unknownFlagsBuilder.build();
}

From source file:com.ccheptea.auto.value.node.TypeSimplifier.java

/**
 * Returns the set of types to import. We import every type that is neither in java.lang nor in
 * the package containing the AutoValue class, provided that the result refers to the type
 * unambiguously. For example, if there is a property of type java.util.Map.Entry then we will
 * import java.util.Map.Entry and refer to the property as Entry. We could also import just
 * java.util.Map in this case and refer to Map.Entry, but currently we never do that.
 *///  w w w .  ja  va2  s .  co  m
ImmutableSortedSet<String> typesToImport() {
    ImmutableSortedSet.Builder<String> typesToImport = ImmutableSortedSet.naturalOrder();
    for (Map.Entry<String, Spelling> entry : imports.entrySet()) {
        if (entry.getValue().importIt) {
            typesToImport.add(entry.getKey());
        }
    }
    return typesToImport.build();
}

From source file:org.pircbotx.UserChannelDao.java

/**
 * Gets all currently known levels (op/voice/etc) a user holds in the
 * channel. A {@link UserListEvent} for the channel must of been dispatched
 * before this method will return complete results
 *
 * @param channel Known channel//from  w ww.  j a  va  2 s. co m
 * @param user Known user
 * @return An immutable sorted set of UserLevels
 */
@Synchronized("accessLock")
public ImmutableSortedSet<UserLevel> getLevels(@NonNull C channel, @NonNull U user) {
    ImmutableSortedSet.Builder<UserLevel> builder = ImmutableSortedSet.naturalOrder();
    for (Map.Entry<UserLevel, UserChannelMap<U, C>> curEntry : levelsMap.entrySet())
        if (curEntry.getValue().containsEntry(user, channel))
            builder.add(curEntry.getKey());
    return builder.build();
}

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

private ImmutableSortedSet<ThriftLibrary> getTransitiveThriftLibraryDeps(Iterable<ThriftLibrary> inputs) {

    final ImmutableSortedSet.Builder<ThriftLibrary> depsBuilder = ImmutableSortedSet.naturalOrder();

    // Build up a graph of the inputs and their transitive dependencies.
    new AbstractBreadthFirstTraversal<BuildRule>(inputs) {
        @Override//from ww  w.  j av a  2  s .  c o m
        public ImmutableSet<BuildRule> visit(BuildRule rule) {
            ThriftLibrary thriftRule = (ThriftLibrary) rule;
            depsBuilder.add(thriftRule);
            return ImmutableSet.copyOf(thriftRule.getThriftDeps());
        }
    }.start();

    return depsBuilder.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./*from  w  w w  .  ja v a 2s. 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.facebook.buck.jvm.java.AbstractJavacOptions.java

public ImmutableSortedSet<SourcePath> getInputs(SourcePathRuleFinder ruleFinder) {
    ImmutableSortedSet.Builder<SourcePath> builder = ImmutableSortedSet.<SourcePath>naturalOrder()
            .addAll(getAnnotationProcessingParams().getInputs());

    Optional<SourcePath> javacJarPath = getJavacJarPath();
    if (javacJarPath.isPresent()) {
        SourcePath sourcePath = javacJarPath.get();

        // Add the original rule regardless of what happens next.
        builder.add(sourcePath);

        Optional<BuildRule> possibleRule = ruleFinder.getRule(sourcePath);

        if (possibleRule.isPresent()) {
            BuildRule rule = possibleRule.get();

            // And now include any transitive deps that contribute to the classpath.
            if (rule instanceof JavaLibrary) {
                builder.addAll(((JavaLibrary) rule).getDepsForTransitiveClasspathEntries().stream()
                        .map(SourcePaths.getToBuildTargetSourcePath()::apply)
                        .collect(MoreCollectors.toImmutableList()));
            } else {
                builder.add(sourcePath);
            }/* w w w. j a va2s . c om*/
        }
    }

    return builder.build();
}

From source file:com.facebook.buck.cli.MissingSymbolsHandler.java

/**
 * Get a list of missing dependencies from {@link #getNeededDependencies} and print it to the
 * console in a list-of-Python-strings way that's easy to copy and paste.
 *//*from  w w  w .  ja va 2s .  c  o m*/
private void printNeededDependencies(Collection<MissingSymbolEvent> missingSymbolEvents)
        throws InterruptedException {
    ImmutableSetMultimap<BuildTarget, BuildTarget> neededDependencies;
    try {
        neededDependencies = getNeededDependencies(missingSymbolEvents);
    } catch (IOException e) {
        LOG.warn(e, "Could not find missing deps");
        print("Could not find missing deps because of an IOException: " + e.getMessage());
        return;
    }
    ImmutableSortedSet.Builder<String> samePackageDeps = ImmutableSortedSet.naturalOrder();
    ImmutableSortedSet.Builder<String> otherPackageDeps = ImmutableSortedSet.naturalOrder();
    for (BuildTarget target : neededDependencies.keySet()) {
        print(formatTarget(target) + " is missing deps:");
        Set<BuildTarget> sortedDeps = ImmutableSortedSet.copyOf(neededDependencies.get(target));
        for (BuildTarget neededDep : sortedDeps) {
            if (neededDep.getBaseName().equals(target.getBaseName())) {
                samePackageDeps.add(":" + neededDep.getShortName());
            } else {
                otherPackageDeps.add(neededDep.toString());
            }
        }
    }
    String format = "    '%s',";
    for (String dep : samePackageDeps.build()) {
        print(String.format(format, dep));
    }
    for (String dep : otherPackageDeps.build()) {
        print(String.format(format, dep));
    }
}

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

@Override
public NdkLibrary createBuildable(BuildRuleParams params, Arg args) {
    final ImmutableSortedSet.Builder<SourcePath> srcs = ImmutableSortedSet.naturalOrder();

    try {// www .  j av a2s  . co  m
        final Path buildRulePath = Paths.get(params.getBuildTarget().getBasePath());
        final Path rootDirectory = params.getPathAbsolutifier().apply(buildRulePath);
        Files.walkFileTree(rootDirectory, EnumSet.of(FileVisitOption.FOLLOW_LINKS),
                /* maxDepth */ Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
                    @Override
                    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                        if (EXTENSIONS_REGEX.matcher(file.toString()).matches()) {
                            srcs.add(new PathSourcePath(buildRulePath.resolve(rootDirectory.relativize(file))));
                        }

                        return super.visitFile(file, attrs);
                    }
                });
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return new NdkLibrary(params.getBuildTarget(), srcs.build(), args.flags.get(), args.isAsset.or(false),
            ndkVersion);
}

From source file:org.apache.beam.sdk.options.PipelineOptionsFactory.java

@VisibleForTesting
static Set<String> getSupportedRunners() {
    ImmutableSortedSet.Builder<String> supportedRunners = ImmutableSortedSet.naturalOrder();
    for (Class<? extends PipelineRunner<?>> runner : SUPPORTED_PIPELINE_RUNNERS.values()) {
        supportedRunners.add(runner.getSimpleName());
    }// w w  w.  ja v  a 2s  .  c om
    return supportedRunners.build();
}