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.eclipse.sirius.common.acceleo.mtl.business.api.extension.JavaImportHandler.java

/**
 * This will return the list of all public method signatures that can be
 * retrieved from the given Class./*w ww .  jav  a2 s .  c  o m*/
 * 
 * @param clazz
 *            The Class we are to check for public methods.
 * @return The list of all public method signatures that can be retrieved
 *         from the given Class.
 */
private static List<String> getPublicSignaturesFrom(Class<?> clazz) {
    final Method[] methods = clazz.getDeclaredMethods();
    List<String> signatures = Lists.newArrayListWithCapacity(methods.length);

    for (int i = 0; i < methods.length; i++) {
        final Method method = methods[i];
        if (Modifier.isPublic(method.getModifiers())) {
            final StringBuilder signature = new StringBuilder();
            signature.append(getTypeName(method.getReturnType())).append(' ');
            signature.append(method.getName()).append('(');
            final Class<?>[] params = method.getParameterTypes();
            for (int j = 0; j < params.length; j++) {
                signature.append(getTypeName(params[j]));
                if (j < (params.length - 1)) {
                    signature.append(',');
                }
            }
            signature.append(')');
            signatures.add(signature.toString());
        }
    }

    return signatures;
}

From source file:org.terasology.persistence.typeSerialization.typeHandlers.SimpleTypeHandler.java

public List<T> deserializeCollection(EntityData.Value value) {
    List<T> result = Lists.newArrayListWithCapacity(value.getValueCount());
    for (EntityData.Value item : value.getValueList()) {
        result.add(deserialize(item));//from  w w w  .  j  a v a 2 s .  c om
    }
    return result;
}

From source file:org.jage.platform.component.pico.injector.Parameters.java

public static List<Parameter> fromList(final List<IArgumentDefinition> argumentDefinitions) {
    List<Parameter> parameters = Lists.newArrayListWithCapacity(argumentDefinitions.size());
    for (IArgumentDefinition argumentDefinition : argumentDefinitions) {
        parameters.add(from(argumentDefinition));
    }/*from   w  w  w . jav  a 2s  .  c o  m*/
    return parameters;
}

From source file:org.summer.dsl.xbase.typesystem.util.Maps2.java

/**
 * Puts a value into a map that supports lists as values.
 * The list is created on-demand.//from   w  w  w . j a  va  2 s. com
 */
public static <K, V> void putIntoListMap(K key, V value, Map<? super K, List<V>> map) {
    List<V> list = map.get(key);
    if (list == null) {
        list = Lists.newArrayListWithCapacity(2);
        map.put(key, list);
    }
    list.add(value);
}

From source file:org.apache.kylin.dict.MultipleDictionaryValueEnumerator.java

public MultipleDictionaryValueEnumerator(List<DictionaryInfo> dictionaryInfoList) {
    dictionaryList = Lists.newArrayListWithCapacity(dictionaryInfoList.size());
    for (DictionaryInfo dictInfo : dictionaryInfoList) {
        dictionaryList.add((Dictionary<String>) dictInfo.getDictionaryObject());
    }/* w  ww.  j  a v  a  2s .  c  o  m*/
    if (!dictionaryList.isEmpty()) {
        curDict = dictionaryList.get(0);
        curKey = curDict.getMinId();
    }
}

From source file:org.apache.tephra.util.TransactionEditUtil.java

/**
 * Generates a number of semi-random {@link co.cask.tephra.persist.TransactionEdit} instances.
 * These are just randomly selected from the possible states, so would not necessarily reflect a real-world
 * distribution.// ww  w  . j  ava2s.  c  o m
 *
 * @param numEntries how many entries to generate in the returned list.
 * @return a list of randomly generated transaction log edits.
 */
@Deprecated
public static List<co.cask.tephra.persist.TransactionEdit> createRandomCaskEdits(int numEntries) {
    List<co.cask.tephra.persist.TransactionEdit> edits = Lists.newArrayListWithCapacity(numEntries);
    for (int i = 0; i < numEntries; i++) {
        co.cask.tephra.persist.TransactionEdit.State nextType = co.cask.tephra.persist.TransactionEdit.State
                .values()[random.nextInt(6)];
        long writePointer = Math.abs(random.nextLong());
        switch (nextType) {
        case INPROGRESS:
            edits.add(co.cask.tephra.persist.TransactionEdit.createStarted(writePointer, writePointer - 1,
                    System.currentTimeMillis() + 300000L, TransactionType.SHORT));
            break;
        case COMMITTING:
            edits.add(co.cask.tephra.persist.TransactionEdit.createCommitting(writePointer,
                    generateChangeSet(10)));
            break;
        case COMMITTED:
            edits.add(co.cask.tephra.persist.TransactionEdit.createCommitted(writePointer,
                    generateChangeSet(10), writePointer + 1, random.nextBoolean()));
            break;
        case INVALID:
            edits.add(co.cask.tephra.persist.TransactionEdit.createInvalid(writePointer));
            break;
        case ABORTED:
            edits.add(co.cask.tephra.persist.TransactionEdit.createAborted(writePointer, TransactionType.SHORT,
                    null));
            break;
        case MOVE_WATERMARK:
            edits.add(co.cask.tephra.persist.TransactionEdit.createMoveWatermark(writePointer));
            break;
        }
    }
    return edits;
}

From source file:com.opengamma.web.server.push.analytics.MainGridViewport.java

String updateResults(ResultsCache cache) {
    boolean updated = false;
    List<List<ViewportResults.Cell>> allResults = Lists.newArrayList();
    // iterate over each row in the viewport
    for (int rowIndex : _viewportSpec.getRows()) {
        MainGridStructure.Row row = _gridStructure.getRowAtIndex(rowIndex);
        // create a list for each row of results
        List<ViewportResults.Cell> rowResults = Lists
                .newArrayListWithCapacity(_viewportSpec.getColumns().size() + 1);
        // iterate over all columns in the viewport and populate the results for the current row
        for (int colIndex : _viewportSpec.getColumns()) {
            if (colIndex == MainGridStructure.LABEL_COLUMN) {
                rowResults.add(ViewportResults.stringCell(row.getName()));
            } else if (colIndex == MainGridStructure.QUANTITY_COLUMN) {
                rowResults.add(ViewportResults.valueCell(row.getQuantity(), null, Collections.emptyList()));
            } else {
                Pair<String, ValueSpecification> cellTarget = _gridStructure.getTargetForCell(rowIndex,
                        colIndex);//w ww .j  a v a  2s . c o m
                if (cellTarget != null) {
                    Class<?> columnType = _gridStructure.getColumnType(colIndex);
                    String calcConfigName = cellTarget.getFirst();
                    ValueSpecification valueSpec = cellTarget.getSecond();
                    ResultsCache.Result cacheResult = cache.getResult(calcConfigName, valueSpec, columnType);
                    updated = updated || cacheResult.isUpdated();
                    rowResults.add(ViewportResults.valueCell(cacheResult.getValue(), valueSpec,
                            cacheResult.getHistory()));
                } else {
                    rowResults.add(ViewportResults.emptyCell());
                }
            }
        }
        allResults.add(rowResults);
    }
    _latestResults = new ViewportResults(allResults, _viewportSpec, _gridStructure.getColumnStructure(),
            _version);
    if (updated) {
        return _dataId;
    } else {
        return null;
    }
}

From source file:com.zimbra.client.ZFilterRules.java

public ZFilterRules(Collection<FilterRule> list) throws ServiceException {
    this.rules = Lists.newArrayListWithCapacity(list.size());
    for (FilterRule rule : list) {
        this.rules.add(new ZFilterRule(rule));
    }//  www  .  j a  v  a 2 s  . c om
}

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

public List<String> getCommandsNames(String prefix) {
    ArrayList<String> names = Lists.newArrayListWithCapacity(commandTable.size());
    for (ShellCommand shellCommand : commandTable) {
        if (prefix == null || shellCommand.getPrefix().equals(prefix)) {
            names.add(shellCommand.getPrefix() + shellCommand.getName());
        }/*from  w ww .  ja v a2  s.  co  m*/
    }
    return names;
}

From source file:yaphyre.core.samplers.HaltonSampler.java

private void setupSampler(int numberOfSamples) {
    RandomVectorGenerator vectorGenerator = new HaltonSequenceGenerator(2);
    unitSquareSamples = Lists.newArrayListWithCapacity(numberOfSamples);
    for (int i = 0; i < numberOfSamples; i++) {
        unitSquareSamples.add(Point2D.of(vectorGenerator.nextVector()));
    }//from  w w  w.  j  a va  2s  .c o  m
    unitSquareSamples = Collections.unmodifiableList(unitSquareSamples);
}