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

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

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Appends the specified element to the end of this list (optional operation).

Usage

From source file:com.facebook.presto.server.QueryExecutionResource.java

private static List<StageInfo> collectStages(StageInfo stage) {
    ImmutableList.Builder<StageInfo> result = ImmutableList.builder();
    result.add(stage);
    for (StageInfo child : stage.getSubStages()) {
        result.addAll(collectStages(child));
    }/*from  ww  w  .j av  a2 s .c o m*/

    return result.build();
}

From source file:com.android.build.gradle.api.ApkOutput.java

public static ImmutableList<SplitApkOutput> load(File inputFile) throws FileNotFoundException {

    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(SplitApkOutput.class, new SplitApkOutput.JsonDeserializer());
    Gson gson = gsonBuilder.create();//from w  w  w. j  ava2s. c o m

    ImmutableList.Builder<SplitApkOutput> builder = ImmutableList.builder();

    for (SplitApkOutput vo : gson.fromJson(new FileReader(inputFile), SplitApkOutput[].class)) {
        builder.add(vo);
    }
    return builder.build();
}

From source file:com.noodlewiz.xjavab.ext.render.internal.ReplyUnpacker.java

public static QueryFiltersReply unpackQueryFilters(final ByteBuffer __xjb_buf) {
    __xjb_buf.position(4);/*from  w w w  . j  av  a 2s.c om*/
    final long length = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUInt(__xjb_buf);
    __xjb_buf.position(1);
    com.noodlewiz.xjavab.core.internal.Unpacker.unpackPad(__xjb_buf, 1);
    __xjb_buf.position(8);
    final long numAliases = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUInt(__xjb_buf);
    final long numFilters = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUInt(__xjb_buf);
    com.noodlewiz.xjavab.core.internal.Unpacker.unpackPad(__xjb_buf, 16);
    final com.google.common.collect.ImmutableList.Builder<Integer> __xjb_aliasesBuilder = new com.google.common.collect.ImmutableList.Builder<Integer>();
    for (int __xjb_i = 0; (__xjb_i < numAliases); __xjb_i++) {
        __xjb_aliasesBuilder.add(com.noodlewiz.xjavab.core.internal.Unpacker.unpackUShort(__xjb_buf));
    }
    final List<Integer> aliases = __xjb_aliasesBuilder.build();
    final com.google.common.collect.ImmutableList.Builder<Str> __xjb_filtersBuilder = new com.google.common.collect.ImmutableList.Builder<Str>();
    for (int __xjb_i = 0; (__xjb_i < numFilters); __xjb_i++) {
        __xjb_filtersBuilder.add(com.noodlewiz.xjavab.core.xproto.internal.Unpacker.unpackStr(__xjb_buf));
    }
    final List<Str> filters = __xjb_filtersBuilder.build();
    return new QueryFiltersReply(numAliases, numFilters, aliases, filters);
}

From source file:com.noodlewiz.xjavab.ext.randr.internal.Unpacker.java

public static RefreshRates unpackRefreshRates(final ByteBuffer __xjb_buf) {
    final int nRates = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUShort(__xjb_buf);
    final com.google.common.collect.ImmutableList.Builder<Integer> __xjb_ratesBuilder = new com.google.common.collect.ImmutableList.Builder<Integer>();
    for (int __xjb_i = 0; (__xjb_i < nRates); __xjb_i++) {
        __xjb_ratesBuilder.add(com.noodlewiz.xjavab.core.internal.Unpacker.unpackUShort(__xjb_buf));
    }// w w  w . j  ava2s.  com
    final List<Integer> rates = __xjb_ratesBuilder.build();
    return new RefreshRates(nRates, rates);
}

From source file:co.cask.cdap.hive.ExploreUtils.java

/**
 * Builds a class loader with the class path provided.
 *//*w  w  w.j  ava  2  s  . c om*/
public static synchronized ClassLoader getExploreClassloader() {
    if (exploreClassLoader != null) {
        return exploreClassLoader;
    }

    // EXPLORE_CLASSPATH and EXPLORE_CONF_FILES will be defined in startup scripts if Hive is installed.
    String exploreClassPathStr = System.getProperty(Constants.Explore.EXPLORE_CLASSPATH);
    LOG.debug("Explore classpath = {}", exploreClassPathStr);
    if (exploreClassPathStr == null) {
        throw new RuntimeException("System property " + Constants.Explore.EXPLORE_CLASSPATH + " is not set.");
    }

    String exploreConfPathStr = System.getProperty(Constants.Explore.EXPLORE_CONF_FILES);
    LOG.debug("Explore confPath = {}", exploreConfPathStr);
    if (exploreConfPathStr == null) {
        throw new RuntimeException("System property " + Constants.Explore.EXPLORE_CONF_FILES + " is not set.");
    }

    Iterable<File> hiveClassPath = getClassPathJarsFiles(exploreClassPathStr);
    Iterable<File> hiveConfFiles = getClassPathJarsFiles(exploreConfPathStr);
    ImmutableList.Builder<URL> builder = ImmutableList.builder();
    for (File file : Iterables.concat(hiveClassPath, hiveConfFiles)) {
        try {
            if (file.getName().matches(".*\\.xml")) {
                builder.add(file.getParentFile().toURI().toURL());
            } else {
                builder.add(file.toURI().toURL());
            }
        } catch (MalformedURLException e) {
            LOG.error("Jar URL is malformed", e);
            throw Throwables.propagate(e);
        }
    }
    exploreClassLoader = new URLClassLoader(Iterables.toArray(builder.build(), URL.class),
            ClassLoader.getSystemClassLoader());
    return exploreClassLoader;
}

From source file:io.prestosql.type.TypeUtils.java

public static Page getHashPage(Page page, List<? extends Type> types, List<Integer> hashChannels) {
    ImmutableList.Builder<Type> hashTypes = ImmutableList.builder();
    Block[] hashBlocks = new Block[hashChannels.size()];
    int hashBlockIndex = 0;

    for (int channel : hashChannels) {
        hashTypes.add(types.get(channel));
        hashBlocks[hashBlockIndex++] = page.getBlock(channel);
    }//w w  w .ja v a2  s .  co m
    return page.appendColumn(getHashBlock(hashTypes.build(), hashBlocks));
}

From source file:org.lenskit.eval.traintest.metrics.TypedMetricResult.java

/**
 * Get the columns for a typed metric result class.
 * @param type The result class.  If `null`, an empty list of columns will be returned.
 * @param suffix A suffix for column labels; if non-`null`, will be appended to each column label separated with
 *               a period.//from  w w  w. j a  va  2 s  . co m
 * @return The column labels for results of type `type`.
 */
@Nonnull
public static List<String> getColumns(@Nullable Class<? extends TypedMetricResult> type,
        @Nullable final String suffix) {
    if (type == null) {
        return Collections.emptyList();
    }
    List<ColumnDesc> columns = getColumnInfo(type);

    Ordering<ColumnDesc> order = Ordering.natural().onResultOf(new Function<ColumnDesc, Integer>() {
        @Override
        public Integer apply(@Nullable ColumnDesc input) {
            assert input != null;
            int c = input.getAnnotation().order();
            // negative values should sort last
            return c >= 0 ? c : Integer.MAX_VALUE;
        }
    });

    ImmutableList.Builder<String> names = ImmutableList.builder();
    for (ColumnDesc c : order.sortedCopy(columns)) {
        if (suffix == null) {
            names.add(c.getName());
        } else {
            names.add(c.getName() + "." + suffix);
        }
    }

    return names.build();
}

From source file:io.prestosql.sql.analyzer.ExpressionTreeUtils.java

private static List<Node> linearizeNodes(Node node) {
    ImmutableList.Builder<Node> nodes = ImmutableList.builder();
    new DefaultExpressionTraversalVisitor<Node, Void>() {
        @Override/*  w w  w.  j  a va 2s . c o  m*/
        public Node process(Node node, Void context) {
            Node result = super.process(node, context);
            nodes.add(node);
            return result;
        }
    }.process(node, null);
    return nodes.build();
}

From source file:io.prestosql.operator.TopNRowNumberOperator.java

private static List<Type> toTypes(List<? extends Type> sourceTypes, List<Integer> outputChannels,
        boolean generateRowNumber) {
    ImmutableList.Builder<Type> types = ImmutableList.builder();
    for (int channel : outputChannels) {
        types.add(sourceTypes.get(channel));
    }//from   w ww .  j av  a 2  s .c  o  m
    if (generateRowNumber) {
        types.add(BIGINT);
    }
    return types.build();
}

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

public static ImmutableList<Arg> toStringWithMacrosArgs(BuildTarget target, CellPathResolver cellPathResolver,
        ActionGraphBuilder graphBuilder, Iterable<StringWithMacros> flags) {
    ImmutableList.Builder<Arg> args = ImmutableList.builder();
    StringWithMacrosConverter macrosConverter = StringWithMacrosConverter.of(target, cellPathResolver,
            ImmutableList.of(new LocationMacroExpander(), new ExecutableMacroExpander()));
    for (StringWithMacros flag : flags) {
        args.add(macrosConverter.convert(flag, graphBuilder));
    }/*from  ww w  .  j a  va  2s .  com*/
    return args.build();
}