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

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

Introduction

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

Prototype

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

Source Link

Document

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).

Usage

From source file:com.facebook.buck.config.Configs.java

/**
 * Generates a Buck config by merging configs from specified locations on disk.
 *
 * In order:// w  w w  . ja v  a  2s  .  co  m
 *
 * <ol>
 *   <li>{@code /etc/buckconfig}</li>
 *   <li>Files (in lexicographical order) in {@code /etc/buckconfig.d}</li>
 *   <li>{@code <HOME>/.buckconfig}</li>
 *   <li>Files (in lexicographical order) in {@code <HOME>/buckconfig.d}</li>
 *   <li>{@code <PROJECT ROOT>/.buckconfig}</li>
 *   <li>{@code <PROJECT ROOT>/.buckconfig.local}</li>
 *   <li>Any overrides (usually from the command line)</li>
 * </ol>
 *
 * @param root Project root.
 * @param configOverrides Config overrides to merge in after the other sources.
 * @return the resulting {@code Config}.
 * @throws IOException on any exceptions during the underlying filesystem operations.
 */
public static Config createDefaultConfig(Path root, RawConfig configOverrides) throws IOException {
    LOG.debug("Loading configuration for %s", root);
    ImmutableList.Builder<Path> configFileBuilder = ImmutableList.builder();

    configFileBuilder.addAll(listFiles(GLOBAL_BUCK_CONFIG_DIRECTORY_PATH));
    if (Files.isRegularFile(GLOBAL_BUCK_CONFIG_FILE_PATH)) {
        configFileBuilder.add(GLOBAL_BUCK_CONFIG_FILE_PATH);
    }

    Path homeDirectory = Paths.get(System.getProperty("user.home"));
    Path userConfigDir = homeDirectory.resolve(DEFAULT_BUCK_CONFIG_DIRECTORY_NAME);
    configFileBuilder.addAll(listFiles(userConfigDir));
    Path userConfigFile = homeDirectory.resolve(DEFAULT_BUCK_CONFIG_FILE_NAME);
    if (Files.isRegularFile(userConfigFile)) {
        configFileBuilder.add(userConfigFile);
    }

    Path configFile = root.resolve(DEFAULT_BUCK_CONFIG_FILE_NAME);
    if (Files.isRegularFile(configFile)) {
        configFileBuilder.add(configFile);
    }
    Path overrideConfigFile = root.resolve(DEFAULT_BUCK_CONFIG_OVERRIDE_FILE_NAME);
    if (Files.isRegularFile(overrideConfigFile)) {
        configFileBuilder.add(overrideConfigFile);
    }

    ImmutableList<Path> configFiles = configFileBuilder.build();

    RawConfig.Builder builder = RawConfig.builder();
    for (Path file : configFiles) {
        try (Reader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
            ImmutableMap<String, ImmutableMap<String, String>> parsedConfiguration = Inis.read(reader);
            LOG.debug("Loaded a configuration file %s: %s", file, parsedConfiguration);
            builder.putAll(parsedConfiguration);
        }
    }
    LOG.debug("Adding configuration overrides %s", configOverrides);
    builder.putAll(configOverrides);
    return new Config(builder.build());
}

From source file:com.spectralogic.ds3autogen.net.utils.GeneratorUtils.java

/**
 * Retrieves a list of arguments from the Ds3Request, including converting the required
 * parameters to arguments, and retrieving the arguments from the request header info
 *///from   www .j a v  a2s.  c  o  m
public static ImmutableList<Arguments> getRequiredArgs(final Ds3Request ds3Request) {
    final ImmutableList.Builder<Arguments> requiredArgs = ImmutableList.builder();
    requiredArgs.addAll(RequestConverterUtil.getRequiredArgsFromRequestHeader(ds3Request));
    requiredArgs.addAll(getArgsFromParamList(ds3Request.getRequiredQueryParams()));
    if (ds3Request.includeIdInPath() && isResourceNotification(ds3Request.getResource())) {
        requiredArgs.add(new Arguments("Guid", "NotificationId"));
    }
    return requiredArgs.build();
}

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

private static SortExpressionContext merge(SortExpressionContext left, SortExpressionContext right) {
    checkArgument(left.getSortExpression().equals(right.getSortExpression()));
    ImmutableList.Builder<Expression> searchExpressions = ImmutableList.builder();
    searchExpressions.addAll(left.getSearchExpressions());
    searchExpressions.addAll(right.getSearchExpressions());
    return new SortExpressionContext(left.getSortExpression(), searchExpressions.build());
}

From source file:com.facebook.buck.util.config.Configs.java

/**
 * Gets all configuration files that should be used for parsing the project configuration
 *
 * @param root The root of the project to search
 * @return Files that exist that conform to buck's configuration file precedence. Settings from
 *     files at the end of this list should override ones that come before.
 *///from   ww w . jav  a2  s . c  o m
public static ImmutableList<Path> getDefaultConfigurationFiles(Path root) throws IOException {
    ImmutableList.Builder<Path> configFileBuilder = ImmutableList.builder();

    configFileBuilder.addAll(listFiles(GLOBAL_BUCK_CONFIG_DIRECTORY_PATH));
    if (Files.isRegularFile(GLOBAL_BUCK_CONFIG_FILE_PATH)) {
        configFileBuilder.add(GLOBAL_BUCK_CONFIG_FILE_PATH);
    }

    Path homeDirectory = Paths.get(System.getProperty("user.home"));
    Path userConfigDir = homeDirectory.resolve(DEFAULT_BUCK_CONFIG_DIRECTORY_NAME);
    configFileBuilder.addAll(listFiles(userConfigDir));

    Path projectConfigDir = root.resolve(DEFAULT_BUCK_CONFIG_DIRECTORY_NAME);
    configFileBuilder.addAll(listFiles(projectConfigDir));

    Path userConfigFile = homeDirectory.resolve(DEFAULT_BUCK_CONFIG_FILE_NAME);
    if (Files.isRegularFile(userConfigFile)) {
        configFileBuilder.add(userConfigFile);
    }

    Path configFile = getMainConfigurationFile(root);
    if (Files.isRegularFile(configFile)) {
        configFileBuilder.add(configFile);
    }
    Path overrideConfigFile = root.resolve(DEFAULT_BUCK_CONFIG_OVERRIDE_FILE_NAME);
    if (Files.isRegularFile(overrideConfigFile)) {
        configFileBuilder.add(overrideConfigFile);
    }

    return configFileBuilder.build();
}

From source file:com.spectralogic.ds3autogen.java.generators.requestmodels.GetObjectRequestGenerator.java

/**
 * Creates the depreciated constructor for the get object request
 *///w  w  w.ja  v a2s.c  om
protected static RequestConstructor createDeprecatedConstructor(final ImmutableList<Arguments> constructorArgs,
        final ImmutableList<QueryParam> queryParams, final String requestName, final Ds3DocSpec docSpec) {
    final ImmutableList.Builder<Arguments> constructorArgBuilder = ImmutableList.builder();
    constructorArgBuilder.addAll(constructorArgs);
    constructorArgBuilder.add(new Arguments("WritableByteChannel", "Channel"));

    final ImmutableList<Arguments> updatedConstructorArgs = constructorArgBuilder.build();
    final ImmutableList<String> argNames = updatedConstructorArgs.stream().map(Arguments::getName)
            .collect(GuavaCollectors.immutableList());

    return new RequestConstructor(true, ImmutableList.of(), updatedConstructorArgs, updatedConstructorArgs,
            queryParams, toConstructorDocs(requestName, argNames, docSpec, 1));
}

From source file:com.spotify.heroic.aggregation.Chain.java

private static List<Aggregation> flattenChain(final List<Aggregation> chain) {
    final ImmutableList.Builder<Aggregation> child = ImmutableList.builder();

    for (final Aggregation a : chain) {
        if (a instanceof Chain) {
            child.addAll(flattenChain(Chain.class.cast(a).getChain()));
        } else {/*from  w w  w.j a va  2s  .  c om*/
            child.add(a);
        }
    }

    return child.build();
}

From source file:com.spectralogic.ds3autogen.java.generators.requestmodels.GetObjectRequestGenerator.java

/**
 * Creates the constructor for the get object request that uses WritableByteChannel
 *//*from ww w  .j  ava2s . c  o m*/
protected static RequestConstructor createChannelConstructor(final ImmutableList<Arguments> constructorArgs,
        final ImmutableList<Arguments> optionalArgs, final ImmutableList<QueryParam> queryParams,
        final String requestName, final Ds3DocSpec docSpec) {
    final ImmutableList.Builder<Arguments> constructorArgBuilder = ImmutableList.builder();
    constructorArgBuilder.addAll(constructorArgs);
    constructorArgBuilder.addAll(optionalArgs);
    constructorArgBuilder.add(new Arguments("WritableByteChannel", "Channel"));

    final ImmutableList.Builder<QueryParam> queryParamsBuilder = ImmutableList.builder();
    queryParamsBuilder.addAll(queryParams);
    queryParamsBuilder.addAll(argsToQueryParams(optionalArgs));

    final ImmutableList<Arguments> updatedConstructorArgs = constructorArgBuilder.build();

    final ImmutableList<String> argNames = updatedConstructorArgs.stream().map(Arguments::getName)
            .collect(GuavaCollectors.immutableList());

    return new RequestConstructor(updatedConstructorArgs, updatedConstructorArgs, queryParamsBuilder.build(),
            toConstructorDocs(requestName, argNames, docSpec, 1));
}

From source file:com.spectralogic.ds3autogen.python.generators.request.BaseRequestGenerator.java

/**
 * Gets the arguments that are assigned within the constructor. This includes arguments
 * defined in the request header, and NotificationId when appropriate
 */// www  .  j  a v a 2  s .co  m
protected static ImmutableList<Arguments> getAssignmentArguments(final Ds3Request ds3Request) {
    final ImmutableList.Builder<Arguments> builder = ImmutableList.builder();
    builder.addAll(getRequiredArgsFromRequestHeader(ds3Request));
    if (ds3Request.includeIdInPath() && isResourceNotification(ds3Request.getResource())) {
        builder.add(new Arguments("UUID", "NotificationId"));
    }
    return builder.build();
}

From source file:com.spectralogic.ds3autogen.java.generators.requestmodels.GetObjectRequestGenerator.java

/**
 * Creates the constructor for the get object request that uses OutputStream
 *///from   w  ww  .  ja  v  a 2 s.co  m
protected static RequestConstructor createOutputStreamConstructor(
        final ImmutableList<Arguments> constructorArgs, final ImmutableList<Arguments> optionalArgs,
        final ImmutableList<QueryParam> queryParams, final String requestName, final Ds3DocSpec docSpec) {
    final ImmutableList.Builder<Arguments> constructorArgBuilder = ImmutableList.builder();
    constructorArgBuilder.addAll(constructorArgs);
    constructorArgBuilder.addAll(optionalArgs);
    constructorArgBuilder.add(new Arguments("OutputStream", "Stream"));

    final ImmutableList.Builder<QueryParam> queryParamsBuilder = ImmutableList.builder();
    queryParamsBuilder.addAll(queryParams);
    queryParamsBuilder.addAll(argsToQueryParams(optionalArgs));

    final ImmutableList.Builder<Arguments> assignmentsBuilder = ImmutableList.builder();
    assignmentsBuilder.addAll(constructorArgs);
    assignmentsBuilder.addAll(optionalArgs);

    final ImmutableList<Arguments> updatedConstructorArgs = constructorArgBuilder.build();

    final ImmutableList<String> argNames = updatedConstructorArgs.stream().map(Arguments::getName)
            .collect(GuavaCollectors.immutableList());

    final ImmutableList<String> additionalLines = ImmutableList
            .of("this.channel = Channels.newChannel(stream);");

    return new RequestConstructor(false, additionalLines, updatedConstructorArgs, assignmentsBuilder.build(),
            queryParamsBuilder.build(), toConstructorDocs(requestName, argNames, docSpec, 1));
}

From source file:org.prebake.html.InlineText.java

static TextChunk make(List<TextChunk> chunks) {
    if (chunks.isEmpty()) {
        return new SimpleTextChunk("");
    }/*from  w  w w . j a v a 2 s .c  o  m*/
    if (chunks.size() == 1 && !chunks.get(0).breaks()) {
        return chunks.get(0);
    }
    ImmutableList.Builder<TextChunk> parts = ImmutableList.builder();
    for (TextChunk c : chunks) {
        if (c instanceof InlineText) {
            parts.addAll(((InlineText) c).parts);
        } else {
            parts.add(c);
        }
    }
    return new InlineText(parts.build());
}