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.android.builder.core.VariantType.java

public static ImmutableList<VariantType> getTestingTypes() {
    ImmutableList.Builder<VariantType> result = ImmutableList.builder();
    for (VariantType variantType : values()) {
        if (variantType.isForTesting()) {
            result.add(variantType);//from   w  w  w  .  ja  v  a  2s . c o  m
        }
    }
    return result.build();
}

From source file:io.prometheus.client.metrics.histogram.buckets.Distributions.java

public static List<Float> logarithmicSizedBucketsFor(final float lower, final float upper) {
    final ImmutableList.Builder<Float> builder = ImmutableList.builder();
    final int bucketCount = (int) Math.ceil(Math.log(upper) / Math.log(2));

    for (int i = 0; i < bucketCount; i++) {
        final float j = (float) Math.pow(2, i + 1);
        builder.add(j);//from   w ww .j av a 2  s.co  m
    }

    return builder.build();
}

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

/**
 * Returns a collector which can be used at the end of a stream of {@link FxConvertible}
 * to build a {@link FxConvertibleList}.
 *
 * @return a collector used to create a {@code FxConvertibleList} from a stream of {@code FxConvertible}
 *//* w  w w.j av a 2  s .  co m*/
public static Collector<FxConvertible<?>, ImmutableList.Builder<FxConvertible<?>>, FxConvertibleList> toFxConvertibleList() {

    // edited to compile in Eclipse
    return Collector.of(ImmutableList.Builder<FxConvertible<?>>::new, (bld, v) -> bld.add(v),
            (l, r) -> l.addAll(r.build()), builder -> FxConvertibleList.of(builder.build()));
}

From source file:org.trustedanalytics.cfbroker.store.hdfs.helper.DirHelper.java

public static List<String> dirList(String path) {
    Builder<String> builder = ImmutableList.builder();
    File folder = new File(path);
    File[] files = folder.listFiles();
    if (files == null) {
        throw new NullPointerException();
    }/*ww  w  .j a v  a  2  s .  c  o  m*/
    for (File entry : files) {
        if (entry.isFile()) {
            builder.add("File : " + entry.getName());
        } else if (entry.isDirectory()) {
            builder.add("Directory : " + entry.getName());
        }
    }
    return builder.build();
}

From source file:org.mule.extension.validation.internal.ImmutableMultipleValidationResult.java

/**
 * A {@link Iterable} with all the {@link ValidationResult} that were generated
 * together, both failed and successful alike.
 *
 * @param results the obtained {@link ValidationResult} objects
 * @return a {@link MultipleValidationResult}
 *//*ww  w  .j a v a  2s . c om*/
public static MultipleValidationResult of(Iterable<ValidationResult> results) {
    ImmutableList.Builder<ValidationResult> failedResultsBuilder = ImmutableList.builder();
    StringBuilder message = new StringBuilder();
    boolean error = false;

    for (ValidationResult result : results) {
        if (result.isError()) {
            failedResultsBuilder.add(result);
            if (message.length() > 0) {
                message.append('\n');
            }

            message.append(result.getMessage());
            error = true;
        }
    }

    return new ImmutableMultipleValidationResult(failedResultsBuilder.build(), error, message.toString());
}

From source file:com.android.build.gradle.ndk.internal.NativeCompilerArgsUtil.java

/**
 * Convert compile arguments to the form used in options.txt.
 *///from www  . ja  v a 2 s .c  o  m
@NonNull
public static List<String> transform(@NonNull Iterable<String> args) {
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    for (String arg : args) {
        String str = arg;
        str = str.replace("\\", "\\\\").replace("\"", "\\\"");
        if (WHITESPACE.matcher(str).find()) {
            str = '\"' + str + '\"';
        }
        builder.add(str);
    }
    return builder.build();
}

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

public static ImmutableList<SkyKey> keys(Iterable<ConfiguredTargetKey> lacs) {
    ImmutableList.Builder<SkyKey> keys = ImmutableList.builder();
    for (ConfiguredTargetKey lac : lacs) {
        keys.add(key(lac));/*from   w  w w .  j a v a2  s .co  m*/
    }
    return keys.build();
}

From source file:dagger.internal.codegen.MethodSignature.java

static MethodSignature fromExecutableType(String methodName, ExecutableType methodType) {
    checkNotNull(methodType);/*  w  w  w .  j  a v  a  2s  .c o  m*/
    ImmutableList.Builder<Equivalence.Wrapper<TypeMirror>> parameters = ImmutableList.builder();
    ImmutableList.Builder<Equivalence.Wrapper<TypeMirror>> thrownTypes = ImmutableList.builder();
    for (TypeMirror parameter : methodType.getParameterTypes()) {
        parameters.add(MoreTypes.equivalence().wrap(parameter));
    }
    for (TypeMirror thrownType : methodType.getThrownTypes()) {
        thrownTypes.add(MoreTypes.equivalence().wrap(thrownType));
    }
    return new AutoValue_MethodSignature(methodName, parameters.build(), thrownTypes.build());
}

From source file:com.facebook.buck.cxx.toolchain.elf.ElfVerDef.java

public static ElfVerDef parse(ElfHeader.EIClass eiClass, ByteBuffer buffer) {
    ImmutableList.Builder<Pair<Verdef, ImmutableList<Verdaux>>> entries = ImmutableList.builder();
    int vdPos = buffer.position();
    while (buffer.hasRemaining()) {
        buffer.position(vdPos);/*from  ww w.  j ava 2  s.co m*/
        Verdef verdef = Verdef.parse(eiClass, buffer);
        int vdaPos = vdPos + (int) verdef.vd_aux;
        ImmutableList.Builder<Verdaux> verdauxEntries = ImmutableList.builder();
        for (int j = 0; j < verdef.vd_cnt; j++) {
            buffer.position(vdaPos);
            Verdaux verdaux = Verdaux.parse(eiClass, buffer);
            verdauxEntries.add(verdaux);
            vdaPos += (int) verdaux.vda_next;
        }
        entries.add(new Pair<>(verdef, verdauxEntries.build()));
        if (verdef.vd_next == 0) {
            break;
        }
        vdPos += verdef.vd_next;
    }
    return new ElfVerDef(entries.build());
}

From source file:be.fror.common.function.MoreCollectors.java

/**
 * Returns a <tt>Collector</tt> that accumulates the input elements into a new
 * <tt>ImmutableList</tt>. The returned <tt>ImmutableList</tt> is guaranteed to be immutable,
 * serializable and thread-safe.//from w  w  w  .j a v  a2 s.c o m
 *
 * @param <T> the type of the input elements
 * @return a Collector which collects all the input elements into a ImmutableList, in encounter
 * order
 */
public static <T> Collector<T, ImmutableList.Builder<T>, ImmutableList<T>> toImmutableList() {
    return Collector.of(ImmutableList.Builder::new, ImmutableList.Builder::add, (l, r) -> l.addAll(r.build()),
            ImmutableList.Builder<T>::build);
}