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:org.apache.drill.common.util.GuavaUtils.java

/**
 * Transforms specified list of lists into {@link com.google.common.collect.ImmutableList} of
 * {@link com.google.common.collect.ImmutableList} lists to pass it into the methods from other libraries.
 * @param tuples list to be transformed//w  w w  .  j  av  a 2  s.co  m
 * @return transformed list
 */
public static <T> com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableList<T>> convertToNestedUnshadedImmutableList(
        List<? extends List<T>> tuples) {
    com.google.common.collect.ImmutableList.Builder<com.google.common.collect.ImmutableList<T>> immutableListBuilder = com.google.common.collect.ImmutableList
            .builder();
    for (List<T> tuple : tuples) {
        immutableListBuilder.add(convertToUnshadedImmutableList(tuple));
    }
    return immutableListBuilder.build();
}

From source file:io.prestosql.server.ThreadResource.java

private static List<StackLine> toStackTrace(StackTraceElement[] stackTrace) {
    ImmutableList.Builder<StackLine> builder = ImmutableList.builder();

    for (StackTraceElement item : stackTrace) {
        builder.add(new StackLine(item.getFileName(), item.getLineNumber(), item.getClassName(),
                item.getMethodName()));// w w w.  ja  v  a2  s.c  o m
    }

    return builder.build();
}

From source file:com.google.devtools.build.buildjar.resourcejar.ResourceJarOptionsParser.java

/** Returns a list of option values. */
private static ImmutableList<String> readList(Deque<String> argumentDeque) {
    ImmutableList.Builder<String> result = ImmutableList.builder();
    while (!argumentDeque.isEmpty() && !argumentDeque.peekFirst().startsWith("--")) {
        result.add(argumentDeque.pollFirst());
    }/* w w  w.j  ava  2  s .  c o m*/
    return result.build();
}

From source file:com.omnigon.aem.common.utils.ParserUtil.java

/**
 *
 * @param array incoming parameters//from w  w w .j  a  va 2 s . c o m
 * @param type type of Object to map
 * @param <T> -
 * @return Object with mapped parameters
 */
public static <T> ImmutableList<T> parseJsonArray(String[] array, Class<T> type) {
    final ImmutableList.Builder<T> builder = ImmutableList.builder();
    final ObjectReader reader = OBJECT_MAPPER.reader(type);
    for (String element : ArrayUtils.nullToEmpty(array)) {
        try {
            builder.add(reader.<T>readValue(element));
        } catch (IOException e) {
            LOGGER.warn(e.getMessage(), e);
        }
    }

    return builder.build();
}

From source file:com.andrewkroh.cisco.server.directory.XmlDirectoryManager.java

/**
 * Converts a {@link JaxbDirectory} object into a {@link Directory} object.
 *
 * @param jaxbDirectory/*from  ww w .jav a2  s .co  m*/
 *            {@code JaxbDirectory} used as the source in the conversion
 *
 * @return {@code Directory} created from the data in {@code jaxbDirectory}
 */
private static Directory convertJaxbDirectory(JaxbDirectory jaxbDirectory) {
    ImmutableList.Builder<DirectoryEntry> entriesBuilder = ImmutableList.builder();

    for (JaxbDirectoryEntry jaxbEntry : jaxbDirectory.getDirectoryEntries()) {
        entriesBuilder.add(new BasicDirectoryEntry(jaxbEntry.getName(), jaxbEntry.getTelephoneNumber()));
    }

    return new BasicDirectory(jaxbDirectory.getTitle(), entriesBuilder.build());
}

From source file:garmintools.encoding.VariableLengthAsciiEncoding.java

private static List<Boolean> bitListOf(int length, int value) {
    ImmutableList.Builder<Boolean> listBuilder = ImmutableList.builder();
    for (int i = 0; i < length; i++) {
        listBuilder.add((value & (1 << i)) > 0);
    }//from   ww w  .  j a  va 2  s  .co  m
    return listBuilder.build();
}

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

static ImmutableList<Type> fromElements(String packageName, ImmutableList<TypeElement> elements) {
    ImmutableList.Builder<Type> types = new ImmutableList.Builder<>();
    for (TypeElement element : elements) {
        ProtoType protoType = ProtoType.get(packageName, element.name());
        types.add(Type.get(packageName, protoType, element));
    }//from w ww. j  a  v  a2s.  co  m
    return types.build();
}

From source file:com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.r13.AndroidNdkCrosstoolsR13.java

private static ImmutableList<DefaultCpuToolchain> getDefaultCpuToolchains(StlImpl stlImpl) {
    // TODO(bazel-team): It would be better to auto-generate this somehow.

    ImmutableMap<String, String> defaultCpus = ImmutableMap.<String, String>builder()
            // arm
            .put("armeabi", "arm-linux-androideabi-clang3.8")
            .put("armeabi-v7a", "arm-linux-androideabi-clang3.8-v7a")
            .put("arm64-v8a", "aarch64-linux-android-clang3.8")

            // mips
            .put("mips", "mipsel-linux-android-clang3.8").put("mips64", "mips64el-linux-android-clang3.8")

            // x86
            .put("x86", "x86-clang3.8").put("x86_64", "x86_64-clang3.8").build();

    ImmutableList.Builder<DefaultCpuToolchain> defaultCpuToolchains = ImmutableList.builder();
    for (Entry<String, String> defaultCpu : defaultCpus.entrySet()) {
        defaultCpuToolchains.add(DefaultCpuToolchain.newBuilder().setCpu(defaultCpu.getKey())
                .setToolchainIdentifier(defaultCpu.getValue() + "-" + stlImpl.getName()).build());
    }/*from  w w  w  .  ja  v  a 2  s.c o m*/
    return defaultCpuToolchains.build();
}

From source file:io.prestosql.plugin.hive.HiveTestUtils.java

public static List<Type> getTypes(List<? extends ColumnHandle> columnHandles) {
    ImmutableList.Builder<Type> types = ImmutableList.builder();
    for (ColumnHandle columnHandle : columnHandles) {
        types.add(TYPE_MANAGER.getType(((HiveColumnHandle) columnHandle).getTypeSignature()));
    }/*from   w w w.  j  ava  2 s  . c  om*/
    return types.build();
}

From source file:google.registry.util.Concurrent.java

/**
 * Processes {@code items} in parallel using {@code funk}, with the specified number of threads.
 *
 * <p><b>Note:</b> Spawned threads will inherit the same namespace.
 *
 * @throws UncheckedExecutionException to wrap the exception thrown by {@code funk}. This will
 *     only contain the exception information for the first exception thrown.
 * @return transformed {@code items} in the same order.
 *///  w  w w.  java  2 s .  co m
public static <A, B> ImmutableList<B> transform(Collection<A> items, int threadCount,
        final Function<A, B> funk) {
    checkNotNull(funk);
    checkNotNull(items);
    ThreadFactory threadFactory = currentRequestThreadFactory();
    if (threadFactory == null) {
        // Fall back to non-concurrent transform if we can't get an App Engine thread factory (most
        // likely caused by hitting this code from a command-line tool). Default Java system threads
        // are not compatible with code that needs to interact with App Engine (such as Objectify),
        // which we often have in funk when calling Concurrent.transform().
        // For more info see: http://stackoverflow.com/questions/15976406
        return FluentIterable.from(items).transform(funk).toList();
    }
    ExecutorService executor = newFixedThreadPool(threadCount, threadFactory);
    try {
        List<Future<B>> futures = new ArrayList<>();
        for (final A item : items) {
            futures.add(executor.submit(new Callable<B>() {
                @Override
                public B call() {
                    return funk.apply(item);
                }
            }));
        }
        ImmutableList.Builder<B> results = new ImmutableList.Builder<>();
        for (Future<B> future : futures) {
            try {
                results.add(Uninterruptibles.getUninterruptibly(future));
            } catch (ExecutionException e) {
                throw new UncheckedExecutionException(e.getCause());
            }
        }
        return results.build();
    } finally {
        executor.shutdownNow();
    }
}