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.spectralogic.ds3autogen.converters.NameConverter.java

/**
 * Removes "Handler" from all request names within the spec
 * and namespaces the spectrads3 commands
 * @param spec A Ds3ApiSpec// w  w w . j ava2  s.com
 * @return A Ds3ApiSpec where the Ds3Request names now conform to the
 *        Java module naming schemes and name spacing
 */
public static Ds3ApiSpec renameRequests(final Ds3ApiSpec spec) {
    if (isEmpty(spec.getRequests())) {
        LOG.info("No requests to rename");
        return spec;
    }

    final ImmutableList.Builder<Ds3Request> builder = ImmutableList.builder();
    for (final Ds3Request request : spec.getRequests()) {
        builder.add(toUpdatedDs3Request(request));
    }

    return new Ds3ApiSpec(builder.build(), spec.getTypes());
}

From source file:com.google.cloud.datastore.IncompleteKey.java

static IncompleteKey fromPb(com.google.datastore.v1.Key keyPb) {
    String projectId = "";
    String namespace = "";
    if (keyPb.hasPartitionId()) {
        com.google.datastore.v1.PartitionId partitionIdPb = keyPb.getPartitionId();
        projectId = partitionIdPb.getProjectId();
        namespace = partitionIdPb.getNamespaceId();
    }/*ww w. j  a v a  2s. c o m*/
    List<com.google.datastore.v1.Key.PathElement> pathElementsPb = keyPb.getPathList();
    Preconditions.checkArgument(!pathElementsPb.isEmpty(), "Path must not be empty");
    ImmutableList.Builder<PathElement> pathBuilder = ImmutableList.builder();
    for (com.google.datastore.v1.Key.PathElement pathElementPb : pathElementsPb) {
        pathBuilder.add(PathElement.fromPb(pathElementPb));
    }
    ImmutableList<PathElement> path = pathBuilder.build();
    PathElement leaf = path.get(path.size() - 1);
    if (leaf.getNameOrId() != null) {
        return new Key(projectId, namespace, path);
    }
    return new IncompleteKey(projectId, namespace, path);
}

From source file:com.google.devtools.build.lib.analysis.actions.CommandLine.java

/**
 * Returns a {@link CommandLine} with {@link CharSequence} arguments. This can be useful to create
 * memory efficient command lines with {@link com.google.devtools.build.lib.util.LazyString}s.
 *//*  w  w  w  .  ja va 2s.c  o m*/
public static CommandLine ofCharSequences(final ImmutableList<CharSequence> arguments) {
    return new CommandLine() {
        @Override
        public Iterable<String> arguments() {
            ImmutableList.Builder<String> builder = ImmutableList.builder();
            for (CharSequence arg : arguments) {
                builder.add(arg.toString());
            }
            return builder.build();
        }
    };
}

From source file:org.apache.giraph.hive.common.HiveParsing.java

/**
 * Parse edges from a list//from w  w  w  . j  ava  2  s .  co m
 * @param record hive record
 * @param index column index
 * @return iterable of edges
 */
public static Iterable<Edge<IntWritable, NullWritable>> parseIntNullEdges(HiveReadableRecord record,
        int index) {
    List<Long> ids = (List<Long>) record.get(index);
    if (ids == null) {
        return ImmutableList.of();
    }
    ImmutableList.Builder<Edge<IntWritable, NullWritable>> builder = ImmutableList.builder();
    for (long id : ids) {
        builder.add(EdgeFactory.create(new IntWritable((int) id)));
    }
    return builder.build();
}

From source file:com.spotify.helios.cli.Target.java

/**
 * Create targets for a list of domains//  w  w w .  ja  va  2 s  .c om
 * @param srvName The SRV name.
 * @param domains A list of domains.
 * @return A list of targets.
 */
public static List<Target> from(final String srvName, final Iterable<String> domains) {
    final ImmutableList.Builder<Target> builder = ImmutableList.builder();
    for (final String domain : domains) {
        builder.add(new SrvTarget(srvName, domain));
    }
    return builder.build();
}

From source file:com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.r15.AndroidNdkCrosstoolsR15.java

private static ImmutableList<DefaultCpuToolchain> getDefaultCpuToolchains(StlImpl stlImpl,
        String clangVersion) {/*from   w ww .jav a2  s  .com*/
    // 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-clang" + clangVersion)
            .put("armeabi-v7a", "arm-linux-androideabi-clang" + clangVersion + "-v7a")
            .put("arm64-v8a", "aarch64-linux-android-clang" + clangVersion)

            // mips
            .put("mips", "mipsel-linux-android-clang" + clangVersion)
            .put("mips64", "mips64el-linux-android-clang" + clangVersion)

            // x86
            .put("x86", "x86-clang" + clangVersion).put("x86_64", "x86_64-clang" + clangVersion).build();

    ImmutableList.Builder<DefaultCpuToolchain> defaultCpuToolchains = ImmutableList.builder();
    for (Map.Entry<String, String> defaultCpu : defaultCpus.entrySet()) {
        defaultCpuToolchains.add(DefaultCpuToolchain.newBuilder().setCpu(defaultCpu.getKey())
                .setToolchainIdentifier(defaultCpu.getValue() + "-" + stlImpl.getName()).build());
    }
    return defaultCpuToolchains.build();
}

From source file:com.spotify.trickle.GraphExceptionWrapper.java

private static List<CallInfo> callInfos(TraverseState state) {
    ImmutableList.Builder<CallInfo> builder = builder();

    for (TraverseState.FutureCallInformation futureCallInformation : state.getCalls()) {
        if (futureCallInformation.isComplete()) {
            builder.add(asCallInfo(futureCallInformation));
        }// w w  w  .j av  a2 s.co m
    }

    return builder.build();
}

From source file:com.google.template.soy.soytree.TemplateElementNode.java

private static ImmutableList<TemplateStateVar> copyState(ImmutableList<TemplateStateVar> orig,
        CopyState copyState) {//from w  w w.j a  v a  2  s  .  co m
    ImmutableList.Builder<TemplateStateVar> newParams = ImmutableList.builder();
    for (TemplateStateVar prev : orig) {
        TemplateStateVar next = prev.copy();
        newParams.add(next);
        copyState.updateRefs(prev, next);
    }
    return newParams.build();
}

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

static IncompleteKey fromPb(DatastoreV1.Key keyPb) {
    String projectId = null;//from   ww  w.  ja  va  2  s.  c  o  m
    String namespace = null;
    if (keyPb.hasPartitionId()) {
        DatastoreV1.PartitionId partitionIdPb = keyPb.getPartitionId();
        if (partitionIdPb.hasDatasetId()) {
            projectId = 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(projectId, namespace, path);
    }
    return new IncompleteKey(projectId, namespace, path);
}

From source file:com.google.devtools.build.lib.collect.IterableCodecs.java

private static ImmutableList<Object> deserialize(DeserializationContext context, CodedInputStream codedIn)
        throws SerializationException, IOException {
    ImmutableList.Builder<Object> builder = ImmutableList.builder();
    for (Object next = context.deserialize(codedIn); next != DONE; next = context.deserialize(codedIn)) {
        builder.add(next);
    }/*w  w  w . j  a  v  a 2 s  .com*/
    return builder.build();
}