Example usage for com.google.common.collect Lists newArrayListWithCapacity

List of usage examples for com.google.common.collect Lists newArrayListWithCapacity

Introduction

In this page you can find the example usage for com.google.common.collect Lists newArrayListWithCapacity.

Prototype

@GwtCompatible(serializable = true)
public static <E> ArrayList<E> newArrayListWithCapacity(int initialArraySize) 

Source Link

Document

Creates an ArrayList instance backed by an array with the specified initial size; simply delegates to ArrayList#ArrayList(int) .

Usage

From source file:org.apache.mahout.cf.taste.impl.common.RefreshHelper.java

/**
 * @param refreshRunnable/*from  w ww . j  a v  a 2 s  .  c  o m*/
 *          encapsulates the containing object's own refresh logic
 */
public RefreshHelper(Callable<?> refreshRunnable) {
    this.dependencies = Lists.newArrayListWithCapacity(3);
    this.refreshLock = new ReentrantLock();
    this.refreshRunnable = refreshRunnable;
}

From source file:org.apache.solr.handler.clustering.carrot2.EchoClusteringAlgorithm.java

@Override
public void process() throws ProcessingException {
    clusters = Lists.newArrayListWithCapacity(documents.size());

    for (Document document : documents) {
        final Cluster cluster = new Cluster();
        cluster.addPhrases(document.getTitle(), document.getSummary());
        if (document.getLanguage() != null) {
            cluster.addPhrases(document.getLanguage().name());
        }/* w w w .ja  v a2 s . c  o  m*/
        for (String field : customFields.split(",")) {
            Object value = document.getField(field);
            if (value != null) {
                cluster.addPhrases(value.toString());
            }
        }
        cluster.addDocuments(document);
        clusters.add(cluster);
    }
}

From source file:io.druid.query.select.SelectResultValueBuilder.java

public Result<SelectResultValue> build() {
    // Pull out top aggregated values
    List<EventHolder> values = Lists.newArrayListWithCapacity(pQueue.size());
    Map<String, Integer> pagingIdentifiers = Maps.newLinkedHashMap();
    while (!pQueue.isEmpty()) {
        EventHolder event = pQueue.remove();
        pagingIdentifiers.put(event.getSegmentId(), event.getOffset());
        values.add(event);//  ww  w .  j  a  v  a2 s  .  c om
    }

    return new Result<SelectResultValue>(timestamp, new SelectResultValue(pagingIdentifiers, values));
}

From source file:com.github.steveash.jg2p.align.AlignerInferencer.java

private List<Alignment> createAlignments(Word x, PathXTable t, int bestPathCount) {
    List<Alignment> results = Lists.newArrayListWithCapacity(bestPathCount);

    Iterable<PathXTable.Entry> lastEntries = t.get(x.unigramCount());

    for (PathXTable.Entry lastEntry : lastEntries) {
        if (lastEntry.score < ProbTable.minLogProb) {
            continue;
        }/*from w  w w.ja va 2  s .co  m*/

        results.add(decodePathFrom(x, t, lastEntry));
    }
    Collections.sort(results, Ordering.natural().reverse());
    return results;
}

From source file:com.opengamma.web.analytics.formatting.BlackVolatilitySurfaceMoneynessFcnBackedByGridFormatter.java

private Object formatExpanded(BlackVolatilitySurfaceMoneynessFcnBackedByGrid value) {
    SmileSurfaceDataBundle gridData = value.getGridData();
    Set<Double> strikes = new TreeSet<Double>();
    for (double[] outer : gridData.getStrikes()) {
        for (double inner : outer) {
            strikes.add(inner);//  www.j a v a2s .  c  om
        }
    }
    List<Double> vol = Lists.newArrayList();
    // x values (outer loop of vol) strikes
    // y values (inner loop of vol) expiries
    List<Double> expiries = Lists.newArrayListWithCapacity(gridData.getExpiries().length);
    for (double expiry : gridData.getExpiries()) {
        expiries.add(expiry);
    }
    for (Double strike : strikes) {
        for (Double expiry : expiries) {
            vol.add(value.getVolatility(expiry, strike));
        }
    }
    Map<String, Object> results = Maps.newHashMap();
    results.put(SurfaceFormatterUtils.X_VALUES, expiries);
    results.put(SurfaceFormatterUtils.X_LABELS, SurfaceFormatterUtils.getAxisLabels(expiries));
    results.put(SurfaceFormatterUtils.X_TITLE, "Time to Expiry");
    results.put(SurfaceFormatterUtils.Y_VALUES, strikes);
    results.put(SurfaceFormatterUtils.Y_LABELS, SurfaceFormatterUtils.getAxisLabels(strikes));
    results.put(SurfaceFormatterUtils.Y_TITLE, "Strike");
    results.put(SurfaceFormatterUtils.VOL, vol);
    return results;
}

From source file:com.android.build.tests.AndroidProjectConnector.java

public void runGradleTasks(@NonNull File project, @NonNull String gradleVersion,
        @NonNull List<String> arguments, @NonNull Map<String, String> jvmDefines, @NonNull String... tasks)
        throws IOException, StreamException {
    File localProp = createLocalProp(project);

    try {//from ww  w . j  av  a 2  s . c o m
        GradleConnector connector = GradleConnector.newConnector();

        ProjectConnection connection = connector.useGradleVersion(gradleVersion).forProjectDirectory(project)
                .connect();
        try {
            List<String> args = Lists.newArrayListWithCapacity(2 + arguments.size());
            args.add("-i");
            args.add("-u");
            args.addAll(arguments);

            BuildLauncher build = connection.newBuild().forTasks(tasks)
                    .withArguments(args.toArray(new String[args.size()]));

            if (!jvmDefines.isEmpty()) {
                String[] jvmArgs = new String[jvmDefines.size()];
                int index = 0;
                for (Map.Entry<String, String> entry : jvmDefines.entrySet()) {
                    jvmArgs[index++] = "-D" + entry.getKey() + "=" + entry.getValue();
                }

                build.setJvmArguments(jvmArgs);
            }

            build.run();
        } finally {
            connection.close();
        }
    } finally {
        localProp.delete();
    }
}

From source file:org.terasology.persistence.typeHandling.coreTypes.BooleanTypeHandler.java

@Override
public List<Boolean> deserializeCollection(PersistedData data, DeserializationContext context) {
    if (data.isArray()) {
        PersistedDataArray array = data.getAsArray();
        List<Boolean> result = Lists.newArrayListWithCapacity(array.size());
        for (PersistedData item : array) {
            if (item.isBoolean()) {
                result.add(item.getAsBoolean());
            } else {
                result.add(null);/*from  ww  w.j  av a  2 s  .c  om*/
            }
        }
        return result;
    }
    return Lists.newArrayList();
}

From source file:org.grouplens.lenskit.eval.data.CSVRatingWriter.java

@Override
public void writeRating(Rating r) throws IOException {
    List<Object> row = Lists.newArrayListWithCapacity(4);
    row.add(r.getUserId());/*from   ww w.  java  2s. co m*/
    row.add(r.getItemId());
    Preference p = r.getPreference();
    if (p == null) {
        row.add(null);
    } else {
        row.add(p.getValue());
    }
    if (includeTimestamps) {
        row.add(r.getTimestamp());
    }
    tableWriter.writeRow(row);
}

From source file:org.apache.shindig.gadgets.rewrite.ProxyingVisitor.java

@Override
protected Collection<Pair<Node, Uri>> mutateUris(Gadget gadget, Collection<Node> nodes) {
    List<ProxyUriManager.ProxyUri> reservedUris = Lists.newArrayListWithCapacity(nodes.size());
    List<Node> reservedNodes = Lists.newArrayListWithCapacity(nodes.size());

    for (Node node : nodes) {
        Element element = (Element) node;
        String nodeName = node.getNodeName().toLowerCase();
        String uriStr = element.getAttribute(resourceTags.get(nodeName)).trim();
        try {//ww w .  j  a  v a 2 s.  com
            ProxyUriManager.ProxyUri proxiedUri = new ProxyUriManager.ProxyUri(gadget, Uri.parse(uriStr));

            // Set the html tag context as the current node being processed.
            proxiedUri.setHtmlTagContext(nodeName);
            reservedUris.add(proxiedUri);
            reservedNodes.add(node);
        } catch (UriException e) {
            // Uri parse exception, ignore.
            logger.log(Level.WARNING, "Uri exception when parsing: " + uriStr, e);
        }
    }

    List<Uri> resourceUris = uriManager.make(reservedUris, featureConfig.getExpires());

    // By contract, resourceUris matches by index with inbound Uris. Create an easy-access
    // List with the results.
    List<Pair<Node, Uri>> proxiedUris = Lists.newArrayListWithCapacity(nodes.size());

    Iterator<Uri> uriIt = resourceUris.iterator();
    for (Node node : reservedNodes) {
        proxiedUris.add(Pair.of(node, uriIt.next()));
    }

    return proxiedUris;
}

From source file:com.google.template.soy.soytree.SwitchCaseNode.java

/**
 * Copy constructor./*w w  w. j a  v  a2  s  .  c  o  m*/
 * @param orig The node to copy.
 */
private SwitchCaseNode(SwitchCaseNode orig, CopyState copyState) {
    super(orig, copyState);
    this.exprListText = orig.exprListText;
    this.exprList = Lists.newArrayListWithCapacity(orig.exprList.size());
    for (ExprRootNode origExpr : orig.exprList) {
        this.exprList.add(origExpr.copy(copyState));
    }
}