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:com.google.enterprise.connector.ldap.JsonDocument.java

private static void extractAttributes(JSONObject jo, ImmutableMap.Builder<String, List<Value>> mapBuilder,
        String key) throws IllegalAccessError {
    JSONArray ja;//from   w w w .  ja  v a 2s  . c  o m
    try {
        ja = jo.getJSONArray(key);
    } catch (JSONException e) {
        LOG.warning("Skipping: " + key);
        return;
    }
    ImmutableList.Builder<Value> builder = new ImmutableList.Builder<Value>();
    for (int i = 0; i < ja.length(); i++) {
        String v;
        try {
            v = ja.getString(i);
        } catch (JSONException e) {
            LOG.warning("Skipping: " + key + " value: " + i);
            continue;
        }
        builder.add(Value.getStringValue(v));
    }
    ImmutableList<Value> l = builder.build();
    if (l.size() > 0) {
        mapBuilder.put(key, l);
    }
    return;
}

From source file:com.google.template.soy.jssrc.dsl.ObjectLiteral.java

static ObjectLiteral create(ImmutableList<? extends Expression> keys,
        ImmutableList<? extends Expression> values) {
    Preconditions.checkArgument(keys.size() == values.size(), "Mismatch between keys and values.");
    ImmutableList.Builder<Statement> initialStatements = ImmutableList.builder();
    for (Expression key : keys) {
        initialStatements.addAll(key.initialStatements());
    }/*from ww  w  . ja v a  2  s.  co m*/
    for (Expression value : values) {
        initialStatements.addAll(value.initialStatements());
    }
    return new AutoValue_ObjectLiteral(initialStatements.build(), keys, values);
}

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

static IncompleteKey fromPb(DatastoreV1.Key keyPb) {
    String projectId = null;/*from  www . ja v a2s  . 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.spectralogic.dsbrowser.gui.util.CancelJobsWorker.java

public static CancelAllTaskBySession cancelAllRunningJobsBySession(final JobWorkers jobWorkers,
        final JobInterruptionStore jobInterruptionStore, final Workers workers,
        final LoggingService loggingService) {
    final ImmutableList<Ds3JobTask> tasks = jobWorkers.getTasks().stream()
            .collect(GuavaCollectors.immutableList());
    if (tasks.size() != 0) {
        final CancelAllTaskBySession cancelAllRunningJobs = new CancelAllTaskBySession(tasks,
                jobInterruptionStore, loggingService);
        cancelAllRunningJobs.setOnSucceeded(SafeHandler.logHandle(event -> {
            if (cancelAllRunningJobs.getValue() != null) {
                LOG.info("Canceled job. {}", cancelAllRunningJobs.getValue());
            }/*from  w  ww  .  j  a  v a 2s . co m*/
        }));
        workers.execute(cancelAllRunningJobs);
        return cancelAllRunningJobs;
    } else {
        return null;
    }
}

From source file:org.apache.james.util.CompletableFutureUtil.java

public static <R, T> CompletableFuture<Stream<R>> chainAll(Stream<T> futureStream,
        Function<T, CompletableFuture<R>> transformationToChain) {
    ImmutableList<T> elements = futureStream.collect(ImmutableList.toImmutableList());
    ArrayList<R> results = new ArrayList<>(elements.size());

    CompletableFuture<Void> futureEmptyStream = CompletableFuture.completedFuture(null);

    BiFunction<CompletableFuture<?>, Supplier<CompletableFuture<R>>, CompletableFuture<?>> accumulator = (
            future, supplier) -> future.thenCompose(any -> supplier.get().thenAccept(results::add));

    BinaryOperator<CompletableFuture<?>> combiner = (f1, f2) -> f1.thenCompose(any -> f2);

    return elements.stream().map(t -> (Supplier<CompletableFuture<R>>) (() -> transformationToChain.apply(t)))
            .reduce(futureEmptyStream, accumulator, combiner).thenApply(any -> results.stream());
}

From source file:com.facebook.buck.lua.LuaInPlaceBinary.java

private static Supplier<String> getScript(final SourcePathResolver pathResolver, final Tool lua,
        final String mainModule, final Path relativeLinkTreeRoot) {
    final String relativeLinkTreeRootStr = Escaper.escapeAsPythonString(relativeLinkTreeRoot.toString());
    return new Supplier<String>() {
        @Override/*from  ww w. j  av a2  s  .  c  o  m*/
        public String get() {
            ImmutableList<String> luaCommand = lua.getCommandPrefix(pathResolver);
            Preconditions.checkArgument(luaCommand.size() == 1);
            return new ST(getRunInplaceResource()).add("SHEBANG", luaCommand.get(0))
                    .add("LUA", Escaper.escapeAsPythonString(luaCommand.get(0)))
                    .add("MAIN_MODULE", Escaper.escapeAsPythonString(mainModule))
                    .add("MODULES_DIR", relativeLinkTreeRootStr).render();
        }
    };
}

From source file:com.google.template.soy.jssrc.dsl.MapLiteral.java

static MapLiteral create(ImmutableList<? extends CodeChunk.WithValue> keys,
        ImmutableList<? extends CodeChunk.WithValue> values) {
    Preconditions.checkArgument(keys.size() == values.size(), "Mismatch between keys and values.");
    ImmutableSet.Builder<CodeChunk> initialStatements = ImmutableSet.builder();
    for (CodeChunk.WithValue key : keys) {
        initialStatements.addAll(key.initialStatements());
    }/*from ww  w  .j av a2s .  com*/
    for (CodeChunk.WithValue value : values) {
        initialStatements.addAll(value.initialStatements());
    }
    return new AutoValue_MapLiteral(initialStatements.build(), keys, values);
}

From source file:com.google.caliper.runner.ExperimentModule.java

private static Method findBenchmarkMethod(Class<?> benchmark, String methodName,
        ImmutableList<Class<?>> methodParameterClasses) {
    Class<?>[] params = methodParameterClasses.toArray(new Class[methodParameterClasses.size()]);
    try {// w  w  w .ja  v a  2 s . c  om
        return benchmark.getDeclaredMethod(methodName, params);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (SecurityException e) {
        // assertion error?
        throw new RuntimeException(e);
    }
}

From source file:com.google.api.codegen.discovery.DefaultString.java

/**
 * Returns whether the pattern represented by the list is in a form we expect.
 *
 * <p>A valid pattern must have the same number of literals and wildcards, alternating, and starts
 * with a literal. Literals must consists of only letters.
 *//*from   w  w  w.  j  a v a2  s .c o m*/
private static boolean validElems(ImmutableList<Elem> elems) {
    if (elems.size() % 2 != 0) {
        return false;
    }
    ImmutableList<ElemType> expect = ImmutableList.<ElemType>of(ElemType.LITERAL, ElemType.WILDCARD);
    for (int i = 0; i < elems.size(); i++) {
        if (elems.get(i).getType() != expect.get(i % expect.size())) {
            return false;
        }
    }
    for (int i = 0; i < elems.size(); i += 2) {
        for (char c : elems.get(i).getLiteral().toCharArray()) {
            if (!Character.isLetter(c)) {
                return false;
            }
        }
    }
    return true;
}

From source file:com.github.rinde.opt.localsearch.Schedule.java

static <C, T> Schedule<C, T> create(C context, ImmutableList<ImmutableList<T>> routes, IntList startIndices,
        RouteEvaluator<C, T> routeEvaluator) {
    final DoubleList costs = new DoubleArrayList(routes.size());
    double sumCost = 0;
    for (int i = 0; i < routes.size(); i++) {
        final double cost = routeEvaluator.computeCost(context, i, routes.get(i));
        costs.add(cost);//from   w  ww  .ja  v a 2s  . c o m
        sumCost += cost;
    }

    return new Schedule<C, T>(context, routes, IntLists.unmodifiable(new IntArrayList(startIndices)),
            DoubleLists.unmodifiable(costs), sumCost, routeEvaluator);
}