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

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

Introduction

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

Prototype

@GwtCompatible(serializable = true)
public static <E> ArrayList<E> newArrayListWithExpectedSize(int estimatedSize) 

Source Link

Document

Creates an ArrayList instance to hold estimatedSize elements, plus an unspecified amount of padding; you almost certainly mean to call #newArrayListWithCapacity (see that method for further advice on usage).

Usage

From source file:org.carrot2.core.ClusterWithParent.java

/**
 * Wraps a list of top level clusters. Each cluster in the list will be assumed to
 * have a <code>null</code> parent cluster. Note that for efficiency reasons,
 * reference cycles are <strong>not</strong> detected.
 * //from   w w w.j  a va 2s  .c  o m
 * @param clusters the list of top-level clusters to be wrapped
 * @return the wrapped clusters with parents
 */
public static List<ClusterWithParent> wrap(List<Cluster> clusters) {
    final List<ClusterWithParent> result = Lists.newArrayListWithExpectedSize(clusters.size());

    for (Cluster cluster : clusters) {
        result.add(wrap(cluster));
    }

    return result;
}

From source file:com.romeikat.datamessie.core.domain.enums.DocumentProcessingState.java

public static List<DocumentProcessingState> getSuccessStatesFor(final DocumentProcessingState state) {
    final List<DocumentProcessingState> states = Lists.newArrayListWithExpectedSize(4);

    // Add one after another in the right order until the desired state occurs
    final List<DocumentProcessingState> successStates = getSuccessStates();
    Collections.reverse(successStates);
    for (final DocumentProcessingState successState : successStates) {
        states.add(successState);//w w  w  .ja  v a  2  s  . co  m
        if (state == successState) {
            return states;
        }
    }

    return states;
}

From source file:com.google.gerrit.server.change.Revisions.java

@Override
public RevisionResource parse(ChangeResource change, IdString id)
        throws ResourceNotFoundException, OrmException {
    if (id.equals("current")) {
        PatchSet.Id p = change.getChange().currentPatchSetId();
        PatchSet ps = p != null ? dbProvider.get().patchSets().get(p) : null;
        if (ps != null && visible(change, ps)) {
            return new RevisionResource(change, ps);
        }/* w  w  w  .  j ava  2 s . c om*/
        throw new ResourceNotFoundException(id);
    }
    List<PatchSet> match = Lists.newArrayListWithExpectedSize(2);
    for (PatchSet ps : find(change, id.get())) {
        Change.Id changeId = ps.getId().getParentKey();
        if (changeId.equals(change.getChange().getId()) && visible(change, ps)) {
            match.add(ps);
        }
    }
    if (match.size() != 1) {
        throw new ResourceNotFoundException(id);
    }
    return new RevisionResource(change, match.get(0));
}

From source file:com.google.jstestdriver.model.JstdTestCaseFactory.java

private List<JstdTestCase> resolveDependencies(List<JstdTestCase> testCases) {
    stopWatch.start("resolveDependencies");
    try {// w  w  w.j  a  v  a 2s.  c  o m
        final List<JstdTestCase> resolved = Lists.newArrayListWithExpectedSize(testCases.size());
        for (JstdTestCase jstdTestCase : testCases) {
            for (ResourceDependencyResolver resolver : resolvers) {
                stopWatch.start(resolver.toString());
                jstdTestCase = resolver.resolve(jstdTestCase);
                stopWatch.stop(resolver.toString());
            }
            resolved.add(jstdTestCase);
        }
        return resolved;
    } finally {
        stopWatch.stop("resolveDependencies");
    }
}

From source file:org.apache.bookkeeper.stream.storage.impl.sc.LocalStorageContainerManager.java

@Override
protected void doStop() {
    List<CompletableFuture<Void>> futures = Lists.newArrayListWithExpectedSize(numStorageContainers);
    for (int scId = 0; scId < numStorageContainers; scId++) {
        futures.add(this.registry.stopStorageContainer(scId));
    }/*from ww  w . ja  v  a2s. com*/
    FutureUtils.collect(futures).join();
}

From source file:org.apache.rave.rest.impl.DefaultWidgetsResource.java

private List<Widget> convert(List<org.apache.rave.model.Widget> resultSet) {
    List<Widget> widgets = Lists.newArrayListWithExpectedSize(resultSet.size());
    for (org.apache.rave.model.Widget widget : resultSet) {
        widgets.add(new Widget(widget));
    }//w w w.j  a va  2s.  c o m
    return widgets;
}

From source file:eu.interedition.collatex.input.SimpleWitness.java

public void setTokenContents(List<String> tokenContents) {
    final List<Token> tokens = Lists.newArrayListWithExpectedSize(tokenContents.size());
    for (String content : tokenContents) {
        tokens.add(new SimpleToken(this, tokens.size(), content, TOKEN_NORMALIZER.apply(content)));
    }/*from  w ww .  ja v a  2s . c  o m*/
    setTokens(tokens);
}

From source file:org.sakaiproject.nakamura.solr.Utils.java

public static String[] toStringArray(Object property, String[] defaultArray) {
    if (property == null) {
        return defaultArray;

    } else if (property instanceof String && !((String) property).isEmpty()) {
        return ((String) property).split("\\|");

    } else if (property instanceof String[]) {
        // String[]
        return (String[]) property;

    } else if (property.getClass().isArray()) {
        // other array
        Object[] valueArray = (Object[]) property;
        List<String> values = Lists.newArrayListWithExpectedSize(valueArray.length);
        for (Object value : valueArray) {
            if (value != null) {
                values.add(value.toString());
            }/* w  w  w.ja v a2 s . com*/
        }
        return values.toArray(new String[values.size()]);

    } else if (property instanceof Collection<?>) {
        // collection
        Collection<?> valueCollection = (Collection<?>) property;
        List<String> valueList = Lists.newArrayListWithExpectedSize(valueCollection.size());
        for (Object value : valueCollection) {
            if (value != null) {
                valueList.add(value.toString());
            }
        }
        return valueList.toArray(new String[valueList.size()]);
    }

    return defaultArray;
}

From source file:com.arpnetworking.tsdcore.sinks.LimitingSink.java

/**
 * {@inheritDoc}//  ww w.ja  v  a2 s  .c  o  m
 */
@Override
public void recordAggregateData(final Collection<AggregatedData> data, final Collection<Condition> conditions) {
    final DateTime now = DateTime.now();
    final List<AggregatedData> filteredData = Lists.newArrayListWithExpectedSize(data.size());
    final Map<FQDSN, Condition> conditionsByFQDSN = Maps.uniqueIndex(conditions,
            new Function<Condition, FQDSN>() {
                @Override
                public FQDSN apply(final Condition condition) {
                    return condition.getFQDSN();
                }
            });
    long limited = 0;
    for (final AggregatedData datum : data) {
        if (_metricsLimiter.offer(datum, now)) {
            filteredData.add(datum);
        } else {
            LOGGER.warn(String.format("%s: Skipping publication of limited data; aggregatedData=%s", getName(),
                    datum));
            ++limited;

            // Remove any condition for the FQDSN
            // NOTE: Although limiting also contains period, the data produced
            // in any one invocation of the sink is for a single period we can
            // safely ignore that and find any matching conditions by FQDSN.
            conditionsByFQDSN.remove(datum.getFQDSN());
        }
    }
    _limited.getAndAdd(limited);
    _sink.recordAggregateData(filteredData, conditionsByFQDSN.values());
}

From source file:sg.atom.utils.datastructure.parser.JSONParser.java

@Override
public Map<String, Object> parse(String input) throws FormattedException {
    try {/* www. jav a  2s.  c o  m*/
        Map<String, Object> map = new LinkedHashMap<String, Object>();
        JsonNode root = jsonMapper.readTree(input);

        Iterator<String> keysIter = (fieldNames == null ? root.fieldNames() : fieldNames.iterator());

        while (keysIter.hasNext()) {
            String key = keysIter.next();
            JsonNode node = root.path(key);

            if (node.isArray()) {
                final List<String> nodeValue = Lists.newArrayListWithExpectedSize(node.size());
                for (final JsonNode subnode : node) {
                    final String subnodeValue = valueFunction.apply(subnode);
                    if (subnodeValue != null) {
                        nodeValue.add(subnodeValue);
                    }
                }
                map.put(key, nodeValue);
            } else {
                final String nodeValue = valueFunction.apply(node);
                if (nodeValue != null) {
                    map.put(key, nodeValue);
                }
            }
        }
        return map;
    } catch (Exception e) {
        Throwables.propagateIfPossible(e, FormattedException.class);
        throw new FormattedException.Builder().withErrorCode(FormattedException.ErrorCode.UNPARSABLE_ROW)
                .withMessage(e.getMessage()).build();
    }
}