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:org.immutables.generator.processor.RunParser.java

public static void main(String... args) {

    Parser templateParser = Parboiled.createParser(Parser.class);
    ParsingResult<Object> result = new ReportingParseRunner<>(templateParser.Unit()).run(input2);

    ImmutableList<Object> copy = ImmutableList.copyOf(result.valueStack.iterator());

    if (!copy.isEmpty()) {
        Unit unit = (Unit) copy.get(0);

        Unit balance = Balancing.balance(unit);
        System.out.println(balance);
    }//from   w  ww  . ja v  a2 s .c o  m

    if (result.hasErrors()) {
        System.err.println(ErrorUtils.printParseErrors(result.parseErrors));
    }
    // System.out.println(ParseTreeUtils.printNodeTree(result));
}

From source file:unportant.gist.jep180.MemoryFootprint.java

public static void main(String[] args) {

    for (int count : ImmutableList.of(10, 100, 1000, 10000, 100000, 1000000)) {
        Collider djbCollider = Colliders.get(Colliders.DJBX31A);
        ImmutableList<String> strings = djbCollider.generate(count);

        {/*from  w  w w. j  a v  a2s  .c om*/
            HashMap<String, Object> map = new HashMap<String, Object>();
            for (String s : strings) {
                map.put(s, s);
            }

            System.out.println(count + " djb " + GraphLayout.parseInstance(map).totalSize());
        }

        {
            RandomStrings randomCollider = new RandomStrings();
            strings = randomCollider.generate(count, strings.get(0).length());

            HashMap<String, Object> map = new HashMap<String, Object>();
            for (String s : strings) {
                map.put(s, s);
            }

            System.out.println(count + " rnd " + GraphLayout.parseInstance(map).totalSize());
        }
    }
}

From source file:se.kth.climate.fast.netcdf.aligner.VariableFit.java

public static VariableFit fromDataDescriptors(ImmutableList<DataDescriptor> dds) {
    DataDescriptor firstDD = dds.get(0); // use first descriptor for records as that one has the largest number of records per variable
    ImmutableMap.Builder<String, Long> rfvb = ImmutableMap.builder();
    for (String varName : firstDD.vars) {
        rfvb.put(varName, firstDD.variableSize(varName));
    }//  w  w w  .jav  a2  s.c o m
    return new VariableFit(rfvb.build(), dds.size(), dds);
}

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  ww  w.  j ava  2  s  .c om
            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:com.google.devtools.build.lib.skyframe.ChainUniquenessUtils.java

private static ImmutableList<Object> canonicalize(ImmutableList<? extends Object> cycle) {
    int minPos = 0;
    String minString = cycle.get(0).toString();
    for (int i = 1; i < cycle.size(); i++) {
        // TOOD(bazel-team): Is the toString representation stable enough?
        String candidateString = cycle.get(i).toString();
        if (candidateString.compareTo(minString) < 0) {
            minPos = i;/*  ww w . j a  va  2  s . co  m*/
            minString = candidateString;
        }
    }
    ImmutableList.Builder<Object> 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:com.google.template.soy.jssrc.dsl.Statement.java

/** Creates a new code chunk representing the concatenation of the given statements. */
public static Statement of(Iterable<Statement> stmts) {
    ImmutableList<Statement> copy = ImmutableList.copyOf(stmts);
    return copy.size() == 1 ? copy.get(0) : StatementList.create(copy);
}

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

static PartialKey fromPb(DatastoreV1.Key keyPb) {
    String dataset = null;//from w  w  w  .  j a  va 2s.c o  m
    String namespace = null;
    if (keyPb.hasPartitionId()) {
        DatastoreV1.PartitionId partitionIdPb = keyPb.getPartitionId();
        if (partitionIdPb.hasDatasetId()) {
            dataset = 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(dataset, namespace, path);
    }
    return new PartialKey(dataset, namespace, path);
}

From source file:net.sf.lucis.core.support.Queryables.java

public static Queryable managed(Iterable<DirectoryProvider> providers) {
    ImmutableList<DirectoryProvider> list = ImmutableList.copyOf(providers);
    if (list.size() == 1) {
        return managed(list.get(0));
    }// w  ww.  jav  a2  s  .co m
    return new DefaultQueryable(ManagedMultiSearcherProvider.of(list));
}

From source file:com.teradata.tpcds.distribution.CalendarDistribution.java

public static int getMaxWeight(Weights weights) {
    ImmutableList<Integer> weightsList = getWeights(weights);
    return weightsList.get(weightsList.size() - 1);
}

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.//from  w  w w.ja va 2s  .co m
 */
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);
    }
}