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.rules.coercer.concat.ImmutableListConcatable.java

@Override
public ImmutableList<T> concat(Iterable<ImmutableList<T>> elements) {
    ImmutableList.Builder<T> builder = ImmutableList.builder();
    for (List<T> list : elements) {
        builder.addAll(list);//from  ww  w  . jav a2 s.  co  m
    }
    return builder.build();
}

From source file:be.dnsbelgium.vcard.datatype.AbstractList.java

public AbstractList(List<T> values) {
    if (values == null) {
        this.values = null;
    } else {/* ww  w  .  j a  v  a2  s  .c  o  m*/
        this.values = new ImmutableList.Builder<T>().addAll(values).build();
    }
}

From source file:com.teradata.tpcds.distribution.StringValuesDistribution.java

public static StringValuesDistribution buildStringValuesDistribution(String valuesAndWeightsFilename,
        int numValueFields, int numWeightFields) {
    Iterator<List<String>> iterator = getDistributionIterator(valuesAndWeightsFilename);

    List<ImmutableList.Builder<String>> valuesBuilders = new ArrayList<>(numValueFields);
    for (int i = 0; i < numValueFields; i++) {
        valuesBuilders.add(ImmutableList.<String>builder());
    }/*from   w ww . j a va 2  s .co  m*/

    List<WeightsBuilder> weightsBuilders = new ArrayList<>(numWeightFields);
    for (int i = 0; i < numWeightFields; i++) {
        weightsBuilders.add(new WeightsBuilder());
    }

    while (iterator.hasNext()) {
        List<String> fields = iterator.next();
        checkState(fields.size() == 2, "Expected line to contain 2 parts but it contains %s: %s", fields.size(),
                fields);

        List<String> values = getListFromCommaSeparatedValues(fields.get(0));
        checkState(values.size() == numValueFields,
                "Expected line to contain %s values, but it contained %s, %s", numValueFields, values.size(),
                values);
        for (int i = 0; i < values.size(); i++) {
            valuesBuilders.get(i).add(values.get(i));
        }

        List<String> weights = getListFromCommaSeparatedValues(fields.get(1));
        checkState(weights.size() == numWeightFields,
                "Expected line to contain %s weights, but it contained %s, %s", numWeightFields, weights.size(),
                weights);
        for (int i = 0; i < weights.size(); i++) {
            weightsBuilders.get(i).computeAndAddNextWeight(Integer.parseInt(weights.get(i)));
        }
    }

    ImmutableList.Builder<ImmutableList<String>> valuesListsBuilder = ImmutableList
            .<ImmutableList<String>>builder();
    for (ImmutableList.Builder<String> valuesBuilder : valuesBuilders) {
        valuesListsBuilder.add(valuesBuilder.build());
    }
    ImmutableList<ImmutableList<String>> valuesLists = valuesListsBuilder.build();

    ImmutableList.Builder<ImmutableList<Integer>> weightsListBuilder = ImmutableList
            .<ImmutableList<Integer>>builder();
    for (WeightsBuilder weightsBuilder : weightsBuilders) {
        weightsListBuilder.add(weightsBuilder.build());
    }
    ImmutableList<ImmutableList<Integer>> weightsLists = weightsListBuilder.build();
    return new StringValuesDistribution(valuesLists, weightsLists);
}

From source file:com.google.copybara.config.ConfigValidator.java

public List<Message> validate(Config config, String migrationName) {
    ImmutableList.Builder<Message> messages = ImmutableList.builder();
    if (config.getMigrations().isEmpty()) {
        messages.add(Message.error("At least one migration is required."));
    }//from  w  w  w .j  av a 2  s. co m
    return messages.build();
}

From source file:ec.tss.tsproviders.db.DbUtil.java

@Nonnull
public static <T extends Exception> List<DbSetId> getAllSeries(@Nonnull AllSeriesCursor<T> cursor,
        @Nonnull DbSetId ref) throws T {
    ImmutableList.Builder<DbSetId> result = ImmutableList.builder();
    while (cursor.next()) {
        result.add(ref.child(cursor.dimValues));
    }/*  w  w w.  j a  va2s.c  om*/
    return result.build();
}

From source file:com.google.devtools.build.android.resources.IntArrayFieldInitializer.java

public static FieldInitializer of(String name, String value) {
    Preconditions.checkArgument(value.startsWith("{ "), "Expected list starting with { ");
    Preconditions.checkArgument(value.endsWith(" }"), "Expected list ending with } ");
    // Check for an empty list, which is "{ }".
    if (value.length() < 4) {
        return new IntArrayFieldInitializer(name, ImmutableList.<Integer>of());
    }//from   ww  w. j  av a 2s.c om
    ImmutableList.Builder<Integer> intValues = ImmutableList.builder();
    String trimmedValue = value.substring(2, value.length() - 2);
    Iterable<String> valueStrings = Splitter.on(',').trimResults().split(trimmedValue);
    for (String valueString : valueStrings) {
        intValues.add(Integer.decode(valueString));
    }
    return new IntArrayFieldInitializer(name, intValues.build());
}

From source file:com.spotify.helios.Utils.java

private static <T> T cli(final Class<T> klass, final String masterEndpoint, final List<String> args)
        throws Exception {
    final ImmutableList<String> argList = new ImmutableList.Builder<String>().add("-z").add(masterEndpoint)
            .add("--json").addAll(args).build();

    return Json.read(main(argList).toString(), klass);
}

From source file:com.stackframe.sarariman.OrgChartGlobalAudit.java

public Collection<AuditResult> getResults() {
    ImmutableList.Builder<AuditResult> listBuilder = ImmutableList.<AuditResult>builder();
    Collection<Employee> activeFulltimeEmployees = Collections2
            .filter(sarariman.getDirectory().getByUserName().values(), Utilities.activeFulltime);
    OrganizationHierarchy organizationHierarchy = sarariman.getOrganizationHierarchy();
    Collection<Integer> employeesInOrgChart = employeesInOrgChart(organizationHierarchy.getOrgChart());
    for (Employee employee : activeFulltimeEmployees) {
        if (!employeesInOrgChart.contains(employee.getNumber())) {
            listBuilder.add(new AuditResult(AuditResultType.error,
                    String.format("%s is not in org chart", employee.getDisplayName()), employee.getURL()));
        }/*www .  java2s .c om*/
    }

    return listBuilder.build();
}

From source file:com.google.errorprone.bugpatterns.testdata.BadImportPositiveCases.java

public void variableDeclarations() {
    ImmutableList.Builder<String> qualified;
    ImmutableList.Builder raw;
}

From source file:vazkii.botania.client.integration.jei.petalapothecary.PetalApothecaryRecipeWrapper.java

public PetalApothecaryRecipeWrapper(RecipePetals recipe) {
    ImmutableList.Builder<Object> builder = ImmutableList.builder();
    for (Object o : recipe.getInputs()) {
        if (o instanceof ItemStack) {
            builder.add(o);/*ww w .  j a  v a2  s.com*/
        }
        if (o instanceof String) {
            builder.add(OreDictionary.getOres((String) o));
        }
    }
    input = builder.build();
    output = recipe.getOutput();
}