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.jivesoftware.os.amza.client.http.Ring.java

public RingMemberAndHost[] orderedRing(List<RingMember> membersInOrder) {
    List<RingMemberAndHost> ordered = Lists.newArrayListWithCapacity(members.length);
    if (membersInOrder == null) {
        if (leaderIndex >= 0) {
            ordered.add(members[leaderIndex]);
        }/*from   w  w w . j av  a2  s . c o  m*/
        for (int i = 0; i < members.length; i++) {
            if (i != leaderIndex) {
                ordered.add(members[i]);
            }
        }
    } else {
        Map<RingMember, RingMemberAndHost> memberHosts = Maps.newHashMapWithExpectedSize(members.length);
        for (RingMemberAndHost member : members) {
            memberHosts.put(member.ringMember, member);
        }
        for (RingMember ringMember : membersInOrder) {
            RingMemberAndHost ringMemberAndHost = memberHosts.remove(ringMember);
            if (ringMemberAndHost != null) {
                ordered.add(ringMemberAndHost);
            }
        }
        for (RingMemberAndHost ringMemberAndHost : memberHosts.values()) {
            ordered.add(ringMemberAndHost);
        }
    }
    return ordered.toArray(new RingMemberAndHost[0]);
}

From source file:com.netflix.paas.mesh.endpoints.CircularEndpointPolicy.java

@Override
public List<InstanceInfo> getEndpoints(InstanceInfo current, List<InstanceInfo> instances) {
    int position = Collections.binarySearch(instances, current, comparator);
    int size = instances.size();

    List<InstanceInfo> endpoints = Lists.newArrayListWithCapacity(replicationFactor);

    int count = Math.max(size - 1, replicationFactor);
    for (int i = 0; i < count; i++) {
        endpoints.add(instances.get((position + i) % size));
    }/* w  w  w .ja  v a2  s .c  om*/
    return endpoints;
}

From source file:org.terasology.engine.modes.loadProcesses.RegisterMods.java

@Override
public boolean step() {
    ModuleManager moduleManager = CoreRegistry.get(ModuleManager.class);
    List<Name> moduleIds = Lists.newArrayListWithCapacity(gameManifest.getModules().size());
    for (NameVersion moduleInfo : gameManifest.getModules()) {
        moduleIds.add(moduleInfo.getName());
    }//from  w  w  w  .  jav a2s . com

    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    ResolutionResult result = resolver.resolve(moduleIds);
    if (result.isSuccess()) {
        moduleManager.loadEnvironment(result.getModules(), true);
        ApplyModulesUtil.applyModules();
    } else {
        CoreRegistry.get(GameEngine.class)
                .changeState(new StateMainMenu("Missing required module or dependency"));
    }
    return true;
}

From source file:org.geogit.rest.repository.RepositoryListResource.java

private List<String> getRepoNames() {
    Request request = getRequest();
    List<DataStoreInfo> geogitStores = findGeogitStores(request);

    List<String> repoNames = Lists.newArrayListWithCapacity(geogitStores.size());
    for (DataStoreInfo info : geogitStores) {
        String wsname = info.getWorkspace().getName();
        String storename = info.getName();
        String repoName = wsname + ":" + storename;
        repoNames.add(repoName);/*  w  w  w . j  a v a 2  s  .  c om*/
    }
    Collections.sort(repoNames);
    return repoNames;
}

From source file:com.palantir.atlasdb.schema.RowTransformers.java

/**
 * Returns a function that permutes the order of the components of each row without changing their types.
 *///from w  w w. j  a v  a 2 s . co m
public static Function<byte[], byte[]> rowNamePermutation(List<EncodingType> initialTypes,
        List<Integer> permutation) {
    Preconditions.checkArgument(initialTypes.size() == permutation.size());
    List<RowComponent> fullPermutation = Lists.newArrayListWithCapacity(permutation.size());
    for (int i = 0; i < initialTypes.size(); i++) {
        fullPermutation.add(RowComponent.of(permutation.get(i), initialTypes.get(permutation.get(i))));
    }
    return rowNamePermuformation(initialTypes, fullPermutation);
}

From source file:org.opendaylight.controller.cluster.raft.utils.InMemorySnapshotStore.java

@SuppressWarnings("unchecked")
public static <T> List<T> getSnapshots(String persistentId, Class<T> type) {
    List<StoredSnapshot> stored = snapshots.get(persistentId);
    if (stored == null) {
        return Collections.emptyList();
    }//from   w  ww  .j a  v  a  2  s .co m

    List<T> retList;
    synchronized (stored) {
        retList = Lists.newArrayListWithCapacity(stored.size());
        for (StoredSnapshot s : stored) {
            if (type.isInstance(s.data)) {
                retList.add((T) s.data);
            }
        }
    }

    return retList;
}

From source file:de.craftolution.craftoplugin.modules.protection.loader.SubjectCache.java

SubjectCache(int length) {
    this.subjects = Lists.newArrayListWithCapacity(length);
}

From source file:com.google.devtools.build.lib.syntax.ListComprehension.java

@Override
Object eval(Environment env) throws EvalException, InterruptedException {
    if (lists.isEmpty()) {
        return convert(new ArrayList<>(), env);
    }//  www . ja  v  a 2  s .  c o m

    List<Map.Entry<LValue, Iterable<?>>> listValues = Lists.newArrayListWithCapacity(lists.size());
    int size = 1;
    for (Map.Entry<LValue, Expression> list : lists) {
        Object listValueObject = list.getValue().eval(env);
        final Iterable<?> listValue = EvalUtils.toIterable(listValueObject, getLocation());
        int listSize = EvalUtils.size(listValue);
        if (listSize == 0) {
            return convert(new ArrayList<>(), env);
        }
        size *= listSize;
        listValues.add(Maps.<LValue, Iterable<?>>immutableEntry(list.getKey(), listValue));
    }
    List<Object> resultList = Lists.newArrayListWithCapacity(size);
    evalLists(env, listValues, resultList);
    return convert(resultList, env);
}

From source file:org.sonar.duplications.benchmark.hash.AbstractHashBlockChunker.java

@Override
public List<Block> chunk(String resourceId, List<Statement> statements) {
    if (statements.size() < getBlockSize()) {
        return Collections.emptyList();
    }//from   w  ww .  ja  v a2s. c  o m

    LinkedList<Statement> statementsForBlock = new LinkedList<Statement>();
    List<Block> blocks = Lists.newArrayListWithCapacity(statements.size() - getBlockSize() + 1);

    for (Statement stmt : statements) {
        statementsForBlock.add(stmt);
        if (statementsForBlock.size() == getBlockSize()) {
            Statement firstStatement = statementsForBlock.getFirst();
            Statement lastStatement = statementsForBlock.getLast();
            blocks.add(new Block(resourceId, buildBlockHash(statementsForBlock), blocks.size(),
                    firstStatement.getStartLine(), lastStatement.getEndLine()));
            statementsForBlock.removeFirst();
        }
    }

    return blocks;
}

From source file:com.nesscomputing.sequencer.HashSequencer.java

private HashSequencer(int startingSize) {
    keyToInt = new TObjectIntHashMap<K>(startingSize, LOAD_FACTOR, -1);
    intToKey = Lists.newArrayListWithCapacity(startingSize);
}