Example usage for com.google.common.collect ImmutableList get

List of usage examples for com.google.common.collect ImmutableList get

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableList get.

Prototype

E get(int index);

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:edu.mit.streamjit.util.bytecode.Method.java

private ImmutableList<Argument> buildArguments() {
    ImmutableList<RegularType> paramTypes = getType().getParameterTypes();
    ImmutableList.Builder<Argument> builder = ImmutableList.builder();
    if (isConstructor())
        builder.add(new Argument(this, getParent().getParent().types().getRegularType(getParent()), "this"));
    for (int i = 0; i < paramTypes.size(); ++i) {
        String name = (i == 0 && hasReceiver()) ? "this" : "arg" + i;
        builder.add(new Argument(this, paramTypes.get(i), name));
    }/*from  w w w  . java 2s  .  co m*/
    return builder.build();
}

From source file:org.locationtech.geogig.storage.postgresql.v9.PGGraphDatabase.java

/**
 * Bulk put compatible with PG 9.5+, using upsert
 *///from   w w  w .  j  av  a2 s.  com
private void putWithUpsert(Connection cx, Stream<RevCommit> commits) throws SQLException {
    // from PG 9.5+
    final String upsert = format(
            "INSERT INTO %s (src, dst, dstindex) VALUES (ROW(?,?,?), ROW(?,?,?), ?) ON CONFLICT DO NOTHING",
            EDGES);

    final Stopwatch sw = LOG.isTraceEnabled() ? Stopwatch.createStarted() : null;

    int count = 0;
    PGId src, dst;
    try (PreparedStatement ps = cx.prepareStatement(upsert)) {
        Iterator<RevCommit> iterator = commits.iterator();
        while (iterator.hasNext()) {
            RevCommit c = iterator.next();
            count++;
            src = PGId.valueOf(c.getId());
            ImmutableList<ObjectId> parentIds = c.getParentIds();
            for (int parentIndex = 0; parentIndex < parentIds.size(); parentIndex++) {
                ObjectId parent = parentIds.get(parentIndex);
                dst = PGId.valueOf(parent);
                src.setArgs(ps, 1);
                dst.setArgs(ps, 4);
                ps.setInt(7, parentIndex);
                ps.addBatch();
            }
        }
        if (count > 0) {
            int[] batchResults = ps.executeBatch();
            if (LOG.isTraceEnabled()) {
                sw.stop();
                LOG.trace(String.format("%,d updates to graph in %s: %s", count, sw,
                        Arrays.toString(batchResults)));
            }
        }
    }
}

From source file:com.opengamma.strata.pricer.swap.DiscountingSwapProductPricer.java

private Triple<Boolean, Integer, Double> checkFixedCompounded(ResolvedSwapLeg leg) {
    if (leg.getPaymentEvents().size() != 0) {
        return Triple.of(false, 0, 0.0d); // No event
    }/* w w w .  j a  v a 2 s  .c o m*/
    RatePaymentPeriod ratePaymentPeriod = (RatePaymentPeriod) leg.getPaymentPeriods().get(0);
    if (ratePaymentPeriod.getCompoundingMethod() == CompoundingMethod.NONE) {
        return Triple.of(false, 0, 0.0d); // Should be compounded
    }
    ImmutableList<RateAccrualPeriod> accrualPeriods = ratePaymentPeriod.getAccrualPeriods();
    int nbAccrualPeriods = accrualPeriods.size();
    double fixedRate = 0;
    for (int i = 0; i < nbAccrualPeriods; i++) {
        if (!(accrualPeriods.get(i).getRateComputation() instanceof FixedRateComputation)) {
            return Triple.of(false, 0, 0.0d); // Should be fixed period
        }
        if ((i > 0) && (((FixedRateComputation) accrualPeriods.get(i).getRateComputation())
                .getRate() != fixedRate)) {
            return Triple.of(false, 0, 0.0d); // All fixed rates should be the same
        }
        fixedRate = ((FixedRateComputation) accrualPeriods.get(i).getRateComputation()).getRate();
        if (accrualPeriods.get(i).getSpread() != 0) {
            return Triple.of(false, 0, 0.0d); // Should have no spread
        }
        if (accrualPeriods.get(i).getGearing() != 1.0d) {
            return Triple.of(false, 0, 0.0d); // Should have a gearing of 1.
        }
        if (accrualPeriods.get(i).getYearFraction() != 1.0d) {
            return Triple.of(false, 0, 0.0d); // Should have a year fraction of 1.
        }
    }
    return Triple.of(true, nbAccrualPeriods, fixedRate);
}

From source file:org.locationtech.geogig.spring.service.RepositoryService.java

public RevFeature mergeFeatures(RepositoryProvider provider, String repoName, MergeFeatureRequest request) {
    // validty check, shouldn't hit this unless the controller isn't catching these
    if (request == null || request.getMerges() == null || request.getOurs() == null || request.getPath() == null
            || request.getTheirs() == null) {
        throw new IllegalArgumentException("Invalid POST data.");
    }/*from   ww  w .  j  av  a 2  s . c o  m*/
    // get the repo
    Repository repository = getRepository(provider, repoName);
    if (repository != null) {
        // ours and thiers
        RevFeature ourFeature = null;
        RevFeatureType ourFeatureType = null;
        RevFeature theirFeature = null;
        RevFeatureType theirFeatureType = null;
        // get our Node
        Optional<NodeRef> ourNode = parseID(ObjectId.valueOf(request.getOurs()), request.getPath(), repository);
        if (ourNode.isPresent()) {
            // get the RevObject for our Node
            Optional<RevObject> object = repository.command(RevObjectParse.class)
                    .setObjectId(ourNode.get().getObjectId()).call();
            Preconditions.checkState(object.isPresent() && object.get() instanceof RevFeature);

            ourFeature = (RevFeature) object.get();

            object = repository.command(RevObjectParse.class).setObjectId(ourNode.get().getMetadataId()).call();
            Preconditions.checkState(object.isPresent() && object.get() instanceof RevFeatureType);

            ourFeatureType = (RevFeatureType) object.get();
        }
        // get their node
        Optional<NodeRef> theirNode = parseID(ObjectId.valueOf(request.getTheirs()), request.getPath(),
                repository);
        if (theirNode.isPresent()) {
            Optional<RevObject> object = repository.command(RevObjectParse.class)
                    .setObjectId(theirNode.get().getObjectId()).call();
            Preconditions.checkState(object.isPresent() && object.get() instanceof RevFeature);

            theirFeature = (RevFeature) object.get();

            object = repository.command(RevObjectParse.class).setObjectId(theirNode.get().getMetadataId())
                    .call();
            Preconditions.checkState(object.isPresent() && object.get() instanceof RevFeatureType);

            theirFeatureType = (RevFeatureType) object.get();
        }
        // ensure feature types are not null
        Preconditions.checkState(ourFeatureType != null || theirFeatureType != null);
        // get the feature builder for the feature to be merged
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(
                (SimpleFeatureType) (ourFeatureType != null ? ourFeatureType.type() : theirFeatureType.type()));
        // get an iterator of the feature properties
        ImmutableList<PropertyDescriptor> descriptors = (ourFeatureType == null ? theirFeatureType
                : ourFeatureType).descriptors();
        // configure the builder
        for (Merge merge : request.getMerges()) {
            int descriptorIndex = getDescriptorIndex(merge.getAttribute(), descriptors);
            if (descriptorIndex > -1) {
                // get the feature property descriptor
                PropertyDescriptor descriptor = descriptors.get(descriptorIndex);
                // determine "ours", "theirs" or "value" (should be mutually exclusive)
                if (Boolean.TRUE.equals(merge.getOurs())) {
                    // take "ours" for this property
                    featureBuilder.set(descriptor.getName(),
                            ourFeature == null ? null : ourFeature.get(descriptorIndex).orNull());

                } else if (Boolean.TRUE.equals(merge.getTheirs())) {
                    // take "theirs" for this property
                    featureBuilder.set(descriptor.getName(),
                            theirFeature == null ? null : theirFeature.get(descriptorIndex).orNull());
                } else {
                    // take "value", even if it's null
                    featureBuilder.set(descriptor.getName(), merge.getValue());
                }
            }
        }
        // merge the feature
        SimpleFeature feature = featureBuilder.buildFeature(NodeRef.nodeFromPath(request.getPath()));
        RevFeature revFeature = RevFeatureBuilder.build(feature);
        repository.objectDatabase().put(revFeature);
        return revFeature;
    }
    return null;
}

From source file:org.locationtech.geogig.porcelain.ApplyPatchOp.java

private void applyPatch(Patch patch) {
    final WorkingTree workTree = workingTree();
    final ObjectStore indexDb = objectDatabase();
    if (reverse) {
        patch = patch.reversed();//w  w  w . ja  va  2 s . co m
    }

    objectDatabase().putAll(patch.getFeatureTypes().iterator());

    List<FeatureInfo> removed = patch.getRemovedFeatures();
    for (FeatureInfo feature : removed) {
        workTree.delete(feature.getPath());
    }
    List<FeatureInfo> added = patch.getAddedFeatures();
    for (FeatureInfo feature : added) {
        workTree.insert(feature);
    }
    List<FeatureDiff> diffs = patch.getModifiedFeatures();
    for (FeatureDiff diff : diffs) {
        String path = diff.getPath();
        DepthSearch depthSearch = new DepthSearch(indexDb);
        Optional<NodeRef> noderef = depthSearch.find(workTree.getTree(), path);
        RevFeatureType oldRevFeatureType = command(RevObjectParse.class)
                .setObjectId(noderef.get().getMetadataId()).call(RevFeatureType.class).get();
        String refSpec = Ref.WORK_HEAD + ":" + path;
        RevFeature feature = command(RevObjectParse.class).setRefSpec(refSpec).call(RevFeature.class).get();

        RevFeatureType newRevFeatureType = getFeatureType(diff, feature, oldRevFeatureType);
        ImmutableList<PropertyDescriptor> oldDescriptors = oldRevFeatureType.descriptors();
        ImmutableList<PropertyDescriptor> newDescriptors = newRevFeatureType.descriptors();
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(
                (SimpleFeatureType) newRevFeatureType.type());
        Map<Name, Object> attrs = Maps.newHashMap();
        for (int i = 0; i < oldDescriptors.size(); i++) {
            PropertyDescriptor descriptor = oldDescriptors.get(i);
            if (newDescriptors.contains(descriptor)) {
                Optional<Object> value = feature.get(i);
                attrs.put(descriptor.getName(), value.orNull());
            }
        }
        Set<Entry<PropertyDescriptor, AttributeDiff>> featureDiffs = diff.getDiffs().entrySet();
        for (Iterator<Entry<PropertyDescriptor, AttributeDiff>> iterator = featureDiffs.iterator(); iterator
                .hasNext();) {
            Entry<PropertyDescriptor, AttributeDiff> entry = iterator.next();
            if (!entry.getValue().getType().equals(TYPE.REMOVED)) {
                Object oldValue = attrs.get(entry.getKey().getName());
                attrs.put(entry.getKey().getName(), entry.getValue().applyOn(oldValue));
            }
        }
        Set<Entry<Name, Object>> entries = attrs.entrySet();
        for (Iterator<Entry<Name, Object>> iterator = entries.iterator(); iterator.hasNext();) {
            Entry<Name, Object> entry = iterator.next();
            featureBuilder.set(entry.getKey(), entry.getValue());

        }

        SimpleFeature f = featureBuilder.buildFeature(NodeRef.nodeFromPath(path));
        RevFeature featureToInsert = RevFeatureBuilder.build(f);
        FeatureInfo featureInfo = FeatureInfo.insert(featureToInsert, newRevFeatureType.getId(), path);
        workTree.insert(featureInfo);

    }
    ImmutableList<FeatureTypeDiff> alteredTrees = patch.getAlteredTrees();
    for (FeatureTypeDiff diff : alteredTrees) {
        Optional<RevFeatureType> featureType;
        if (diff.getOldFeatureType().isNull()) {
            featureType = patch.getFeatureTypeFromId(diff.getNewFeatureType());
            workTree.createTypeTree(diff.getPath(), featureType.get().type());
        } else if (diff.getNewFeatureType().isNull()) {
            workTree.delete(diff.getPath());
        } else {
            featureType = patch.getFeatureTypeFromId(diff.getNewFeatureType());
            workTree.updateTypeTree(diff.getPath(), featureType.get().type());
        }
    }

}

From source file:org.locationtech.geogig.api.porcelain.ApplyPatchOp.java

private void applyPatch(Patch patch) {
    final WorkingTree workTree = workingTree();
    final ObjectDatabase indexDb = objectDatabase();
    if (reverse) {
        patch = patch.reversed();//  w  w w .  j  a  v  a  2s  .c o m
    }

    List<FeatureInfo> removed = patch.getRemovedFeatures();
    for (FeatureInfo feature : removed) {
        workTree.delete(NodeRef.parentPath(feature.getPath()), NodeRef.nodeFromPath(feature.getPath()));
    }
    List<FeatureInfo> added = patch.getAddedFeatures();
    for (FeatureInfo feature : added) {
        workTree.insert(NodeRef.parentPath(feature.getPath()), feature.getFeature());
    }
    List<FeatureDiff> diffs = patch.getModifiedFeatures();
    for (FeatureDiff diff : diffs) {
        String path = diff.getPath();
        DepthSearch depthSearch = new DepthSearch(indexDb);
        Optional<NodeRef> noderef = depthSearch.find(workTree.getTree(), path);
        RevFeatureType oldRevFeatureType = command(RevObjectParse.class)
                .setObjectId(noderef.get().getMetadataId()).call(RevFeatureType.class).get();
        String refSpec = Ref.WORK_HEAD + ":" + path;
        RevFeature feature = command(RevObjectParse.class).setRefSpec(refSpec).call(RevFeature.class).get();

        RevFeatureType newRevFeatureType = getFeatureType(diff, feature, oldRevFeatureType);
        ImmutableList<Optional<Object>> values = feature.getValues();
        ImmutableList<PropertyDescriptor> oldDescriptors = oldRevFeatureType.sortedDescriptors();
        ImmutableList<PropertyDescriptor> newDescriptors = newRevFeatureType.sortedDescriptors();
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(
                (SimpleFeatureType) newRevFeatureType.type());
        Map<Name, Optional<?>> attrs = Maps.newHashMap();
        for (int i = 0; i < oldDescriptors.size(); i++) {
            PropertyDescriptor descriptor = oldDescriptors.get(i);
            if (newDescriptors.contains(descriptor)) {
                Optional<Object> value = values.get(i);
                attrs.put(descriptor.getName(), value);
            }
        }
        Set<Entry<PropertyDescriptor, AttributeDiff>> featureDiffs = diff.getDiffs().entrySet();
        for (Iterator<Entry<PropertyDescriptor, AttributeDiff>> iterator = featureDiffs.iterator(); iterator
                .hasNext();) {
            Entry<PropertyDescriptor, AttributeDiff> entry = iterator.next();
            if (!entry.getValue().getType().equals(TYPE.REMOVED)) {
                Optional<?> oldValue = attrs.get(entry.getKey().getName());
                attrs.put(entry.getKey().getName(), entry.getValue().applyOn(oldValue));
            }
        }
        Set<Entry<Name, Optional<?>>> entries = attrs.entrySet();
        for (Iterator<Entry<Name, Optional<?>>> iterator = entries.iterator(); iterator.hasNext();) {
            Entry<Name, Optional<?>> entry = iterator.next();
            featureBuilder.set(entry.getKey(), entry.getValue().orNull());

        }

        SimpleFeature featureToInsert = featureBuilder.buildFeature(NodeRef.nodeFromPath(path));
        workTree.insert(NodeRef.parentPath(path), featureToInsert);

    }
    ImmutableList<FeatureTypeDiff> alteredTrees = patch.getAlteredTrees();
    for (FeatureTypeDiff diff : alteredTrees) {
        Optional<RevFeatureType> featureType;
        if (diff.getOldFeatureType().isNull()) {
            featureType = patch.getFeatureTypeFromId(diff.getNewFeatureType());
            workTree.createTypeTree(diff.getPath(), featureType.get().type());
        } else if (diff.getNewFeatureType().isNull()) {
            workTree.delete(diff.getPath());
        } else {
            featureType = patch.getFeatureTypeFromId(diff.getNewFeatureType());
            workTree.updateTypeTree(diff.getPath(), featureType.get().type());
        }
    }

}

From source file:org.locationtech.geogig.storage.postgresql.v9.PGGraphDatabase.java

/**
 * Bulk put compatible with PG < 9.5, can't use upsert
 * /* ww  w  .  ja v a2s  .  com*/
 * @throws SQLException
 */
private void putWithoutUpsert(Connection cx, Stream<RevCommit> commits) throws SQLException {

    Preconditions.checkArgument(!cx.getAutoCommit());

    final Set<RevCommit> uniqueCommits = commits.collect(Collectors.toSet());
    if (uniqueCommits.isEmpty()) {
        return;
    }

    final String tmpTable = "graph_edge_tmp";
    final String tmpTableSql = format(
            "CREATE TEMPORARY TABLE %s (src OBJECTID, dst OBJECTID, dstindex int NOT NULL, PRIMARY KEY (src,dst)) ON COMMIT DROP",
            tmpTable, EDGES);

    // create temporary table. The temporary table is local to the transaction
    try (Statement st = cx.createStatement()) {
        st.execute(log(tmpTableSql, LOG));
    }

    // insert all rows to the tmp table
    final String insert = "INSERT INTO " + tmpTable
            + " (src, dst, dstindex) VALUES (ROW(?,?,?), ROW(?,?,?), ?)";

    PGId src, dst;
    try (PreparedStatement ps = cx.prepareStatement(insert)) {
        for (RevCommit c : uniqueCommits) {
            src = PGId.valueOf(c.getId());
            ImmutableList<ObjectId> parentIds = c.getParentIds();
            for (int parentIndex = 0; parentIndex < parentIds.size(); parentIndex++) {
                ObjectId parent = parentIds.get(parentIndex);
                dst = PGId.valueOf(parent);
                src.setArgs(ps, 1);
                dst.setArgs(ps, 4);
                ps.setInt(7, parentIndex);
                ps.addBatch();
            }
        }
        ps.executeBatch();
    }

    // copy all new rows to the edges table
    final String insertUniqueSql = "INSERT INTO " + EDGES + "(src,dst,dstindex)\n"//
            + " SELECT DISTINCT src,dst,dstindex FROM " + tmpTable + "\n"//
            + " WHERE NOT EXISTS (\n"//
            + "  SELECT 1 FROM " + EDGES + "\n"//
            + "  WHERE \n" //
            + "   " + tmpTable + ".src = " + EDGES + ".src \n"//
            + "   AND " + tmpTable + ".dst = " + EDGES + ".dst\n"//
            + ")";

    try (Statement st = cx.createStatement()) {
        st.execute(log(insertUniqueSql, LOG));
    }
}

From source file:de.metanome.algorithm_helper.data_structures.ColumnCombinationBitset.java

/**
 * Returns the {@link ColumnCombination} with the correct name of the relation and the column
 * names.//from  w ww  .  ja  v  a 2s  . c om
 *
 * @param relationName the relation name
 * @param columnNames  the name of the columns
 * @return a {@link ColumnCombination}
 */
public ColumnCombination createColumnCombination(String relationName, ImmutableList<String> columnNames) {
    ColumnIdentifier[] identifierList = new ColumnIdentifier[size()];
    int i = 0;
    for (Integer columnIndex : getSetBits()) {
        identifierList[i] = new ColumnIdentifier(relationName, columnNames.get(columnIndex));
        i++;
    }

    return new ColumnCombination(identifierList);
}

From source file:org.geogit.api.porcelain.ApplyPatchOp.java

private void applyPatch(Patch patch) {

    if (reverse) {
        patch = patch.reversed();//w  w  w.ja v a  2 s. c om
    }

    List<FeatureInfo> removed = patch.getRemovedFeatures();
    for (FeatureInfo feature : removed) {
        workTree.delete(NodeRef.parentPath(feature.getPath()), NodeRef.nodeFromPath(feature.getPath()));
    }
    List<FeatureInfo> added = patch.getAddedFeatures();
    for (FeatureInfo feature : added) {
        workTree.insert(NodeRef.parentPath(feature.getPath()), feature.getFeature());
    }
    List<FeatureDiff> diffs = patch.getModifiedFeatures();
    for (FeatureDiff diff : diffs) {
        String path = diff.getPath();
        DepthSearch depthSearch = new DepthSearch(indexDb);
        Optional<NodeRef> noderef = depthSearch.find(workTree.getTree(), path);
        RevFeatureType oldRevFeatureType = command(RevObjectParse.class)
                .setObjectId(noderef.get().getMetadataId()).call(RevFeatureType.class).get();
        String refSpec = Ref.WORK_HEAD + ":" + path;
        RevFeature feature = command(RevObjectParse.class).setRefSpec(refSpec).call(RevFeature.class).get();

        RevFeatureType newRevFeatureType = getFeatureType(diff, feature, oldRevFeatureType);
        ImmutableList<Optional<Object>> values = feature.getValues();
        ImmutableList<PropertyDescriptor> oldDescriptors = oldRevFeatureType.sortedDescriptors();
        ImmutableList<PropertyDescriptor> newDescriptors = newRevFeatureType.sortedDescriptors();
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(
                (SimpleFeatureType) newRevFeatureType.type());
        Map<Name, Optional<?>> attrs = Maps.newHashMap();
        for (int i = 0; i < oldDescriptors.size(); i++) {
            PropertyDescriptor descriptor = oldDescriptors.get(i);
            if (newDescriptors.contains(descriptor)) {
                Optional<Object> value = values.get(i);
                attrs.put(descriptor.getName(), value);
            }
        }
        Set<Entry<PropertyDescriptor, AttributeDiff>> featureDiffs = diff.getDiffs().entrySet();
        for (Iterator<Entry<PropertyDescriptor, AttributeDiff>> iterator = featureDiffs.iterator(); iterator
                .hasNext();) {
            Entry<PropertyDescriptor, AttributeDiff> entry = iterator.next();
            if (!entry.getValue().getType().equals(TYPE.REMOVED)) {
                Optional<?> oldValue = attrs.get(entry.getKey().getName());
                attrs.put(entry.getKey().getName(), entry.getValue().applyOn(oldValue));
            }
        }
        Set<Entry<Name, Optional<?>>> entries = attrs.entrySet();
        for (Iterator<Entry<Name, Optional<?>>> iterator = entries.iterator(); iterator.hasNext();) {
            Entry<Name, Optional<?>> entry = iterator.next();
            featureBuilder.set(entry.getKey(), entry.getValue().orNull());

        }

        SimpleFeature featureToInsert = featureBuilder.buildFeature(NodeRef.nodeFromPath(path));
        workTree.insert(NodeRef.parentPath(path), featureToInsert);

    }
    ImmutableList<FeatureTypeDiff> alteredTrees = patch.getAlteredTrees();
    for (FeatureTypeDiff diff : alteredTrees) {
        Optional<RevFeatureType> featureType;
        if (diff.getOldFeatureType().isNull()) {
            featureType = patch.getFeatureTypeFromId(diff.getNewFeatureType());
            workTree.createTypeTree(diff.getPath(), featureType.get().type());
        } else if (diff.getNewFeatureType().isNull()) {
            workTree.delete(diff.getPath());
        } else {
            featureType = patch.getFeatureTypeFromId(diff.getNewFeatureType());
            workTree.updateTypeTree(diff.getPath(), featureType.get().type());
        }
    }

}

From source file:com.facebook.buck.rust.RustCompileRule.java

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    buildableContext.recordArtifact(getOutput());
    return ImmutableList.of(new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir),
            new SymlinkFilesIntoDirectoryStep(getProjectFilesystem(), getProjectFilesystem().getRootPath(),
                    srcs.stream().map(getResolver()::getRelativePath).collect(MoreCollectors.toImmutableList()),
                    scratchDir),/*from w  w  w.  jav  a  2 s.  c  o m*/
            new MakeCleanDirectoryStep(getProjectFilesystem(),
                    getOutputDir(getBuildTarget(), getProjectFilesystem())),
            new ShellStep(getProjectFilesystem().getRootPath()) {

                @Override
                protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
                    ImmutableList<String> linkerCmd = linker.getCommandPrefix(getResolver());
                    ImmutableList.Builder<String> cmd = ImmutableList.builder();

                    Path src = scratchDir.resolve(getResolver().getRelativePath(rootModule));

                    cmd.addAll(compiler.getCommandPrefix(getResolver()))
                            .addAll(context.getAnsi().isAnsiTerminal() ? ImmutableList.of("--color=always")
                                    : ImmutableList.of())
                            .add(String.format("-Clinker=%s", linkerCmd.get(0)))
                            .addAll(processLinkerArgs(linkerCmd.subList(1, linkerCmd.size())))
                            .addAll(processLinkerArgs(Arg.stringify(linkerArgs))).addAll(Arg.stringify(args))
                            .add("-o", getOutput().toString()).add(src.toString());

                    return cmd.build();
                }

                /*
                 * Make sure all stderr output from rustc is emitted, since its either a warning or an
                 * error. In general Rust code should have zero warnings, or all warnings as errors.
                 * Regardless, respect requests for silence.
                 */
                @Override
                protected boolean shouldPrintStderr(Verbosity verbosity) {
                    return !verbosity.isSilent();
                }

                @Override
                public ImmutableMap<String, String> getEnvironmentVariables(ExecutionContext context) {
                    return compiler.getEnvironment();
                }

                @Override
                public String getShortName() {
                    return "rust-build";
                }

            });
}