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

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

Introduction

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

Prototype

int size();

Source Link

Document

Returns the number of elements in this list.

Usage

From source file:org.jclouds.compute.functions.NodeAndTemplateOptionsToStatementWithoutPublicKey.java

@Override
public Statement apply(NodeMetadata node, TemplateOptions options) {
    ImmutableList.Builder<Statement> builder = ImmutableList.builder();
    if (options.getRunScript() != null) {
        builder.add(options.getRunScript());
    }/*ww  w.ja v a 2  s.c  o  m*/
    if (options.getPrivateKey() != null) {
        builder.add(new InstallRSAPrivateKey(options.getPrivateKey()));
    }

    ImmutableList<Statement> bootstrap = builder.build();
    if (!bootstrap.isEmpty()) {
        if (options.getTaskName() == null && !(options.getRunScript() instanceof InitScript)) {
            options.nameTask("bootstrap");
        }
        return bootstrap.size() == 1 ? bootstrap.get(0) : new StatementList(bootstrap);
    }

    return null;
}

From source file:com.facebook.buck.simulate.BuildSimulator.java

public SimulateReport simulateBuild(long currentTimeMillis, ImmutableList<BuildTarget> buildTargets) {
    Preconditions.checkArgument(buildTargets.size() > 0, "No targets provided for the simulation.");
    SimulateReport.Builder simulateReport = SimulateReport.builder();

    for (String timeAggregate : times.getTimeAggregates()) {
        // Setup the build order.
        Map<BuildTarget, NodeState> reverseDependencies = Maps.newHashMap();
        Queue<BuildTarget> leafNodes = Queues.newArrayDeque();
        int totalDagEdges = 0;
        for (BuildTarget target : buildTargets) {
            BuildRule rule;/*w  w w  .  j  ava2 s. com*/
            try {
                rule = resolver.requireRule(target);
            } catch (NoSuchBuildTargetException e) {
                throw new HumanReadableException(e.getHumanReadableErrorMessage());
            }

            totalDagEdges += recursiveTraversal(rule, reverseDependencies, leafNodes);
        }

        SingleRunReport.Builder report = SingleRunReport.builder().setTimestampMillis(currentTimeMillis)
                .setBuildTargets(FluentIterable.from(buildTargets).transform(Functions.toStringFunction()))
                .setSimulateTimesFile(times.getFile())
                .setRuleFallbackTimeMillis(times.getRuleFallbackTimeMillis())
                .setTotalActionGraphNodes(Iterables.size(actionGraph.getNodes()))
                .setTimeAggregate(timeAggregate).setNumberOfThreads(numberOfThreads);

        report.setTotalDependencyDagEdges(totalDagEdges);

        // Run the simulation.
        simulateReport.addRunReports(runSimulation(report, reverseDependencies, leafNodes, timeAggregate));
    }

    return simulateReport.build();
}

From source file:org.jclouds.digitalocean.compute.functions.TemplateOptionsToStatementWithoutPublicKey.java

@Override
public Statement apply(TemplateOptions options) {
    ImmutableList.Builder<Statement> builder = ImmutableList.builder();
    if (options.getRunScript() != null) {
        builder.add(options.getRunScript());
    }// ww w.jav  a 2  s .co  m
    if (options.getPrivateKey() != null) {
        builder.add(new InstallRSAPrivateKey(options.getPrivateKey()));
    }

    ImmutableList<Statement> bootstrap = builder.build();
    if (!bootstrap.isEmpty()) {
        if (options.getTaskName() == null && !(options.getRunScript() instanceof InitScript)) {
            options.nameTask("bootstrap");
        }
        return bootstrap.size() == 1 ? bootstrap.get(0) : new StatementList(bootstrap);
    }

    return null;
}

From source file:com.facebook.buck.query.AbstractBinaryOperatorExpression.java

@Override
ImmutableSet<QueryTarget> eval(QueryEvaluator evaluator, QueryEnvironment env) throws QueryException {
    ImmutableList<QueryExpression> operands = getOperands();
    Set<QueryTarget> lhsValue = new LinkedHashSet<>(evaluator.eval(operands.get(0), env));

    for (int i = 1; i < operands.size(); i++) {
        Set<QueryTarget> rhsValue = evaluator.eval(operands.get(i), env);
        switch (getOperator()) {
        case INTERSECT:
            lhsValue.retainAll(rhsValue);
            break;
        case UNION:
            lhsValue.addAll(rhsValue);//w w  w  .  ja  v  a2s. c o  m
            break;
        case EXCEPT:
            lhsValue.removeAll(rhsValue);
            break;
        default:
            throw new IllegalStateException("operator=" + getOperator());
        }
    }
    return ImmutableSet.copyOf(lhsValue);
}

From source file:guru.qas.martini.DefaultMixologist.java

protected Collection<Martini> getMartinis(Expression expression) {
    StandardEvaluationContext context = new StandardEvaluationContext();
    List<MethodResolver> methodResolvers = context.getMethodResolvers();
    ArrayList<MethodResolver> modifiedList = Lists.newArrayList(methodResolvers);
    modifiedList.add(new TagResolver(this.context, categories));
    context.setMethodResolvers(modifiedList);

    ImmutableList<Martini> martinis = getMartinis();
    List<Martini> matches = Lists.newArrayListWithCapacity(martinis.size());
    for (Martini martini : martinis) {
        Boolean match = expression.getValue(context, martini, Boolean.class);
        if (null != match && match) {
            matches.add(martini);/* ww w  . j av a2s.  co m*/
        }
    }
    return matches;
}

From source file:org.jenkinsci.plugins.workflow.support.concurrent.ListFuture.java

private void init(final Executor listenerExecutor) {
    // First, schedule cleanup to execute when the Future is done.
    addListener(new Runnable() {
        @Override/*ww  w.  ja v a  2s.co  m*/
        public void run() {
            // By now the values array has either been set as the Future's value,
            // or (in case of failure) is no longer useful.
            ListFuture.this.values = null;

            // Let go of the memory held by other futures
            ListFuture.this.futures = null;
        }
    }, MoreExecutors.sameThreadExecutor());

    // Now begin the "real" initialization.

    // Corner case: List is empty.
    if (futures.isEmpty()) {
        set(Lists.newArrayList(values));
        return;
    }

    // Populate the results list with null initially.
    for (int i = 0; i < futures.size(); ++i) {
        values.add(null);
    }

    // Register a listener on each Future in the list to update
    // the state of this future.
    // Note that if all the futures on the list are done prior to completing
    // this loop, the last call to addListener() will callback to
    // setOneValue(), transitively call our cleanup listener, and set
    // this.futures to null.
    // We store a reference to futures to avoid the NPE.
    ImmutableList<? extends ListenableFuture<? extends V>> localFutures = futures;
    for (int i = 0; i < localFutures.size(); i++) {
        final ListenableFuture<? extends V> listenable = localFutures.get(i);
        final int index = i;
        listenable.addListener(new Runnable() {
            @Override
            public void run() {
                setOneValue(index, listenable);
            }
        }, listenerExecutor);
    }
}

From source file:net.tzolov.geode.jmx.JmxInfluxLoader.java

private String[] attributeNames(MBeanServerConnection connection, String objectName,
        MBeanAttributeInfoFilter attributeFilter) {

    try {/*from  ww w .  j  a v  a 2  s .  co m*/
        ImmutableList.Builder<String> builder = ImmutableList.builder();
        for (MBeanAttributeInfo attr : connection.getMBeanInfo(new ObjectName(objectName)).getAttributes()) {
            if (!attributeFilter.filter(attr)) {
                builder.add(attr.getName());
            }
        }
        ImmutableList<String> names = builder.build();
        return names.toArray(new String[names.size()]);
    } catch (Exception ex) {
        throw new RuntimeException((ex));
    }
}

From source file:no.ssb.vtl.script.operations.join.InnerJoinMerger.java

private ImmutableListMultimap<Integer, Integer> buildIndices(ImmutableList<Component> leftList,
        ImmutableList<Component> rightList) {
    ImmutableListMultimap.Builder<Integer, Integer> indexMapBuilder = ImmutableListMultimap.builder();
    // Save the indices of the right data points that need to be moved to the left.
    for (int i = 0; i < rightList.size(); i++) {
        Component rightComponent = rightList.get(i);
        for (int j = 0; j < leftList.size(); j++) {
            Component leftComponent = leftList.get(j);
            if (rightComponent.equals(leftComponent)) {
                indexMapBuilder.put(i, j);
            }/*from   www .  j  a  v a  2  s . c om*/
        }
    }
    return indexMapBuilder.build();
}

From source file:google.registry.flows.domain.DomainFlowTmchUtils.java

public SignedMark verifySignedMarks(ImmutableList<AbstractSignedMark> signedMarks, String domainLabel,
        DateTime now) throws EppException {
    if (signedMarks.size() > 1) {
        throw new TooManySignedMarksException();
    }//from   ww  w  .  j  ava 2 s .  c o  m
    if (!(signedMarks.get(0) instanceof EncodedSignedMark)) {
        throw new SignedMarksMustBeEncodedException();
    }
    return verifyEncodedSignedMark((EncodedSignedMark) signedMarks.get(0), domainLabel, now);
}

From source file:org.xlrnet.tibaija.commands.math.BinaryCommand.java

/**
 * Apply the internal function if they both operands are lists and have the same length. Each i-th element of the
 * left list will be applied to the i-th element of the right list to build the i-th element of the result list.
 *
 * @param lhs//  w  ww  .j a  v a 2s. c om
 *         Left side of the expression
 * @param rhs
 *         Right side of the expression.
 * @return A new Value object with the internal function applied to it.
 */
@NotNull
private Value applyOnBothList(@NotNull Value lhs, @NotNull Value rhs) {
    final ImmutableList<Complex> leftList = lhs.list();
    final ImmutableList<Complex> rightList = rhs.list();

    if (leftList.size() != rightList.size())
        throw new TIArgumentException("Mismatching dimensions: " + leftList.size() + " - " + rightList.size(),
                lhs, rhs);

    List<Complex> resultList = new ArrayList<>(leftList.size());
    for (int i = 0; i < leftList.size(); i++)
        resultList
                .add(evaluationFunction.apply(Value.of(leftList.get(i)), Value.of(rightList.get(i))).complex());
    return Value.of(resultList);
}