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:jp.tkgktyk.xposed.forcetouchdetector.app.util.ActionInfoList.java

public String toStringForPreference() {
    ArrayList<ActionInfo.Record> records = Lists.newArrayListWithCapacity(size());
    for (ActionInfo info : this) {
        records.add(info.toRecord());//from   ww w . j  a va2 s . c  o m
    }

    return new Gson().toJson(records);
}

From source file:edu.harvard.med.screensaver.util.CollectionUtils.java

public static <T> List<T> listOf(T e, int i) {
    ArrayList<T> l = Lists.newArrayListWithCapacity(i);
    fill(l, e, i);//from  w  w w . jav a 2 s .c om
    return l;
}

From source file:com.yahoo.yqlplus.language.logical.TypeCheckers.java

public static ArgumentsTypeChecker make(Operator target, Object... types) {
    // Class<?> extends Operator -> NodeTypeChecker
    if (types == null) {
        types = new Object[0];
    }/*from   ww w.j  a v  a  2  s. co  m*/
    List<OperatorTypeChecker> checkers = Lists.newArrayListWithCapacity(types.length);
    for (int i = 0; i < types.length; ++i) {
        checkers.add(createChecker(target, i, types[i]));
    }
    return new ArgumentsTypeChecker(target, checkers);
}

From source file:com.google.devtools.build.lib.concurrent.Sharder.java

/**
 * Returns an immutable list of mutable lists.
 *
 * @param numLists the number of top-level lists.
 * @param expectedSize the exepected size of each mutable list.
 * @return a list of lists.//from  w ww. ja  v  a 2 s . co  m
 */
private static <T> List<List<T>> immutableListOfLists(int numLists, int expectedSize) {
    List<List<T>> list = Lists.newArrayListWithCapacity(numLists);
    for (int i = 0; i < numLists; i++) {
        list.add(Lists.<T>newArrayListWithExpectedSize(expectedSize));
    }
    return Collections.unmodifiableList(list);
}

From source file:org.apache.hadoop.hbase.util.ByteRangeUtils.java

public static ArrayList<byte[]> copyToNewArrays(Collection<ByteRange> ranges) {
    if (ranges == null) {
        return new ArrayList<byte[]>(0);
    }//w  w w. j  a  v a2  s  . c om
    ArrayList<byte[]> arrays = Lists.newArrayListWithCapacity(ranges.size());
    for (ByteRange range : ranges) {
        arrays.add(range.deepCopyToNewArray());
    }
    return arrays;
}

From source file:org.apache.kylin.query.routing.QueryRouter.java

public static IRealization selectRealization(OLAPContext olapContext, Set<IRealization> realizations)
        throws NoRealizationFoundException {

    String factTableName = olapContext.firstTableScan.getTableName();
    String projectName = olapContext.olapSchema.getProjectName();
    SQLDigest sqlDigest = olapContext.getSQLDigest();

    List<Candidate> candidates = Lists.newArrayListWithCapacity(realizations.size());
    for (IRealization real : realizations) {
        if (real.isReady())
            candidates.add(new Candidate(real, sqlDigest));
    }//w  w w. j  av  a 2 s  . co  m

    logger.info("Find candidates by table " + factTableName + " and project=" + projectName + " : "
            + StringUtils.join(candidates, ","));

    // rule based realization selection, rules might reorder realizations or remove specific realization
    RoutingRule.applyRules(candidates);

    if (candidates.size() == 0) {
        return null;
    }

    Candidate chosen = candidates.get(0);
    adjustForDimensionAsMeasure(chosen, olapContext);

    logger.info("The realizations remaining: " + RoutingRule.getPrintableText(candidates)
            + " And the final chosen one is the first one");

    return chosen.realization;
}

From source file:com.maxifier.cliche.CommandTable.java

public List<String> getAbbreviates(String prefix) {
    ArrayList<String> abbrs = Lists.newArrayListWithCapacity(commandTable.size());
    for (ShellCommand shellCommand : commandTable) {
        if (prefix == null || shellCommand.getPrefix().equals(prefix)) {
            abbrs.add(shellCommand.getPrefix() + shellCommand.getAbbreviation());
        }/*  ww w.  j a  v  a  2  s.  co  m*/
    }
    return abbrs;
}

From source file:com.ebay.pulsar.analytics.metricstore.druid.query.model.QueryCacheHelper.java

public static byte[] computeIntervalsBytes(List<String> intervals) {
    List<byte[]> cacheKeySet = Lists.newArrayListWithCapacity(intervals.size());

    int totalSize = 0;
    for (String interval : intervals) {
        final byte[] cacheKey = computeStringBytes(interval);
        cacheKeySet.add(cacheKey);//  w  ww  .ja va2 s .c om
        totalSize += cacheKey.length;
    }

    ByteBuffer retVal = ByteBuffer.allocate(totalSize);
    for (byte[] bytes : cacheKeySet) {
        retVal.put(bytes);
    }
    return retVal.array();
}

From source file:org.gradle.internal.serialize.ListSerializer.java

@Override
protected List<T> createCollection(int size) {
    if (size == 0) {
        return Collections.emptyList();
    }//from  w w w.j a  va 2s  .c o  m
    return Lists.newArrayListWithCapacity(size);
}

From source file:com.palantir.common.persist.Persistables.java

public static List<byte[]> persistAll(Iterable<? extends Persistable> persistables) {
    List<byte[]> output;
    if (persistables instanceof Collection) {
        output = Lists.newArrayListWithCapacity(((Collection<? extends Persistable>) persistables).size());
    } else {/*  www .ja  va  2 s .  c  om*/
        output = Lists.newArrayList();
    }
    return persistAll(persistables, output);
}