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:net.awairo.mcmod.common.v1.client.gui.ToggleButton.java

private static ButtonContext getFirstFrom(Handler handler) {
    final ImmutableList<ButtonContext> context = handler.contexts();
    checkElementIndex(0, context.size());

    final int selected = handler.firstSelectedIndex();
    checkPositionIndex(selected, context.size());

    return context.get(selected);
}

From source file:net.techcable.pineapple.collect.ImmutableTables.java

public static <R, C, V> void forEach(ImmutableTable<R, C, V> table,
        TriConsumer<? super R, ? super C, ? super V> action) {
    ImmutableList<Table.Cell<R, C, V>> cellList = checkNotNull(table, "Null table").cellSet().asList();
    for (int i = 0; i < cellList.size(); i++) {
        Table.Cell<R, C, V> cell = cellList.get(i);
        R rowKey = cell.getRowKey();/*from  w w  w.  j  av a  2s  .c o  m*/
        C columnKey = cell.getColumnKey();
        V value = cell.getValue();
        checkNotNull(action, "Null action").accept(rowKey, columnKey, value);
    }
}

From source file:com.google.devtools.moe.client.github.PullRequestUrl.java

/**
 * Create from a URL string, throwing an {@link InvalidGithubUrl} exception if the supplied
 * URL is invalid./*  ww w.  j av  a2s.  c  om*/
 */
static PullRequestUrl create(URL url) {
    if (!url.getHost().equals("github.com")) {
        throw new InvalidGithubUrl("Pull request url is not a github.com url: '%s'", url);
    }
    ImmutableList<String> path = ImmutableList.copyOf(url.getPath().substring(1).split("/"));
    if (path.size() != 4 || !path.get(2).equals("pull")) {
        throw new InvalidGithubUrl("Invalid pull request URL: '%s'", url);
    }
    try {
        return new AutoValue_PullRequestUrl(path.get(0), path.get(1), Integer.parseInt(path.get(3)));
    } catch (NumberFormatException nfe) {
        throw new InvalidGithubUrl("Invalid pull request number '%s': '%s'", path.get(3), url);
    }
}

From source file:io.leishvl.core.util.LocaleUtils.java

/**
 * Obtains the locale that best-matches with the specified string.
 * @param str input string.//from  w  ww  .  java2  s  .  c o m
 * @return the locale that best-matches with the specified string, or {@code null}.
 */
public static @Nullable Locale getLocale(final @Nullable String str) {
    Locale locale = null;
    if (isNotBlank(str)) {
        final ImmutableList<Locale> locales = availableLocaleList();
        for (int i = 0; i < locales.size() && locale == null; i++) {
            final Locale item = locales.get(i);
            if (containsIgnoreCase(str, item.getDisplayCountry())) {
                locale = item;
            }
        }
    }
    return locale;
}

From source file:eu.eubrazilcc.lvl.core.util.LocaleUtils.java

/**
 * Obtains the locale that best-matches with the specified string.
 * @param str input string.//from  ww  w .j ava  2 s  . c o m
 * @return the locale that best-matches with the specified string, or {@code null}.
 */
public static @Nullable Locale getLocale(final @Nullable String str) {
    Locale locale = null;
    if (isNotBlank(str)) {
        final ImmutableList<Locale> locales = availableLocaleList();
        for (int i = 0; i < locales.size() && locale == null; i++) {
            final Locale item = locales.get(i);
            if (StringUtils.containsIgnoreCase(str, item.getDisplayCountry())) {
                locale = item;
            }
        }
    }
    return locale;
}

From source file:net.techcable.pineapple.collect.ImmutableSets.java

public static <T> void forEach(ImmutableSet<T> set, Consumer<T> consumer) {
    ImmutableList<T> list = checkNotNull(set, "Null set").asList();
    for (int i = 0; i < list.size(); i++) {
        consumer.accept(list.get(i));//ww  w  .j ava2s .c  om
    }
}

From source file:org.geogit.repository.SpatialOps.java

public static Envelope boundsOf(RevTree tree) {
    Envelope env = new Envelope();
    if (tree.buckets().isPresent()) {
        for (Bucket bucket : tree.buckets().get().values()) {
            bucket.expand(env);/*ww  w  . j  a  v  a  2 s.c  o  m*/
        }
    } else {
        if (tree.trees().isPresent()) {
            ImmutableList<Node> trees = tree.trees().get();
            for (int i = 0; i < trees.size(); i++) {
                trees.get(i).expand(env);
            }
        }
        if (tree.features().isPresent()) {
            ImmutableList<Node> trees = tree.features().get();
            for (int i = 0; i < trees.size(); i++) {
                trees.get(i).expand(env);
            }
        }
    }
    return env;
}

From source file:org.glowroot.local.store.QueryResult.java

static <T extends /*@NonNull*/Object> QueryResult<T> from(ImmutableList<T> records, int limit) {
    if (limit == 0) {
        return new QueryResult<T>(records, false);
    } else if (records.size() > limit) {
        return new QueryResult<T>(records.subList(0, limit), true);
    } else {/*from  www  .j  av  a  2s .  c o  m*/
        return new QueryResult<T>(records, false);
    }
}

From source file:com.google.devtools.build.lib.skyframe.AbstractFileSymlinkExceptionUniquenessValue.java

private static ImmutableList<RootedPath> canonicalize(ImmutableList<RootedPath> cycle) {
    int minPos = 0;
    String minString = cycle.get(0).toString();
    for (int i = 1; i < cycle.size(); i++) {
        String candidateString = cycle.get(i).toString();
        if (candidateString.compareTo(minString) < 0) {
            minPos = i;//from  w w w  .  ja va2s.  co  m
            minString = candidateString;
        }
    }
    ImmutableList.Builder<RootedPath> builder = ImmutableList.builder();
    for (int i = 0; i < cycle.size(); i++) {
        int pos = (minPos + i) % cycle.size();
        builder.add(cycle.get(pos));
    }
    return builder.build();
}

From source file:eu.eidas.auth.commons.io.MapSerializationHelper.java

public static <K, V> void writeKeyValueList(@Nonnull ObjectOutputStream oos,
        @Nonnull ImmutableList<KeyValue<K, V>> keyValueList) throws IOException {
    int kvSize = keyValueList.size();
    oos.writeInt(kvSize);//from  w w  w.ja v a  2s. com
    for (int i = 0; i < kvSize; i++) {
        KeyValue<K, V> keyValue = keyValueList.get(i);
        oos.writeObject(keyValue.getKey());
        oos.writeObject(keyValue.getValue());
    }
}