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:de.flapdoodle.guava.Merger.java

public static <T> ImmutableList<T> remove(Iterable<? extends T> src, Predicate<? super T> matcher,
        Function<T, Optional<T>> transformation) {
    ImmutableList.Builder<T> builder = ImmutableList.builder();
    for (T s : src) {
        if (matcher.apply(s)) {
            builder.addAll(transformation.apply(s).asSet());
        } else {/*w w  w .ja v  a2  s  .  c  om*/
            builder.add(s);
        }
    }
    return builder.build();
}

From source file:io.github.karols.hocr4j.utils.CollectionUtils.java

/**
 * Creates a new immutable list with an element added to the end.
 * @param list original list//w  ww  .j  a  v a  2 s  .c  o  m
 * @param elem element to add
 * @param <T> element type
 * @return list with added element
 */
@Nonnull
public static <T> ImmutableList<T> pushBack(@Nonnull Iterable<T> list, T elem) {
    ImmutableList.Builder<T> b = ImmutableList.builder();
    b.addAll(list);
    b.add(elem);
    return b.build();
}

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

/**
 * Creates the create object request constructor that has the required
 * parameters Stream/*from www  .  j ava  2 s.c  o m*/
 */
protected static RequestConstructor getInputStreamConstructor(final ImmutableList<Arguments> constructorArgs,
        final ImmutableList<Arguments> optionalArgs, final ImmutableList<QueryParam> queryParams,
        final String requestName, final Ds3DocSpec docSpec) {
    final ImmutableList.Builder<Arguments> builder = ImmutableList.builder();
    builder.addAll(constructorArgs);
    builder.addAll(optionalArgs);
    return CommonRequestGeneratorUtils.createInputStreamConstructor(builder.build(), queryParams, requestName,
            docSpec);
}

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

/**
 * Creates the create object request constructor that has the required
 * parameters Channel/*from  w w  w . j  a  va 2 s  .  c  o  m*/
 */
protected static RequestConstructor getChannelConstructor(final ImmutableList<Arguments> constructorArgs,
        final ImmutableList<Arguments> optionalArgs, final ImmutableList<QueryParam> queryParams,
        final String requestName, final Ds3DocSpec docSpec) {
    final ImmutableList.Builder<Arguments> builder = ImmutableList.builder();
    builder.addAll(constructorArgs);
    builder.addAll(optionalArgs);
    return CommonRequestGeneratorUtils.createChannelConstructor(builder.build(), queryParams, requestName,
            docSpec);
}

From source file:com.google.template.soy.jssrc.dsl.ObjectLiteral.java

static ObjectLiteral create(ImmutableList<? extends Expression> keys,
        ImmutableList<? extends Expression> values) {
    Preconditions.checkArgument(keys.size() == values.size(), "Mismatch between keys and values.");
    ImmutableList.Builder<Statement> initialStatements = ImmutableList.builder();
    for (Expression key : keys) {
        initialStatements.addAll(key.initialStatements());
    }/*w  w  w .ja v a  2 s.  c  om*/
    for (Expression value : values) {
        initialStatements.addAll(value.initialStatements());
    }
    return new AutoValue_ObjectLiteral(initialStatements.build(), keys, values);
}

From source file:com.spectralogic.ds3autogen.java.utils.CommonRequestGeneratorUtils.java

/**
 * Creates a constructor with the provided parameters in addition to
 * adding the required parameter Stream for parsing a request payload.
 *///ww  w  . ja  v  a2 s .com
public static RequestConstructor createInputStreamConstructor(final ImmutableList<Arguments> parameters,
        final ImmutableList<QueryParam> queryParams, final String requestName, final Ds3DocSpec docSpec) {
    final ImmutableList.Builder<Arguments> builder = ImmutableList.builder();
    if (hasContent(parameters)) {
        builder.addAll(parameters);
    }
    builder.add(new Arguments("InputStream", "Stream"));

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

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

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

/**
 * Creates the create deprecated object request constructor that
 * uses the Channel parameter/* www  . jav  a  2 s . com*/
 */
protected static RequestConstructor createDeprecatedConstructor(final ImmutableList<Arguments> constructorArgs,
        final String requestName, final Ds3DocSpec docSpec) {
    final ImmutableList.Builder<Arguments> builder = ImmutableList.builder();
    builder.addAll(constructorArgs);
    builder.add(new Arguments("SeekableByteChannel", "Channel"));

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

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

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

From source file:ru.adios.budgeter.util.Immutables.java

@SuppressWarnings("unchecked")
public static <T> Collector<T, ImmutableList.Builder<T>, ImmutableList<T>> getListCollector() {
    return Collectors.of((Supplier<ImmutableList.Builder<T>>) LIST_BUILDER_SUPPLIER,
            new BiConsumer<ImmutableList.Builder<T>, T>() {
                @Override// ww w.  j  a  va  2  s . c o  m
                public void accept(ImmutableList.Builder<T> b, T t) {
                    b.add(t);
                }
            }, new BinaryOperator<ImmutableList.Builder<T>>() {
                @Override
                public ImmutableList.Builder<T> apply(ImmutableList.Builder<T> builder1,
                        ImmutableList.Builder<T> builder2) {
                    return builder1.addAll(builder2.build());
                }
            }, new Function<ImmutableList.Builder<T>, ImmutableList<T>>() {
                @Override
                public ImmutableList<T> apply(ImmutableList.Builder<T> builder) {
                    return builder.build();
                }
            });
}

From source file:org.waveprotocol.box.common.DeltaSequence.java

/** Creates a delta sequence by concatenating contiguous sequences. */
public static DeltaSequence join(DeltaSequence first, DeltaSequence... rest) {
    ImmutableList.Builder<TransformedWaveletDelta> builder = ImmutableList.builder();
    builder.addAll(first);
    long expectedBeginVersion = first.getEndVersion().getVersion();
    for (DeltaSequence s : rest) {
        Preconditions.checkArgument(s.getStartVersion() == expectedBeginVersion,
                "Sequences are not contiguous, expected start version %s for sequence %s", expectedBeginVersion,
                s);//from w w  w  .j a  va 2 s  . c  om
        builder.addAll(s);
        expectedBeginVersion = s.getEndVersion().getVersion();
    }
    return new DeltaSequence(builder.build(), false);
}

From source file:org.eigenbase.rex.RexPermuteInputsShuttle.java

private static ImmutableList<RelDataTypeField> fields(RelNode[] inputs) {
    final ImmutableList.Builder<RelDataTypeField> fields = ImmutableList.builder();
    for (RelNode input : inputs) {
        fields.addAll(input.getRowType().getFieldList());
    }/*from   w  w  w.  j av  a 2  s.c  o m*/
    return fields.build();
}