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:com.google.gerrit.server.query.change.IsStarredByPredicate.java

private static List<Predicate<ChangeData>> predicates(Schema<ChangeData> schema, Set<Change.Id> ids) {
    List<Predicate<ChangeData>> r = Lists.newArrayListWithCapacity(ids.size());
    for (Change.Id id : ids) {
        r.add(new LegacyChangeIdPredicate(schema, id));
    }/*from   ww w.j a v a  2  s.  c  om*/
    return r;
}

From source file:org.apache.tez.dag.utils.RelocalizationUtils.java

public static List<URL> processAdditionalResources(Map<String, URI> additionalResources, Configuration conf,
        String destDir) throws IOException, TezException {
    if (additionalResources == null || additionalResources.isEmpty()) {
        return Collections.emptyList();
    }//from ww w .j a va  2s . c o  m

    List<URL> urls = Lists.newArrayListWithCapacity(additionalResources.size());

    for (Entry<String, URI> lrEntry : additionalResources.entrySet()) {
        Path dFile = downloadResource(lrEntry.getKey(), lrEntry.getValue(), conf, destDir);
        urls.add(dFile.toUri().toURL());
    }
    return urls;
}

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

/**
 * Utility to create a list of {@code ExprUnion}s from a list of expression trees.
 * @param exprs The list of expression trees.
 * @return A new list of corresponding {@code ExprUnion}s.
 *//* www.j ava 2  s. co  m*/
public static List<ExprUnion> createList(List<? extends ExprRootNode> exprs) {
    List<ExprUnion> exprUnions = Lists.newArrayListWithCapacity(exprs.size());
    for (ExprRootNode expr : exprs) {
        exprUnions.add(new ExprUnion(expr));
    }
    return exprUnions;
}

From source file:org.apache.hadoop.fs.permission.AclUtil.java

/**
 * Given permissions and extended ACL entries, returns the full logical ACL.
 *
 * @param perm FsPermission containing permissions
 * @param entries List<AclEntry> containing extended ACL entries
 * @return List<AclEntry> containing full logical ACL
 */// w w  w.  j a  v a  2  s.c  o m
public static List<AclEntry> getAclFromPermAndEntries(FsPermission perm, List<AclEntry> entries) {
    List<AclEntry> acl = Lists.newArrayListWithCapacity(entries.size() + 3);

    // Owner entry implied by owner permission bits.
    acl.add(new AclEntry.Builder().setScope(AclEntryScope.ACCESS).setType(AclEntryType.USER)
            .setPermission(perm.getUserAction()).build());

    // All extended access ACL entries.
    boolean hasAccessAcl = false;
    Iterator<AclEntry> entryIter = entries.iterator();
    AclEntry curEntry = null;
    while (entryIter.hasNext()) {
        curEntry = entryIter.next();
        if (curEntry.getScope() == AclEntryScope.DEFAULT) {
            break;
        }
        hasAccessAcl = true;
        acl.add(curEntry);
    }

    // Mask entry implied by group permission bits, or group entry if there is
    // no access ACL (only default ACL).
    acl.add(new AclEntry.Builder().setScope(AclEntryScope.ACCESS)
            .setType(hasAccessAcl ? AclEntryType.MASK : AclEntryType.GROUP).setPermission(perm.getGroupAction())
            .build());

    // Other entry implied by other bits.
    acl.add(new AclEntry.Builder().setScope(AclEntryScope.ACCESS).setType(AclEntryType.OTHER)
            .setPermission(perm.getOtherAction()).build());

    // Default ACL entries.
    if (curEntry != null && curEntry.getScope() == AclEntryScope.DEFAULT) {
        acl.add(curEntry);
        while (entryIter.hasNext()) {
            acl.add(entryIter.next());
        }
    }

    return acl;
}

From source file:com.cinchapi.concourse.util.Collections.java

/**
 * Convert the given {@code collection} to a {@link List} of {@link Long}
 * values, if necessary. The client must attempt to do this for every
 * collection of records because CaSH always passes user input in as a
 * collection of {@link Integer integers}.
 * //from   w w w.  ja v a2  s  .c  o  m
 * @param collection
 * @return a List that contains Long values
 */
public static <T> List<Long> toLongList(Collection<T> collection) {
    List<Long> list = Lists.newArrayListWithCapacity(collection.size());
    Iterator<T> it = collection.iterator();
    while (it.hasNext()) {
        T elt = it.next();
        if (elt instanceof Number) {
            list.add(((Number) elt).longValue());
        } else {
            throw new ClassCastException("Cant convert object of type" + elt.getClass() + " to java.lang.Long");
        }
    }
    return list;
}

From source file:com.ojuslabs.oct.util.Reference.java

protected Reference() {
    _authors = Lists.newArrayListWithCapacity(LIST_SIZE_S);
}

From source file:com.torodb.torod.db.backends.query.processors.AndProcessor.java

public static List<ProcessedQueryCriteria> process(AndQueryCriteria criteria,
        QueryCriteriaVisitor<List<ProcessedQueryCriteria>, Void> visitor) {

    List<ProcessedQueryCriteria> child1Result = criteria.getSubQueryCriteria1().accept(visitor, null);
    List<ProcessedQueryCriteria> child2Result = criteria.getSubQueryCriteria2().accept(visitor, null);

    List<ProcessedQueryCriteria> result = Lists
            .newArrayListWithCapacity(child1Result.size() * child2Result.size());
    for (ProcessedQueryCriteria qcr1 : child1Result) {
        for (ProcessedQueryCriteria qcr2 : child2Result) {

            result.add(new ProcessedQueryCriteria(
                    getMergedQueryCriteria(qcr1.getStructureQuery(), qcr2.getStructureQuery()),
                    getMergedQueryCriteria(qcr1.getDataQuery(), qcr2.getDataQuery())));
        }//from   w  w w  .  j  av  a  2  s. c  o  m
    }

    return result;
}

From source file:com.opengamma.integration.viewer.status.AggregateType.java

public static AggregateType of(String aggregateStrType) {
    ArgumentChecker.notNull(aggregateStrType, "aggregateStrType");

    validateAggregateType(aggregateStrType.toUpperCase());

    List<ViewColumnType> types = Lists.newArrayListWithCapacity(VALID_AGGRAGATION_CHARS.size());
    char[] chars = aggregateStrType.toCharArray();
    for (char character : chars) {
        String shortName = String.valueOf(character);
        ViewColumnType type = ViewColumnType.of(shortName);
        if (type == null) {
            throw new IllegalArgumentException("Unsupported aggregate type: " + shortName);
        }//from w  w w  .  ja  v a2 s.  co  m
        types.add(type);
    }
    return new AggregateType(types);
}

From source file:org.apache.beam.runners.core.WindowMatchers.java

public static <T> Matcher<WindowedValue<? extends T>> isWindowedValue(T value, Instant timestamp,
        Collection<? extends BoundedWindow> windows, PaneInfo paneInfo) {

    Collection<Matcher<? super BoundedWindow>> windowMatchers = Lists.newArrayListWithCapacity(windows.size());
    for (BoundedWindow window : windows) {
        windowMatchers.add(Matchers.equalTo(window));
    }//from w  ww .j a v  a2  s.c o  m

    return isWindowedValue(Matchers.equalTo(value), Matchers.equalTo(timestamp),
            Matchers.containsInAnyOrder(windowMatchers), Matchers.equalTo(paneInfo));
}

From source file:com.google.appinventor.server.properties.json.ServerJsonArray.java

public ServerJsonArray(org.json.JSONArray array) {
    int size = array.length();
    elements = Lists.newArrayListWithCapacity(size);
    for (int i = 0; i < size; i++) {
        try {//from ww w  .  ja v  a2 s  . c om
            elements.add(ServerJsonValue.convert(array.get(i)));
        } catch (JSONException e) {
            // Cannot happen
            throw new AssertionError(e);
        }
    }
}