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.github.steveash.typedconfig.resolver.type.container.MapValueResolverFactory.java

@Override
protected Collection<Object> makeEmptyCollection(int size) {
    return Lists.newArrayListWithCapacity(size);
}

From source file:org.eclipse.xtext.xbase.scoping.batch.FeatureScopeSessionWithNamedStaticTypes.java

@Override
protected List<TypeBucket> concatTypeBuckets(Map<? extends JvmType, Set<String>> types,
        List<TypeBucket> parentResult, Provider resolvedFeaturesProvider) {
    if (types.isEmpty()) {
        return parentResult;
    }// w w w  . j a v  a  2  s.co  m
    List<TypeBucket> result = Lists.newArrayListWithCapacity(3);
    result.add(new TypeWithRestrictedNamesBucket(getId(), types, resolvedFeaturesProvider));
    result.addAll(parentResult);
    return result;
}

From source file:org.eclipse.xtext.common.types.access.binary.asm.BinaryTypeParameter.java

public List<BinaryGenericTypeSignature> getBounds() {
    final int end = offset + length;
    int afterTypeParameterName = chars.indexOf(':', offset);
    if (afterTypeParameterName >= end) {
        throw new IllegalArgumentException();
    }//from  w w w  .  j  a  v a2  s . c  o  m
    if (afterTypeParameterName == chars.length() - 1) {
        return Collections.emptyList();
    }
    if (chars.charAt(afterTypeParameterName + 1) == ':') {
        // no class bound
        List<BinaryGenericTypeSignature> result = Lists.newArrayListWithCapacity(3);
        int nextInterface = afterTypeParameterName + 2;
        while (nextInterface <= end) {
            int afterInterfaceBound = SignatureUtil.scanTypeSignature(chars, nextInterface) + 1;
            BinaryGenericTypeSignature intf = new BinaryGenericTypeSignature(chars, nextInterface,
                    afterInterfaceBound - nextInterface);
            result.add(intf);
            nextInterface = afterInterfaceBound + 1;
        }
        return result;
    } else {
        int afterClassBound = SignatureUtil.scanTypeSignature(chars, afterTypeParameterName + 1);
        BinaryGenericTypeSignature classBound = new BinaryGenericTypeSignature(chars,
                afterTypeParameterName + 1, afterClassBound - afterTypeParameterName);
        if (afterClassBound == end - 1) {
            return Collections.singletonList(classBound);
        }
        if (afterClassBound != end - 2) {
            int nextInterface = afterClassBound + 1;
            List<BinaryGenericTypeSignature> result = Lists.newArrayListWithCapacity(3);
            result.add(classBound);
            while (nextInterface != end) {
                int afterInterfaceBound = scanTypeSignature(chars, nextInterface + 1);
                BinaryGenericTypeSignature intf = new BinaryGenericTypeSignature(chars, nextInterface + 1,
                        afterInterfaceBound - nextInterface);
                result.add(intf);
                nextInterface = afterInterfaceBound + 1;
            }
            return result;
        } else {
            return Collections.singletonList(classBound);
        }
    }
}

From source file:org.novelang.common.tree.TreeTools.java

/**
 * Returns a copy of a {@code Tree} with the {@code newChild} added as first child.
 *
 * @param tree a non-null object that may implement {@link StorageTypeProvider}.
 * @param newChild a non-null object./*w ww  .ja  v  a 2s .c o  m*/
 * @param position a value between [0, {@link Tree#getChildCount()}[.
 * @return a non-null object.
 */
public static <T extends Tree<T>> T add(final T tree, final T newChild, final int position) {
    Preconditions.checkNotNull(newChild);
    if (position < 0 || position > tree.getChildCount()) {
        throw new IllegalArgumentException(
                "Invalid position:" + position + " as childcount=" + tree.getChildCount());
    }
    final List<T> newChildList = Lists.newArrayListWithCapacity(tree.getChildCount() + 1);
    int oldArrayIndex = 0;
    for (int newArrayIndex = 0; newArrayIndex <= tree.getChildCount(); newArrayIndex++) {
        if (position == newArrayIndex) {
            newChildList.add(newArrayIndex, newChild);
        } else {
            newChildList.add(newArrayIndex, tree.getChildAt(oldArrayIndex));
            oldArrayIndex++;
        }
    }
    return tree.adopt(newChildList);
}

From source file:com.google.devtools.build.lib.packages.FilesetEntry.java

public static List<String> makeStringList(List<Label> labels) {
    if (labels == null) {
        return Collections.emptyList();
    }/*from w w  w  . ja v a2 s.  co m*/
    List<String> strings = Lists.newArrayListWithCapacity(labels.size());
    for (Label label : labels) {
        strings.add(label.toString());
    }
    return strings;
}

From source file:com.threerings.servlet.util.Parameters.java

/**
 * Returns all the names and values in the parameters. The name is {@link Tuple#left} and the
 * value is {@link Tuple#right}. If a name appears multiple times, it'll be in multiple
 * tuples.//from  w w w  .j a  va 2  s.c  o m
 */
public Collection<Tuple<String, String>> entries() {
    Set<String> names = names();
    List<Tuple<String, String>> entries = Lists.newArrayListWithCapacity(names.size());
    for (String name : names) {
        for (String val : getAll(name)) {
            entries.add(Tuple.newTuple(name, val));
        }
    }
    return entries;
}

From source file:org.locationtech.geogig.model.impl.CommitBuilder.java

/**
 * @param platform//w w  w .j  a  v  a  2 s.c  om
 */
public CommitBuilder(Platform platform) {
    Preconditions.checkNotNull(platform);
    this.platform = platform;
    this.parentIds = Lists.newArrayListWithCapacity(2);
}

From source file:defrac.intellij.projectView.DefracViewModuleGroupNode.java

@Override
@NotNull/*  ww  w .  ja va2 s  .co m*/
public Collection<AbstractTreeNode> getChildren() {
    final Project project = getProject();

    if (project == null) {
        return Lists.newArrayListWithCapacity(0);
    }

    final List<AbstractTreeNode> result = new ArrayList<AbstractTreeNode>();
    final Collection<Module> modules = getValue().getModules();

    for (final Module module : modules) {
        result.add(createModuleNode(project, module, getSettings()));
    }

    return result;
}

From source file:org.apache.kylin.metadata.filter.EvaluatableFunctionTupleFilter.java

public EvaluatableFunctionTupleFilter(String name) {
    super(name, FilterOperatorEnum.EVAL_FUNC);
    values = Lists.newArrayListWithCapacity(1);
    values.add(null);
}

From source file:at.molindo.esi4j.rebuild.util.IteratorRebuildSession.java

@Override
public List<?> getNext(int batchSize) {
    if (_iterator == null) {
        throw new IllegalStateException("already closed");
    }/*from  ww  w . java 2  s .c o  m*/

    List<Object> list = Lists.newArrayListWithCapacity(batchSize);
    while (list.size() < batchSize && _iterator.hasNext()) {
        list.add(_iterator.next());
    }

    return list;
}