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.terasology.entitySystem.metadata.core.LongTypeHandler.java

public List<Long> deserializeList(EntityData.Value value) {
    if (value.getLongCount() > 0) {
        return Lists.newArrayList(value.getLongList());
    } else if (value.getIntegerCount() > 0) {
        List<Long> result = Lists.newArrayListWithCapacity(value.getIntegerCount());
        for (int i = 0; i < value.getIntegerCount(); ++i) {
            result.add((long) value.getInteger(i));
        }//from w  w w  .ja v a  2s  .c  om
        return result;
    } else if (value.getDoubleCount() > 0) {
        List<Long> result = Lists.newArrayListWithCapacity(value.getDoubleCount());
        for (int i = 0; i < value.getDoubleCount(); ++i) {
            result.add((long) TeraMath.floorToInt((float) value.getDouble(i)));
        }
        return result;
    } else if (value.getFloatCount() > 0) {
        List<Long> result = Lists.newArrayListWithCapacity(value.getFloatCount());
        for (int i = 0; i < value.getFloatCount(); ++i) {
            result.add((long) TeraMath.floorToInt(value.getFloat(i)));
        }
        return result;
    }
    return Lists.newArrayList();
}

From source file:com.opengamma.core.config.impl.RemoteConfigSource.java

@SuppressWarnings("unchecked")
private <R> Collection<ConfigItem<R>> configItemCollectionResult(final FudgeMsg msg) {
    final Collection<ConfigItem<R>> result = Lists.newArrayListWithCapacity(msg.getNumFields());
    final FudgeDeserializer deserializer = new FudgeDeserializer(OpenGammaFudgeContext.getInstance());
    for (final FudgeField field : msg) {
        result.add(deserializer.fieldValueToObject(ConfigItem.class, field));
    }/*  w w  w . j  a va  2s.co  m*/
    return result;
}

From source file:org.gradoop.common.model.impl.properties.PropertyList.java

/**
 * Creates property list with given capacity.
 *
 * @param capacity initial capacity
 */
private PropertyList(int capacity) {
    properties = Lists.newArrayListWithCapacity(capacity);
}

From source file:net.myrrix.online.MultiRescorerProvider.java

@Override
public IDRescorer getRecommendRescorer(long[] userIDs, MyrrixRecommender recommender, String... args) {
    List<IDRescorer> rescorers = Lists.newArrayListWithCapacity(providers.length);
    for (RescorerProvider provider : providers) {
        IDRescorer rescorer = provider.getRecommendRescorer(userIDs, recommender, args);
        if (rescorer != null) {
            rescorers.add(rescorer);//from  w w  w  .j ava 2  s  . com
        }
    }
    return buildRescorer(rescorers);
}

From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.ExactInvocation.java

public static GambitCreator.Invocable boundInvoke(int op, final String methodName, final TypeWidget owner,
        TypeWidget returnType, final List<BytecodeExpression> args) {
    List<TypeWidget> types = Lists.newArrayListWithCapacity(args.size());
    for (BytecodeExpression expr : hasReceiver(op) ? args.subList(1, args.size()) : args) {
        types.add(expr.getType());/*from  ww  w  .  ja  v  a 2  s. c  om*/
    }
    return exactInvoke(op, methodName, owner, returnType, types).prefix(args);
}

From source file:com.greensopinion.swagger.jaxrsgen.model.ApiBuilder.java

public ApiRoot create() {
    List<Service> services = Lists.newArrayListWithCapacity(serviceBuilders.size());
    for (ServiceBuilder builder : serviceBuilders) {
        services.add(builder.version(version).basePath(apiBasePath).create());
    }/*from www.  j a va  2s.c  o  m*/
    return new ApiRoot(version, services);
}

From source file:org.cinchapi.concourse.server.storage.temp.Queue.java

/**
 * Construct a Limbo with enough capacity for {@code initialSize}. If
 * necessary, the structure will grow to accommodate more data.
 * // w  ww. ja  va 2s . c om
 * @param initialSize
 */
public Queue(int initialSize) {
    writes = Lists.newArrayListWithCapacity(initialSize);
}

From source file:com.opengamma.integration.viewer.status.impl.SimpleViewStatusModel.java

private List<List<String>> deepCopyHeaders(final List<List<String>> columnHeaders) {
    List<List<String>> headers = Lists.newArrayListWithCapacity(columnHeaders.size());
    for (List<String> headings : columnHeaders) {
        headers.add(Lists.newArrayList(headings));
    }/*from   w  w w . j  a  v  a  2s  . c  om*/
    return headers;
}

From source file:net.bither.logging.AsyncAppender.java

private AsyncAppender(Appender<ILoggingEvent> delegate) {
    this.delegate = delegate;
    this.queue = Queues.newLinkedBlockingQueue();
    this.batch = Lists.newArrayListWithCapacity(BATCH_SIZE);
    this.dispatcher = THREAD_FACTORY.newThread(this);
    setContext(delegate.getContext());//from  w ww. j a  v  a2s .c o m
}

From source file:voldemort.store.slop.strategy.ConsistentHandoffStrategy.java

/**
 * Creates a consistent handoff strategy instance
 * /* www.  jav a 2  s  .  c  o  m*/
 * @param cluster The cluster
 * @param prefListSize The number of nodes adjacent to the failed node in
 *        the that could be selected to receive given hint
 * @param enableZoneRouting is zone routing enabled?
 * @param clientZoneId client zone id if zone routing is enabled
 */
public ConsistentHandoffStrategy(Cluster cluster, int prefListSize, boolean enableZoneRouting,
        int clientZoneId) {
    int nodesInCluster = cluster.getNumberOfNodes();
    if (prefListSize > nodesInCluster - 1)
        throw new IllegalArgumentException(
                "Preference list size must be less than " + "number of nodes in the cluster - 1");

    routeToMap = Maps.newHashMapWithExpectedSize(cluster.getNumberOfNodes());
    for (Node node : cluster.getNodes()) {
        List<Node> prefList = Lists.newArrayListWithCapacity(prefListSize);
        int i = node.getId();
        int n = 0;
        while (n < prefListSize) {
            i = (i + 1) % cluster.getNumberOfNodes();
            Node peer = cluster.getNodeById(i);
            if (peer.getId() != node.getId()) {
                if (enableZoneRouting && cluster.getZones().size() > 1) {
                    // don't handoff hints to the same zone
                    int zoneId = node.getZoneId();
                    if (clientZoneId == zoneId) {
                        if (peer.getZoneId() != zoneId)
                            continue;
                    } else {
                        if (peer.getZoneId() == zoneId)
                            continue;
                    }
                }
                prefList.add(peer);
                n++;
            }
            routeToMap.put(node.getId(), prefList);
        }
    }
}