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.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodecUtil.java

/**
 * Returns a class name generated from the given {@code element}.
 *
 * <p>For {@code Foo.Bar} this is {@code Foo_Bar_suffix}.
 */// w  w  w. j  ava  2s  .co m
static String getGeneratedName(Element element, String suffix) {
    ImmutableList.Builder<String> classNamesBuilder = new ImmutableList.Builder<>();
    classNamesBuilder.add(suffix);
    do {
        classNamesBuilder.add(element.getSimpleName().toString());
        element = element.getEnclosingElement();
    } while (element instanceof TypeElement);
    return classNamesBuilder.build().reverse().stream().collect(Collectors.joining("_"));
}

From source file:com.squareup.wire.schema.Reserved.java

static ImmutableList<Reserved> fromElements(ImmutableList<ReservedElement> reserveds) {
    ImmutableList.Builder<Reserved> builder = ImmutableList.builder();
    for (ReservedElement reserved : reserveds) {
        builder.add(new Reserved(reserved.location(), reserved.documentation(), reserved.values()));
    }//from   ww  w .  j a v  a 2s .  c o  m
    return builder.build();
}

From source file:com.squareup.wire.schema.Reserved.java

static ImmutableList<ReservedElement> toElements(ImmutableList<Reserved> reserveds) {
    ImmutableList.Builder<ReservedElement> builder = ImmutableList.builder();
    for (Reserved reserved : reserveds) {
        builder.add(ReservedElement.create(reserved.location(), reserved.documentation(), reserved.values()));
    }//  w w  w.ja va2s  .  c  om
    return builder.build();
}

From source file:com.google.devtools.build.lib.skyframe.ActionEnvironmentFunction.java

/**
 * Returns a map of environment variable key => values, getting them from Skyframe. Returns null
 * if and only if some dependencies from Skyframe still need to be resolved.
 *//*  www  .jav  a 2 s  .c om*/
public static Map<String, String> getEnvironmentView(Environment env, Iterable<String> keys)
        throws InterruptedException {
    ImmutableList.Builder<SkyKey> skyframeKeysBuilder = ImmutableList.builder();
    for (String key : keys) {
        skyframeKeysBuilder.add(key(key));
    }
    ImmutableList<SkyKey> skyframeKeys = skyframeKeysBuilder.build();
    Map<SkyKey, SkyValue> values = env.getValues(skyframeKeys);
    if (env.valuesMissing()) {
        return null;
    }
    // To return the initial order and support null values, we use a LinkedHashMap.
    LinkedHashMap<String, String> result = new LinkedHashMap<>();
    for (SkyKey key : skyframeKeys) {
        ClientEnvironmentValue value = (ClientEnvironmentValue) values.get(key);
        result.put(key.argument().toString(), value.getValue());
    }
    return Collections.unmodifiableMap(result);
}

From source file:org.apache.beam.runners.spark.SparkTransformOverrides.java

public static List<PTransformOverride> getDefaultOverrides(boolean streaming) {
    ImmutableList.Builder<PTransformOverride> builder = ImmutableList.builder();
    // TODO: [BEAM-5358] Support @RequiresStableInput on Spark runner
    builder.add(
            PTransformOverride.of(PTransformMatchers.requiresStableInputParDoMulti(), UnsupportedOverrideFactory
                    .withMessage("Spark runner currently doesn't support @RequiresStableInput annotation.")));
    if (!streaming) {
        builder.add(PTransformOverride.of(PTransformMatchers.splittableParDo(),
                new SplittableParDo.OverrideFactory()))
                .add(PTransformOverride.of(
                        PTransformMatchers.urnEqualTo(PTransformTranslation.SPLITTABLE_PROCESS_KEYED_URN),
                        new SplittableParDoNaiveBounded.OverrideFactory()));
    }// w w w  .  j  a va2 s . com
    return builder.build();
}

From source file:org.liquigraph.cli.LiquigraphCli.java

private static ClassLoader classloader(String changelog, String dryRunOutputDirectory) {
    ImmutableList.Builder<URL> resources = ImmutableList.builder();
    try {/*from  w  w  w . j  a  v a2  s .  com*/
        resources.add(toUrl(changelog));
        if (dryRunOutputDirectory != null) {
            resources.add(toUrl(dryRunOutputDirectory));
        }
    } catch (MalformedURLException e) {
        throw propagate(e);
    }

    Collection<URL> urls = resources.build();
    return new URLClassLoader(urls.toArray(new URL[urls.size()]));
}

From source file:com.opengamma.strata.calc.runner.function.result.ScenarioResult.java

/**
 * Obtains an instance using a function to create the entries.
 * <p>/*from w w  w .  j a  v  a  2s .co m*/
 * The function is passed the scenario index and returns the value for that index.
 * 
 * @param size  the number of elements
 * @param valueFunction  the function used to obtain each value
 * @return an instance initialized using the function
 * @throws IllegalArgumentException is size is zero or less
 */
public static <T> ScenarioResult<T> of(int size, IntFunction<T> valueFunction) {
    ArgChecker.notNegativeOrZero(size, "size");
    ImmutableList.Builder<T> builder = ImmutableList.builder();
    for (int i = 0; i < size; i++) {
        builder.add(valueFunction.apply(i));
    }
    return ScenarioResult.of(builder.build());
}

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

/**
 * Creates the Multi File Delete constructor that uses objects
 *//*ww  w  . j  a v  a  2 s.c  om*/
protected static RequestConstructor createObjectsConstructor(final ImmutableList<Arguments> constructorArgs,
        final ImmutableList<QueryParam> queryParams, final String requestName, final Ds3DocSpec docSpec) {
    final ImmutableList.Builder<Arguments> builder = ImmutableList.builder();
    builder.addAll(constructorArgs);
    builder.add(new Arguments("List<String>", "Objects"));

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

    return new RequestConstructor(updatedArgs, updatedArgs, queryParams,
            toConstructorDocs(requestName, argNames, docSpec, 1));
}

From source file:com.facebook.buck.rules.args.SanitizedArg.java

public static ImmutableList<Arg> from(Function<String, String> sanitizer, Iterable<String> args) {
    ImmutableList.Builder<Arg> converted = ImmutableList.builder();
    for (String arg : args) {
        converted.add(new SanitizedArg(sanitizer, arg));
    }//from   w w  w.  jav  a  2  s.co  m
    return converted.build();
}

From source file:org.locationtech.geogig.api.RevFeatureBuilder.java

/**
 * Constructs a new {@link RevFeature} from the provided {@link Feature}.
 * /*from   w  w w  .ja  v  a2 s. c  o  m*/
 * @param feature the feature to build from
 * @return the newly constructed RevFeature
 */
public static RevFeature build(Feature feature) {
    if (feature == null) {
        throw new IllegalStateException("No feature set");
    }

    Collection<Property> props = feature.getProperties();

    ImmutableList.Builder<Optional<Object>> valuesBuilder = new ImmutableList.Builder<Optional<Object>>();

    for (Property prop : props) {
        valuesBuilder.add(Optional.fromNullable(prop.getValue()));
    }

    return RevFeatureImpl.build(valuesBuilder.build());
}