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.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.StlImpl.java

protected static Iterable<String> createIncludeFlags(Iterable<String> includePaths) {
    ImmutableList.Builder<String> includeFlags = ImmutableList.builder();
    for (String includePath : includePaths) {
        includeFlags.add("-isystem");
        includeFlags.add(includePath);//from  w ww  .j a v  a2  s . c  om
    }
    return includeFlags.build();
}

From source file:com.google.errorprone.util.ErrorProneTokens.java

/** Returns the tokens for the given source text, including comments. */
public static ImmutableList<ErrorProneToken> getTokens(String source, Context context) {
    if (source == null) {
        return ImmutableList.of();
    }/* w w  w .j  a v  a  2  s. c  o  m*/
    ScannerFactory fac = ScannerFactory.instance(context);
    char[] buffer = source.toCharArray();
    Scanner scanner = new AccessibleScanner(fac, new CommentSavingTokenizer(fac, buffer, buffer.length));
    ImmutableList.Builder<ErrorProneToken> tokens = ImmutableList.builder();
    do {
        scanner.nextToken();
        tokens.add(new ErrorProneToken(scanner.token()));
    } while (scanner.token().kind != TokenKind.EOF);
    return tokens.build();
}

From source file:com.facebook.presto.metadata.NativeRecordSink.java

private static List<TupleInfo> toTupleInfos(List<ColumnType> columnTypes) {
    ImmutableList.Builder<TupleInfo> tupleInfos = ImmutableList.builder();
    for (ColumnType columnType : columnTypes) {
        tupleInfos.add(new TupleInfo(fromColumnType(columnType)));
    }/*from   ww  w . jav a2  s.c o m*/
    return tupleInfos.build();
}

From source file:com.facebook.buck.apple.xcode.RuleDependencyFinder.java

/**
 * Retrieve all rules related to the given roots in the given graph.
 *
 * "Related" is defined as:/*w  w w .  j av a  2  s  . c om*/
 * - The rules themselves
 * - Their transitive dependencies
 * - The tests of the above rules
 * - Any additional dependencies of the tests
 */
public static ImmutableSet<BuildRule> getAllRules(PartialGraph graph, Iterable<BuildTarget> initialTargets) {

    ImmutableList.Builder<BuildRule> initialRulesBuilder = ImmutableList.builder();
    for (BuildTarget target : initialTargets) {
        initialRulesBuilder.add(graph.getDependencyGraph().findBuildRuleByTarget(target));
    }

    ImmutableSet<BuildRule> buildRules = gatherTransitiveDependencies(initialRulesBuilder.build());
    ImmutableMultimap<BuildRule, BuildRule> ruleToTestRules = buildRuleToTestRulesMap(graph);

    // Extract the test rules for the initial rules and their dependencies.
    ImmutableSet.Builder<BuildRule> testRulesBuilder = ImmutableSet.builder();
    for (BuildRule rule : buildRules) {
        testRulesBuilder.addAll(ruleToTestRules.get(rule));
    }
    ImmutableSet<BuildRule> additionalBuildRules = gatherTransitiveDependencies(testRulesBuilder.build());

    return ImmutableSet.<BuildRule>builder().addAll(buildRules).addAll(additionalBuildRules).build();
}

From source file:com.google.devtools.build.lib.rules.objc.WatchUtils.java

private static Iterable<XcodeprojBuildSetting> xcodeSettings(RuleContext ruleContext) {
    ImmutableList.Builder<XcodeprojBuildSetting> xcodeSettings = new ImmutableList.Builder<>();
    xcodeSettings.add(XcodeprojBuildSetting.newBuilder().setName("RESOURCES_TARGETED_DEVICE_FAMILY")
            .setValue(TargetDeviceFamily.WATCH.getNameInRule()).build());
    xcodeSettings.add(XcodeprojBuildSetting.newBuilder().setName("IPHONEOS_DEPLOYMENT_TARGET")
            .setValue(determineMinimumIosVersion(ruleContext.getFragment(AppleConfiguration.class)
                    .getMinimumOsForPlatformType(PlatformType.IOS)).toString())
            .build());/*  w ww . ja  v a  2 s.  c o  m*/
    return xcodeSettings.build();
}

From source file:com.torodb.torod.db.postgresql.query.processors.InProcessor.java

@Nullable
private static ProcessedQueryCriteria getProcessedQuery(InQueryCriteria criteria,
        Multimap<BasicType, Value<?>> byTypeValues, BasicType type) {
    Collection<Value<?>> values = byTypeValues.get(type);
    if (values.isEmpty()) {
        return null;
    }//ww  w  .  ja  v a  2  s  .c o  m
    ImmutableList.Builder<Value<?>> newInBuilder = new ImmutableList.Builder();
    for (Value<?> value : values) {
        newInBuilder.add(value);
    }

    return new ProcessedQueryCriteria(new TypeIsQueryCriteria(criteria.getAttributeReference(), type),
            new InQueryCriteria(criteria.getAttributeReference(), newInBuilder.build()));
}

From source file:org.apache.tajo.catalog.TypeConverter.java

public static TypeDesc convert(Type type) {
    switch (type.kind()) {
    case CHAR://from w w  w.  j  ava2 s.  c o m
        Char charType = (Char) type;
        return new TypeDesc(newDataTypeWithLen(TajoDataTypes.Type.CHAR, charType.length()));
    case VARCHAR:
        Varchar varcharType = (Varchar) type;
        return new TypeDesc(newDataTypeWithLen(TajoDataTypes.Type.VARCHAR, varcharType.length()));
    case NUMERIC:
        Numeric numericType = (Numeric) type;
        return new TypeDesc(newDataTypeWithLen(TajoDataTypes.Type.NUMERIC, numericType.precision()));
    case PROTOBUF:
        Protobuf protobuf = (Protobuf) type;
        return new TypeDesc(CatalogUtil.newDataType(TajoDataTypes.Type.PROTOBUF, protobuf.getMessageName()));
    case RECORD:
        Record record = (Record) type;
        ImmutableList.Builder<Column> fields = ImmutableList.builder();
        for (Field t : record.fields()) {
            fields.add(new Column(t.name().interned(), convert(t)));
        }
        return new TypeDesc(SchemaBuilder.builder().addAll(fields.build()).build());

    case ARRAY:
        Array array = (Array) type;
        Type elemType = array.elementType();
        switch (elemType.kind()) {
        case INT1:
            return new TypeDesc(newSimpleDataType(INT1_ARRAY));
        case INT2:
            return new TypeDesc(newSimpleDataType(INT2_ARRAY));
        case INT4:
            return new TypeDesc(newSimpleDataType(INT4_ARRAY));
        case INT8:
            return new TypeDesc(newSimpleDataType(INT8_ARRAY));
        case FLOAT4:
            return new TypeDesc(newSimpleDataType(FLOAT4_ARRAY));
        case FLOAT8:
            return new TypeDesc(newSimpleDataType(FLOAT8_ARRAY));
        default:
            return new TypeDesc(newSimpleDataType(type.kind()));
        }

    default:
        return new TypeDesc(newSimpleDataType(type.kind()));
    }
}

From source file:io.prestosql.sql.tree.DereferenceExpression.java

/**
 * If this DereferenceExpression looks like a QualifiedName, return QualifiedName.
 * Otherwise return null/*from w  ww  . jav  a2 s .c  o m*/
 */
public static QualifiedName getQualifiedName(DereferenceExpression expression) {
    List<Identifier> parts = null;
    if (expression.base instanceof Identifier) {
        parts = ImmutableList.of((Identifier) expression.base, expression.field);
    } else if (expression.base instanceof DereferenceExpression) {
        QualifiedName baseQualifiedName = getQualifiedName((DereferenceExpression) expression.base);
        if (baseQualifiedName != null) {
            ImmutableList.Builder<Identifier> builder = ImmutableList.builder();
            builder.addAll(baseQualifiedName.getOriginalParts());
            builder.add(expression.field);
            parts = builder.build();
        }
    }

    return parts == null ? null : QualifiedName.of(parts);
}

From source file:com.google.gcloud.datastore.PartialKey.java

static PartialKey fromPb(DatastoreV1.Key keyPb) {
    String dataset = null;/*from   w ww.j  av  a  2  s .c o m*/
    String namespace = null;
    if (keyPb.hasPartitionId()) {
        DatastoreV1.PartitionId partitionIdPb = keyPb.getPartitionId();
        if (partitionIdPb.hasDatasetId()) {
            dataset = partitionIdPb.getDatasetId();
        }
        if (partitionIdPb.hasNamespace()) {
            namespace = partitionIdPb.getNamespace();
        }
    }
    List<DatastoreV1.Key.PathElement> pathElementsPb = keyPb.getPathElementList();
    Preconditions.checkArgument(!pathElementsPb.isEmpty(), "Path must not be empty");
    ImmutableList.Builder<PathElement> pathBuilder = ImmutableList.builder();
    for (DatastoreV1.Key.PathElement pathElementPb : pathElementsPb) {
        pathBuilder.add(PathElement.fromPb(pathElementPb));
    }
    ImmutableList<PathElement> path = pathBuilder.build();
    PathElement leaf = path.get(path.size() - 1);
    if (leaf.nameOrId() != null) {
        return new Key(dataset, namespace, path);
    }
    return new PartialKey(dataset, namespace, path);
}

From source file:com.facebook.buck.java.JavaLibraryRules.java

static void addAccumulateClassNamesStep(JavaLibrary javaLibrary, BuildableContext buildableContext,
        ImmutableList.Builder<Step> steps) {
    Preconditions.checkNotNull(javaLibrary);

    Path pathToClassHashes = JavaLibraryRules.getPathToClassHashes(javaLibrary.getBuildTarget());
    steps.add(new MkdirStep(pathToClassHashes.getParent()));
    steps.add(new AccumulateClassNamesStep(Optional.fromNullable(javaLibrary.getPathToOutputFile()),
            pathToClassHashes));//from  w w w.  j a va2  s.c  o  m
    buildableContext.recordArtifact(pathToClassHashes);
}