Example usage for com.google.common.collect ImmutableList builder

List of usage examples for com.google.common.collect ImmutableList builder

Introduction

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

Prototype

public static <E> Builder<E> builder() 

Source Link

Usage

From source file:com.facebook.buck.cxx.elf.ElfVerNeed.java

public static ElfVerNeed parse(ElfHeader.EIClass eiClass, ByteBuffer buffer) {
    ImmutableList.Builder<Pair<Verneed, ImmutableList<Vernaux>>> entries = ImmutableList.builder();
    int vnPos = buffer.position();
    while (true) {
        buffer.position(vnPos);//from  w ww .jav a 2s .com
        Verneed verneed = Verneed.parse(eiClass, buffer);
        int vnaPos = vnPos + (int) verneed.vn_aux;
        ImmutableList.Builder<Vernaux> vernauxEntries = ImmutableList.builder();
        for (int j = 0; j < verneed.vn_cnt; j++) {
            buffer.position(vnaPos);
            Vernaux vernaux = Vernaux.parse(eiClass, buffer);
            vernauxEntries.add(vernaux);
            vnaPos += (int) vernaux.vna_next;
        }
        entries.add(new Pair<>(verneed, vernauxEntries.build()));
        if (verneed.vn_next == 0) {
            break;
        }
        vnPos += verneed.vn_next;
    }
    return new ElfVerNeed(entries.build());
}

From source file:org.basepom.mojo.propertyhelper.UuidField.java

public static List<UuidField> createUuids(final ValueCache valueCache, final UuidDefinition[] uuidDefinitions)
        throws IOException {
    checkNotNull(valueCache, "valueCache is null");
    checkNotNull(uuidDefinitions, "uuidDefinitions is null");

    final ImmutableList.Builder<UuidField> result = ImmutableList.builder();

    for (UuidDefinition uuidDefinition : uuidDefinitions) {
        uuidDefinition.check();/*from w  w w  . j  a  va2 s.  co  m*/
        final ValueProvider uuidValue = valueCache.getValueProvider(uuidDefinition);
        final UuidField uuidField = new UuidField(uuidDefinition, uuidValue);
        result.add(uuidField);
    }

    return result.build();
}

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

public static ImmutableList<StringWithMacrosArg> toStringWithMacrosArgs(BuildTarget target,
        CellPathResolver cellPathResolver, BuildRuleResolver resolver, Iterable<StringWithMacros> flags) {
    ImmutableList.Builder<StringWithMacrosArg> args = ImmutableList.builder();
    for (StringWithMacros flag : flags) {
        args.add(StringWithMacrosArg.of(flag,
                ImmutableList.of(new LocationMacroExpander(), new ExecutableMacroExpander()), target,
                cellPathResolver, resolver));
    }/*from   w w  w . ja  v  a  2s.  c  o  m*/
    return args.build();
}

From source file:com.facebook.presto.sql.analyzer.LambdaReferenceExtractor.java

public static List<Expression> getReferencesToLambdaArgument(Node node, Analysis analysis) {
    ImmutableList.Builder<Expression> builder = ImmutableList.builder();
    new Visitor(analysis).process(node, builder);
    return builder.build();
}

From source file:com.google.template.soy.exprtree.ExprRootNode.java

public static List<ExprNode> unwrap(Iterable<ExprRootNode> exprs) {
    ImmutableList.Builder<ExprNode> builder = ImmutableList.builder();
    for (ExprRootNode expr : exprs) {
        builder.add(expr.getRoot());/*from  www . jav  a2 s.com*/
    }
    return builder.build();
}

From source file:com.facebook.buck.rules.macros.StringWithMacrosUtils.java

/** @return a {@link StringWithMacros} object built with the given format strings and macros. */
public static StringWithMacros format(String format, MacroContainer... macros) {
    ImmutableList.Builder<Either<String, MacroContainer>> partsBuilder = ImmutableList.builder();

    List<String> stringParts = Splitter.on("%s").splitToList(format);
    Preconditions.checkState(stringParts.size() == macros.length + 1);

    if (!stringParts.get(0).isEmpty()) {
        partsBuilder.add(Either.ofLeft(stringParts.get(0)));
    }/*from w  w w  .  ja  va 2 s.  c o  m*/

    for (int i = 0; i < macros.length; i++) {
        partsBuilder.add(Either.ofRight(macros[i]));
        if (!stringParts.get(i + 1).isEmpty()) {
            partsBuilder.add(Either.ofLeft(stringParts.get(i + 1)));
        }
    }

    return StringWithMacros.of(partsBuilder.build());
}

From source file:com.tibco.businessworks6.sonar.plugin.CommonExtensions.java

@SuppressWarnings("rawtypes")
public static List getExtensions() {
    ImmutableList.Builder<Object> builder = ImmutableList.builder();
    builder.add(BusinessWorksMetrics.class);
    builder.add(BusinessWorksMetricsWidget.class);
    //builder.add(BusinessWorksProcessColorizerFormat.class);
    return builder.build();
}

From source file:org.kmworks.util.cp.CodepointSetUtil.java

public static List<Integer> codepointsFrom(CharSequence s) {
    ImmutableList.Builder<Integer> builder = new ImmutableList.Builder<>();
    int i = 0;/* w  w  w  .  j a  va 2s. co  m*/
    while (i < s.length()) {
        builder.add((int) s.charAt(i));
        i += Character.charCount(i);
    }
    return builder.build();
}

From source file:com.bouncestorage.chaoshttpproxy.ChaosConfig.java

private static List<Failure> loadFailures(Properties properties) {
    ImmutableList.Builder<Failure> failures = ImmutableList.builder();
    for (String propertyName : properties.stringPropertyNames()) {
        Failure failure = Failure.fromPropertyName(propertyName);
        int occurrences = Integer.parseInt(properties.getProperty(propertyName));
        for (int i = 0; i < occurrences; ++i) {
            failures.add(failure);/*from  w  w  w .  j  av  a  2s .  c o  m*/
        }
    }
    return failures.build();
}

From source file:com.facebook.presto.cost.StatsCalculatorModule.java

@Provides
@Singleton/*from  w ww  . ja v  a2  s.c om*/
public static StatsCalculator createNewStatsCalculator(Metadata metadata) {
    StatsNormalizer normalizer = new StatsNormalizer();
    ScalarStatsCalculator scalarStatsCalculator = new ScalarStatsCalculator(metadata);
    FilterStatsCalculator filterStatsCalculator = new FilterStatsCalculator(metadata, scalarStatsCalculator,
            normalizer);

    ImmutableList.Builder<ComposableStatsCalculator.Rule<?>> rules = ImmutableList.builder();
    rules.add(new OutputStatsRule());
    rules.add(new TableScanStatsRule(metadata, normalizer));
    rules.add(new SimpleFilterProjectSemiJoinStatsRule(normalizer, filterStatsCalculator)); // this must be before FilterStatsRule
    rules.add(new FilterStatsRule(normalizer, filterStatsCalculator));
    rules.add(new ValuesStatsRule(metadata));
    rules.add(new LimitStatsRule(normalizer));
    rules.add(new EnforceSingleRowStatsRule(normalizer));
    rules.add(new ProjectStatsRule(scalarStatsCalculator, normalizer));
    rules.add(new ExchangeStatsRule(normalizer));
    rules.add(new JoinStatsRule(filterStatsCalculator, normalizer));
    rules.add(new SpatialJoinStatsRule(filterStatsCalculator, normalizer));
    rules.add(new AggregationStatsRule(normalizer));
    rules.add(new UnionStatsRule(normalizer));
    rules.add(new AssignUniqueIdStatsRule());
    rules.add(new SemiJoinStatsRule());
    rules.add(new RowNumberStatsRule(normalizer));

    return new ComposableStatsCalculator(rules.build());
}