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.palantir.typescript.services.language.ScriptElementModifierKind.java

public static ImmutableList<ScriptElementModifierKind> parseList(String kindModifiers) {
    ImmutableList.Builder<ScriptElementModifierKind> kindModifiersBuilder = ImmutableList.builder();

    if (kindModifiers.length() > 0) {
        for (String kindModifier : Splitter.on(',').split(kindModifiers)) {
            kindModifiersBuilder.add(fromString(kindModifier));
        }/*from w  w w. ja v  a  2 s.com*/
    }

    return kindModifiersBuilder.build();
}

From source file:com.facebook.presto.verifier.PrestoVerifier.java

private static List<URL> getUrls(String path) throws MalformedURLException {
    ImmutableList.Builder<URL> urlList = ImmutableList.builder();
    File driverPath = new File(path);
    if (!driverPath.isDirectory()) {
        urlList.add(Paths.get(path).toUri().toURL());
        return urlList.build();
    }//from  w w  w  . j  a  va  2 s  . c o m
    File[] files = driverPath.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".jar");
        }
    });
    if (files == null) {
        return urlList.build();
    }
    for (File file : files) {
        // Does not handle nested directories
        if (file.isDirectory()) {
            continue;
        }
        urlList.add(Paths.get(file.getAbsolutePath()).toUri().toURL());
    }
    return urlList.build();
}

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

/**
 * Creates the depreciated constructor for the get object request
 *///from   w  w  w.  j a v  a  2 s  .  c o  m
protected static RequestConstructor createDeprecatedConstructor(final ImmutableList<Arguments> constructorArgs,
        final ImmutableList<QueryParam> queryParams, final String requestName, final Ds3DocSpec docSpec) {
    final ImmutableList.Builder<Arguments> constructorArgBuilder = ImmutableList.builder();
    constructorArgBuilder.addAll(constructorArgs);
    constructorArgBuilder.add(new Arguments("WritableByteChannel", "Channel"));

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

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

From source file:org.apache.james.transport.mailets.remote.delivery.DelaysAndMaxRetry.java

private static List<Delay> createDelayList(String delaysAsString) {
    if (delaysAsString == null) {
        // Use default delayTime.
        return ImmutableList.of(new Delay());
    }//from  w w  w.  ja  v  a  2 s .com

    List<String> delayStrings = Splitter.on(',').omitEmptyStrings().trimResults().splitToList(delaysAsString);

    ImmutableList.Builder<Delay> builder = ImmutableList.builder();
    try {
        for (String s : delayStrings) {
            builder.add(Delay.from(s));
        }
        return builder.build();
    } catch (Exception e) {
        LOGGER.warn("Invalid delayTime setting: {}", delaysAsString);
        return builder.build();
    }
}

From source file:com.palantir.typescript.services.language.ScriptElementKindModifier.java

public static ImmutableList<ScriptElementKindModifier> parseList(String kindModifiers) {
    ImmutableList.Builder<ScriptElementKindModifier> kindModifiersBuilder = ImmutableList.builder();

    if (kindModifiers.length() > 0) {
        for (String kindModifier : Splitter.on(',').split(kindModifiers)) {
            kindModifiersBuilder.add(fromString(kindModifier));
        }/*from w  ww  .j av a2  s  .  c  o m*/
    }

    return kindModifiersBuilder.build();
}

From source file:com.facebook.presto.operator.RowNumberLimitOperator.java

private static List<Type> toTypes(List<? extends Type> sourceTypes, List<Integer> outputChannels) {
    ImmutableList.Builder<Type> types = ImmutableList.builder();
    for (int channel : outputChannels) {
        types.add(sourceTypes.get(channel));
    }/*from w w w  .  j  av  a2s . c  o m*/
    types.add(BIGINT);
    return types.build();
}

From source file:com.facebook.buck.android.resources.ChunkUtils.java

/**
 * Finds all chunks in the buffer with the requested type. This is useful for tests to find chunks
 * of a certain type without needing to understand all the other encountered chunks.
 *
 * @return A list of offsets in the buffer to chunks of the requested type.
 *///from www.  j ava2  s . c  o  m
static List<Integer> findChunks(ByteBuffer data, int wantedType) {
    ByteBuffer buf = ResChunk.slice(data, 0);
    ImmutableList.Builder<Integer> offsetsBuilder = ImmutableList.builder();
    int offset = 0;
    while (offset < buf.limit()) {
        int type = buf.getShort(offset);
        if (type == wantedType) {
            offsetsBuilder.add(offset);
        }
        int headerSize = buf.getShort(offset + 2);
        int chunkSize = buf.getInt(offset + 4);
        // These chunks consist of lists of sub-chunks after their headers.
        if (type == ResChunk.CHUNK_RESOURCE_TABLE || type == ResChunk.CHUNK_RES_TABLE_PACKAGE
                || type == ResChunk.CHUNK_XML_TREE) {
            int subchunksStart = offset + headerSize;
            int subchunksLength = chunkSize - headerSize;
            for (int subOffset : findChunks(ResChunk.slice(buf, subchunksStart, subchunksLength), wantedType)) {
                offsetsBuilder.add(subchunksStart + subOffset);
            }
        }
        offset += chunkSize;
    }
    return offsetsBuilder.build();
}

From source file:com.facebook.presto.jdbc.client.FailureInfo.java

private static FailureException toException(FailureInfo failureInfo) {
    if (failureInfo == null) {
        return null;
    }//from www .  j a  va 2s. com
    FailureException failure = new FailureException(failureInfo.getType(), failureInfo.getMessage(),
            toException(failureInfo.getCause()));
    ImmutableList.Builder<StackTraceElement> stackTraceBuilder = ImmutableList.builder();
    for (String stack : failureInfo.getStack()) {
        stackTraceBuilder.add(toStackTraceElement(stack));
    }
    ImmutableList<StackTraceElement> stackTrace = stackTraceBuilder.build();
    failure.setStackTrace(stackTrace.toArray(new StackTraceElement[stackTrace.size()]));
    return failure;
}

From source file:com.android.build.gradle.tasks.SplitRelatedTask.java

/**
 * Creates a new FilterData for each identifiers for a particular {@link FilterType} and store
 * it in the to builder.// w  ww  .  j ava 2  s  . c o m
 * @param to          the builder to store the new FilterData instances in.
 * @param identifiers the list of filter identifiers
 * @param filterType  the filter type.
 */
protected static void addAllFilterData(ImmutableList.Builder<FilterData> to, Collection<String> identifiers,
        OutputFile.FilterType filterType) {
    for (String identifier : identifiers) {
        to.add(FilterDataImpl.build(filterType.toString(), identifier));
    }
}

From source file:com.spectralogic.ds3autogen.c.helpers.EnumHelper.java

public static ImmutableList<String> convertDs3EnumConstants(final Ds3Type ds3Type) {
    final ImmutableList.Builder<String> stringListBuilder = ImmutableList.builder();
    for (final Ds3EnumConstant currentEnum : ds3Type.getEnumConstants()) {
        stringListBuilder
                .add(getDs3Type(ds3Type.getName()).toUpperCase() + '_' + currentEnum.getName().toUpperCase());
    }//  ww w .  j  a  va  2 s. com
    return stringListBuilder.build();
}