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:io.prestosql.plugin.memory.MemoryColumnHandle.java

public static List<MemoryColumnHandle> extractColumnHandles(List<ColumnMetadata> columns) {
    ImmutableList.Builder<MemoryColumnHandle> columnHandles = ImmutableList.builder();
    int columnIndex = 0;
    for (ColumnMetadata column : columns) {
        columnHandles.add(new MemoryColumnHandle(column, columnIndex));
        columnIndex++;//ww w.  ja v  a 2 s  . com
    }
    return columnHandles.build();
}

From source file:org.obiba.magma.datasource.mongodb.converter.ValueConverter.java

public static Value unmarshall(ValueType type, boolean repeatable, String field, BSONObject object) {
    if (object == null || !object.containsField(field)) {
        return repeatable ? type.nullSequence() : type.nullValue();
    }/*ww w .j  a  va  2s . com*/

    if (repeatable) {
        Iterable<?> values = (Iterable<?>) object.get(field);
        if (values == null)
            return type.nullSequence();
        ImmutableList.Builder<Value> list = ImmutableList.builder();
        for (Object o : values) {
            list.add(unmarshall(type, o));
        }
        return type.sequenceOf(list.build());
    }
    return unmarshall(type, object.get(field));
}

From source file:org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.UnionVersionSelector.java

public static UnionVersionSelector of(List<String> selectors, VersionSelectorScheme scheme) {
    ImmutableList.Builder<VersionSelector> builder = new ImmutableList.Builder<VersionSelector>();
    for (String selector : selectors) {
        builder.add(scheme.parseSelector(selector));
    }/*w  ww . j  a  v  a2s  . co m*/
    return new UnionVersionSelector(builder.build());
}

From source file:org.attribyte.api.http.NamedValues.java

/**
 * Copies values from an array to an immutable list.
 * Empty or <code>null</code> values are ignored.
 * @param values The input values./*w w  w  . j a  v  a  2s. com*/
 * @return The internal values.
 */
static final ImmutableList<String> copyValues(final String[] values) {
    if (values == null || values.length == 0) {
        return ImmutableList.of();
    } else {
        ImmutableList.Builder<String> builder = ImmutableList.builder();
        for (final String value : values) {
            if (!Strings.isNullOrEmpty(value)) {
                builder.add(value);
            }
        }
        return builder.build();
    }
}

From source file:org.attribyte.api.http.NamedValues.java

/**
 * Copies values from a collection to an immutable list.
 * Empty or <code>null</code> values are ignored.
 * @param values The input values./* w w  w .java  2s. c  o m*/
 * @return The internal values.
 */
static final ImmutableList<String> copyValues(final Collection<String> values) {
    if (values == null) {
        return ImmutableList.of();
    } else {
        ImmutableList.Builder<String> builder = ImmutableList.builder();
        for (final String value : values) {
            if (!Strings.isNullOrEmpty(value)) {
                builder.add(value);
            }
        }
        return builder.build();
    }
}

From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.ReflectivePropertyAdapter.java

public static PropertyAdapter create(TypeWidget typeWidget, ProgramValueTypeAdapter adapter,
        TypeLiteral<?> typeLiteral) {
    Map<String, PropertyReader> properties = readProperties(typeLiteral, adapter);
    ImmutableList.Builder<Property> propertyBuilder = ImmutableList.builder();
    for (PropertyReader reader : properties.values()) {
        propertyBuilder.add(reader.property);
    }//from w  w w. ja  va  2  s.c  o m
    List<Property> propertyList = propertyBuilder.build();
    return new ReflectivePropertyAdapter(typeWidget, properties, propertyList);
}

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

static ImmutableList<ServiceElement> toElements(ImmutableList<Service> services) {
    ImmutableList.Builder<ServiceElement> elements = new ImmutableList.Builder<>();
    for (Service service : services) {
        elements.add(
                ServiceElement.builder(service.location).documentation(service.documentation).name(service.name)
                        .rpcs(Rpc.toElements(service.rpcs)).options(service.options.toElements()).build());
    }//from   w w  w.jav a2 s  .  c  om
    return elements.build();
}

From source file:com.google.devtools.build.xcode.xcodegen.SourceFile.java

/**
 * Returns information on all source files in a target. In particular, this includes:
 * <ul>//from w  w w  . j  a  v a2 s . c  o m
 *   <li>arc-compiled source files
 *   <li>non-arc-compiled source files
 *   <li>support files, such as BUILD and header files
 *   <li>Info.plist file
 * </ul>
 */
public static Iterable<SourceFile> allSourceFiles(FileSystem fileSystem, TargetControl control) {
    ImmutableList.Builder<SourceFile> result = new ImmutableList.Builder<>();
    for (Path plainSource : RelativePaths.fromStrings(fileSystem, control.getSourceFileList())) {
        result.add(new SourceFile(BuildType.BUILD, plainSource));
    }
    for (Path nonArcSource : RelativePaths.fromStrings(fileSystem, control.getNonArcSourceFileList())) {
        result.add(new SourceFile(BuildType.NON_ARC_BUILD, nonArcSource));
    }
    for (Path supportSource : RelativePaths.fromStrings(fileSystem, control.getSupportFileList())) {
        result.add(new SourceFile(BuildType.NO_BUILD, supportSource));
    }
    if (control.hasInfoplist()) {
        result.add(new SourceFile(BuildType.NO_BUILD,
                RelativePaths.fromString(fileSystem, control.getInfoplist())));
    }
    return result.build();
}

From source file:com.facebook.presto.verifier.framework.JdbcDriverUtil.java

private static List<URL> getUrls(String path) {
    try {/*ww w  .  j  a va 2s.  c o m*/
        ImmutableList.Builder<URL> urlList = ImmutableList.builder();
        File driverPath = new File(path);
        if (!driverPath.isDirectory()) {
            return urlList.add(Paths.get(path).toUri().toURL()).build();
        }
        File[] files = driverPath.listFiles((dir, name) -> 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();
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
}

From source file:eu.eidas.auth.commons.io.MapSerializationHelper.java

public static <K, V> ImmutableList<KeyValue<K, V>> asKeyValueList(Map<K, V> map) {
    Set<Map.Entry<K, V>> entrySet = map.entrySet();
    ImmutableList.Builder<KeyValue<K, V>> keyValueViewBuilder = new ImmutableList.Builder<KeyValue<K, V>>();
    for (final Map.Entry<K, V> entry : entrySet) {
        keyValueViewBuilder.add(new KeyValue<K, V>(entry.getKey(), entry.getValue()));
    }/*from   w w w .  j ava  2 s .  c o  m*/
    return keyValueViewBuilder.build();
}