Example usage for com.google.common.collect Lists newArrayListWithExpectedSize

List of usage examples for com.google.common.collect Lists newArrayListWithExpectedSize

Introduction

In this page you can find the example usage for com.google.common.collect Lists newArrayListWithExpectedSize.

Prototype

@GwtCompatible(serializable = true)
public static <E> ArrayList<E> newArrayListWithExpectedSize(int estimatedSize) 

Source Link

Document

Creates an ArrayList instance to hold estimatedSize elements, plus an unspecified amount of padding; you almost certainly mean to call #newArrayListWithCapacity (see that method for further advice on usage).

Usage

From source file:org.summer.dsl.ui.codetemplates.ui.scoping.SyntheticResourceAwareScopeProvider.java

public IScope scope_Codetemplates_language(Codetemplates templates, EReference reference) {
    if (TemplateResourceProvider.SYNTHETIC_SCHEME.equals(templates.eResource().getURI().scheme())) {
        ResourceSet resourceSet = templates.eResource().getResourceSet();
        List<Grammar> grammars = Lists.newArrayListWithExpectedSize(1);
        for (Resource resource : resourceSet.getResources()) {
            EObject root = resource.getContents().get(0);
            if (root instanceof Grammar) {
                grammars.add((Grammar) root);
            }//from   ww  w . jav  a  2s.  com
        }
        return Scopes.scopeFor(grammars, new Function<Grammar, QualifiedName>() {

            public QualifiedName apply(Grammar from) {
                return qualifiedNameConverter.toQualifiedName(from.getName());
            }

        }, IScope.NULLSCOPE);
    } else {
        return delegateGetScope(templates, reference);
    }
}

From source file:edu.buaa.satla.analysis.core.CounterexampleInfo.java

private CounterexampleInfo(boolean pSpurious, ARGPath pTargetPath, Model pModel) {
    spurious = pSpurious;// w  ww  . ja v  a2s  . c  o  m
    targetPath = pTargetPath;
    model = pModel;

    if (!spurious) {
        furtherInfo = Lists.newArrayListWithExpectedSize(1);
    } else {
        furtherInfo = null;
    }
}

From source file:com.yahoo.yqlplus.engine.rules.PushAndTransform.java

@Override
public OperatorNode<ExpressionOperator> visitExpr(OperatorNode<ExpressionOperator> expr) {
    if (expr.getOperator() == ExpressionOperator.AND) {
        // (AND a b c (OR d x))
        //  -> (OR (AND a b c d) (AND a b c x))
        // a AND (b OR c) AND (d OR x)
        //  -> (a AND b AND d) OR (a AND c AND x)
        List<OperatorNode<ExpressionOperator>> args = expr.getArgument(0);
        if (args.size() == 1) {
            return visitExpr(args.get(0));
        }/*from w w  w .j a v  a 2s .  co  m*/
        final List<OperatorNode<ExpressionOperator>> ands = Lists.newArrayList();
        List<List<OperatorNode<ExpressionOperator>>> ors = Lists.newArrayList();
        for (OperatorNode<ExpressionOperator> arg : args) {
            arg = visitExpr(arg);
            if (arg.getOperator() == ExpressionOperator.OR) {
                ors.add((List<OperatorNode<ExpressionOperator>>) arg.getArgument(0));
            } else {
                ands.add(arg);
            }
        }
        if (ors.isEmpty()) {
            // nothing to do
            return expr;
        }
        final List<OperatorNode<ExpressionOperator>> result = Lists.newArrayListWithExpectedSize(ors.size());
        // for every combination of OR clauses, emit a new AND clause
        enumerate(ors, new Visit() {
            @Override
            public void add(List<OperatorNode<ExpressionOperator>> clauses) {
                List<OperatorNode<ExpressionOperator>> p = Lists
                        .newArrayListWithExpectedSize(ands.size() + clauses.size());
                p.addAll(ands);
                p.addAll(clauses);
                result.add(OperatorNode.create(ExpressionOperator.AND, p));
            }
        });
        if (result.size() == 1) {
            return result.get(0);
        } else {
            return OperatorNode.create(ExpressionOperator.OR, result);
        }
    }
    return super.visitExpr(expr);
}

From source file:com.mgmtp.jfunk.data.generator.field.Enumeration.java

public Enumeration(final MathRandom random, final Element element, final String characterSetId) {
    super(random, element, characterSetId);
    @SuppressWarnings("unchecked")
    List<Element> valueElements = element.getChildren(XMLTags.VALUE);
    values = Lists.newArrayListWithExpectedSize(valueElements.size());
    for (Element valueElement : valueElements) {
        String value = valueElement.getText();
        if (value != null) {
            values.add(value);//w w  w .  j  a v a2  s. c  o  m
        }
    }
    range = new Range(0, values.size() - 1);
}

From source file:org.eclipse.xtext.ui.codetemplates.ui.scoping.SyntheticResourceAwareScopeProvider.java

public IScope scope_Codetemplates_language(Codetemplates templates, EReference reference) {
    if (TemplateResourceProvider.SYNTHETIC_SCHEME.equals(templates.eResource().getURI().scheme())) {
        ResourceSet resourceSet = templates.eResource().getResourceSet();
        List<Grammar> grammars = Lists.newArrayListWithExpectedSize(1);
        for (Resource resource : resourceSet.getResources()) {
            EObject root = resource.getContents().get(0);
            if (root instanceof Grammar) {
                grammars.add((Grammar) root);
            }/*w w w. j a va  2s .  c o m*/
        }
        return Scopes.scopeFor(grammars, new Function<Grammar, QualifiedName>() {

            @Override
            public QualifiedName apply(Grammar from) {
                return qualifiedNameConverter.toQualifiedName(from.getName());
            }

        }, IScope.NULLSCOPE);
    } else {
        return delegateGetScope(templates, reference);
    }
}

From source file:com.android.tools.idea.rendering.AttributeSnapshot.java

/** Creates a list of attribute snapshots corresponding to the attributes of the given tag */
@NotNull//from  w  w  w .j  a v  a2s.com
public static List<AttributeSnapshot> createAttributesForTag(@NotNull XmlTag tag) {
    // Attributes
    XmlAttribute[] psiAttributes = tag.getAttributes();
    List<AttributeSnapshot> attributes = Lists.newArrayListWithExpectedSize(psiAttributes.length);
    for (XmlAttribute psiAttribute : psiAttributes) {
        AttributeSnapshot attribute = createAttributeSnapshot(psiAttribute);
        if (attribute != null) {
            attributes.add(attribute);
        }
    }

    return attributes;
}

From source file:org.sonatype.nexus.orient.entity.FieldCopier.java

@SuppressWarnings("unchecked")
public static List copy(final List<?> source) {
    List target = Lists.newArrayListWithExpectedSize(source.size());
    for (Object value : source) {
        value = maybeCopy(value);//from  w w  w  .java2 s.  co  m
        target.add(value);
    }
    return target;
}

From source file:eu.project.ttc.models.scored.ScoredModel.java

public void importTermIndex(TermIndex termIndex) {
    this.terms = Lists.newLinkedList();
    for (Term t : termIndex.getTerms()) {
        List<ScoredVariation> scoredVariations = Lists.newArrayListWithExpectedSize(t.getVariations().size());
        ScoredTerm st = getAdapter(t);//from w w w.  ja v a 2s . c  o  m
        for (TermVariation tv : t.getVariations()) {
            ScoredVariation stv = new ScoredVariation(this, tv);
            scoredVariations.add(stv);
        }
        st.setVariations(scoredVariations);
        this.terms.add(st);
    }
    this.termIndex = termIndex;
}

From source file:com.metamx.druid.query.metadata.ListColumnIncluderator.java

@Override
public byte[] getCacheKey() {
    int size = 1;
    List<byte[]> columns = Lists.newArrayListWithExpectedSize(this.columns.size());

    for (String column : this.columns) {
        final byte[] bytes = column.getBytes(Charsets.UTF_8);
        columns.add(bytes);/*  w ww  . j  a  v a2 s. c  o  m*/
        size += bytes.length;
    }

    final ByteBuffer bytes = ByteBuffer.allocate(size).put(LIST_CACHE_PREFIX);
    for (byte[] column : columns) {
        bytes.put(column);
    }

    return bytes.array();
}

From source file:com.threerings.tools.gxlate.spreadsheet.Table.java

/**
 * Creates a new table from the given worksheet entry. A worksheet is a single tab on a google
 * spreadsheet.// w w w. j a v a2  s  .  c o m
 */
public Table(WorksheetEntry worksheet) throws ServiceException, IOException {
    _worksheet = worksheet;
    _rows = Lists.newArrayListWithExpectedSize(worksheet.getRowCount());
    process(worksheet.getService().getFeed(worksheet.getCellFeedUrl(), CellFeed.class));
}