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: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();
    }// w w w  . j  av a 2 s  .  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.mycompany.mavenproject3.List.java

public static Cons makeCons(ImmutableList<Sexpression> list) {
    if (list.isEmpty()) {
        return new Nil();
    } else if (list.size() == 1) {
        return new Cons(list.get(0), new Nil());
    } else {/*from  ww w . j  a  v  a 2  s  .c  o  m*/
        Sexpression head = list.get(0);
        ImmutableList<Sexpression> tail = list.subList(1, list.size() - 1);
        return new Cons(head, makeCons(tail));
    }
}

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

public static <T, U> ImmutableSet<U> transform(ImmutableSet<T> set, Function<T, U> transformer) {
    ImmutableSet.Builder<U> resultBuilder = builder(checkNotNull(set, "Null set").size());
    ImmutableList<T> list = set.asList();
    for (int i = 0; i < list.size(); i++) {
        T oldElement = list.get(i);
        U newElement = checkNotNull(transformer, "Null transformer").apply(oldElement);
        if (newElement == null)
            throw new NullPointerException(
                    "Transformer  " + transformer.getClass().getTypeName() + " returned null.");
        resultBuilder.add(newElement);/*www. java  2 s  .  c o m*/
    }
    return resultBuilder.build();
}

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

static IncompleteKey fromPb(DatastoreV1.Key keyPb) {
    String projectId = null;//  www  .ja  v a2 s .co 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:elaborate.editor.model.ModelFactory.java

public static TranscriptionType getDefaultTranscriptionType() {
    ImmutableList<TranscriptionType> entities = transcriptionService.getTranscriptionTypes();
    return entities.size() > 0 ? entities.get(0)
            : create(TranscriptionType.class).setName(TranscriptionType.DIPLOMATIC);
}

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);//w ww  .j  a  v a 2s .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: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));
    }/*from  w w  w .  ja v  a 2 s  . c  o  m*/
}

From source file:com.google.security.zynamics.binnavi.Gui.GraphWindows.types.TypeEditorSearchPanel.java

private static void scrollToMatch(int matchIndex, final ImmutableList<Integer> matches, final TypesTree tree) {
    tree.scrollRowToVisible(matches.get(matchIndex));
}

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();/*w w  w  .j a  v a2 s  .c o m*/
        C columnKey = cell.getColumnKey();
        V value = cell.getValue();
        checkNotNull(action, "Null action").accept(rowKey, columnKey, value);
    }
}

From source file:com.google.template.soy.types.ast.UnionTypeNode.java

public static UnionTypeNode create(Iterable<TypeNode> candidates) {
    ImmutableList<TypeNode> candidateList = ImmutableList.copyOf(candidates);
    Preconditions.checkArgument(candidateList.size() > 1);
    return new AutoValue_UnionTypeNode(
            candidateList.get(0).sourceLocation().extend(Iterables.getLast(candidateList).sourceLocation()),
            candidateList);//from  w  w  w. jav a  2  s.  c o m
}