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:com.android.tools.idea.editors.strings.StringsWriteUtils.java

/**
 * Sets the value of an attribute for resource items.  If SdkConstants.ATTR_NAME is set to null or "", the items are deleted.
 *
 * @param attribute The attribute whose value we wish to change
 * @param value     The desired attribute value
 * @param items     The resource items/*from  ww w. j  a  va  2  s .c om*/
 * @return True if the value was successfully set, false otherwise
 */
public static boolean setAttributeForItems(@NotNull Project project, @NotNull final String attribute,
        @Nullable final String value, @NotNull List<ResourceItem> items) {
    if (items.isEmpty()) {
        return false;
    }
    final List<XmlTag> tags = Lists.newArrayListWithExpectedSize(items.size());
    final Set<PsiFile> files = Sets.newHashSetWithExpectedSize(items.size());
    for (ResourceItem item : items) {
        XmlTag tag = LocalResourceRepository.getItemTag(project, item);
        if (tag == null) {
            return false;
        }
        tags.add(tag);
        files.add(tag.getContainingFile());
    }
    final boolean deleteTag = attribute.equals(SdkConstants.ATTR_NAME) && (value == null || value.isEmpty());
    new WriteCommandAction.Simple(project, "Setting attribute " + attribute,
            files.toArray(new PsiFile[files.size()])) {
        @Override
        public void run() {
            for (XmlTag tag : tags) {
                if (deleteTag) {
                    tag.delete();
                } else {
                    // XmlTagImpl handles a null value by deleting the attribute, which is our desired behavior
                    //noinspection ConstantConditions
                    tag.setAttribute(attribute, value);
                }
            }
        }
    }.execute();
    return true;
}

From source file:org.cordovastudio.editors.designer.utils.ReplaceTagFix.java

@Override
protected void run(Result<Void> result) throws Throwable {
    Collection<XmlTag> xmlTags = PsiTreeUtil.findChildrenOfType(myFile, XmlTag.class);
    if (!xmlTags.isEmpty()) {
        List<XmlTag> matching = Lists.newArrayListWithExpectedSize(xmlTags.size());
        for (XmlTag tag : xmlTags) {
            if (tag.getName().equals(myWrongTag)) {
                matching.add(tag);//  w ww .  j  a  v  a2 s . co m
            }
        }
        if (!matching.isEmpty()) {
            for (XmlTag tag : matching) {
                tag.setName(myRightTag);
            }
        }
    }
}

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

@Override
protected void run(@NotNull Result<Void> result) throws Throwable {
    Collection<XmlTag> xmlTags = PsiTreeUtil.findChildrenOfType(myFile, XmlTag.class);
    if (!xmlTags.isEmpty()) {
        List<XmlTag> matching = Lists.newArrayListWithExpectedSize(xmlTags.size());
        for (XmlTag tag : xmlTags) {
            if (tag.getName().equals(myWrongTag)) {
                matching.add(tag);//from  ww  w  .  j a  va  2s . c o m
            }
        }
        if (!matching.isEmpty()) {
            for (XmlTag tag : matching) {
                tag.setName(myRightTag);
            }
        }
    }
}

From source file:com.github.reinert.jjschema.v1.CustomSchemaWrapper.java

public CustomSchemaWrapper(Class<?> type, Set<ManagedReference> managedReferences, String relativeId) {
    super(type);//from  ww  w  .  j  a  v  a  2s  .  co m
    setType("object");
    processNullable();
    processAttributes(getNode(), type);
    propertyWrappers = Lists.newArrayListWithExpectedSize(type.getDeclaredFields().length);
    this.managedReferences = managedReferences;
    if (relativeId != null) {
        addTokenToRelativeId(relativeId);
    }
    processProperties();
}

From source file:com.intellij.react.css.modules.psi.CssModulesStyleNameAttributePsiReferenceContributor.java

@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
    registrar.registerReferenceProvider(CssModulesUtil.STYLE_NAME_PATTERN, new PsiReferenceProvider() {
        @NotNull/*from ww  w  .java  2 s  . c o m*/
        @Override
        public PsiReference[] getReferencesByElement(@NotNull PsiElement element,
                @NotNull ProcessingContext context) {
            final StylesheetFile styleSheetFile = CssModulesUtil.getImportedStyleSheetFile(element);
            if (styleSheetFile != null) {
                final XmlAttributeValue xmlAttributeValue = (XmlAttributeValue) element;
                if (xmlAttributeValue.getValue().startsWith("{")) {
                    // attribute value is a jsx expression and not a literal class name
                    return PsiReference.EMPTY_ARRAY;
                }
                final String[] cssClassNames = xmlAttributeValue.getValue().split(" ");
                final List<PsiReference> referenceList = Lists.newArrayListWithExpectedSize(1);
                int offset = xmlAttributeValue.getValueTextRange().getStartOffset()
                        - xmlAttributeValue.getTextRange().getStartOffset();
                for (String cssClassName : cssClassNames) {
                    final Ref<CssClass> cssClassRef = new Ref<>(null);
                    cssClassRef.set(CssModulesUtil.getCssClass(styleSheetFile, "." + cssClassName));
                    final TextRange rangeInElement = TextRange.from(offset, cssClassName.length());
                    if (cssClassRef.get() != null) {
                        referenceList.add(new PsiReferenceBase<PsiElement>(element, rangeInElement) {
                            @Nullable
                            @Override
                            public PsiElement resolve() {
                                return cssClassRef.get();
                            }

                            @NotNull
                            @Override
                            public Object[] getVariants() {
                                return new Object[0];
                            }
                        });
                    } else {
                        referenceList.add(new CssModulesUnknownClassPsiReference(element, rangeInElement,
                                styleSheetFile));
                    }
                    offset += cssClassName.length() + 1;
                }
                return referenceList.toArray(new PsiReference[referenceList.size()]);
            }

            return PsiReference.EMPTY_ARRAY;
        }
    });
}

From source file:org.atlasapi.remotesite.bliptv.BlipTvClient.java

private List<String> locationUrisFrom(HtmlNavigator html) {
    List<String> relativeUrls = html.optionValuesWithinSelect("SelectFormat");
    List<String> absoluteUrls = Lists.newArrayListWithExpectedSize(relativeUrls.size());
    for (String url : relativeUrls) {
        absoluteUrls.add(applySubstitutionsTo("http://blip.tv" + url));
    }//ww w  .  j ava 2 s  .co  m
    return absoluteUrls;
}

From source file:org.elasticsearch.common.lucene.search.AndFilter.java

@Override
public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException {
    if (filters.size() == 1) {
        // LUCENE 4 UPGRADE: For leave this null, until we figure out how to deal with deleted docs...
        return filters.get(0).getDocIdSet(context, null);
    }/*from w w w . ja v a 2 s.  c  o m*/
    List sets = Lists.newArrayListWithExpectedSize(filters.size());
    boolean allAreDocSet = true;
    for (Filter filter : filters) {
        // LUCENE 4 UPGRADE: For leave this null, until we figure out how to deal with deleted docs...
        DocIdSet set = filter.getDocIdSet(context, null);
        if (set == null) { // none matching for this filter, we AND, so return EMPTY
            return DocSet.EMPTY_DOC_SET;
        }
        if (!(set instanceof DocSet)) {
            allAreDocSet = false;
        }
        sets.add(set);
    }
    if (allAreDocSet) {
        return new AndDocSet(sets);
    }
    return new AndDocIdSet(sets);
}

From source file:org.elasticsearch.common.lucene.search.OrFilter.java

@Override
public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException {
    if (filters.size() == 1) {
        // LUCENE 4 UPGRADE: For leave acceptedDocs null, until we figure out how to deal with deleted docs...
        return filters.get(0).getDocIdSet(context, null);
    }//from   ww w .  j  a v  a  2  s  . c o m
    List sets = Lists.newArrayListWithExpectedSize(filters.size());
    boolean allAreDocSet = true;
    for (Filter filter : filters) {
        // LUCENE 4 UPGRADE: For leave acceptedDocs null, until we figure out how to deal with deleted docs...
        DocIdSet set = filter.getDocIdSet(context, null);
        if (set == null) { // none matching for this filter, continue
            continue;
        }
        if (!(set instanceof DocSet)) {
            allAreDocSet = false;
        }
        sets.add(set);
    }
    if (sets.size() == 0) {
        return DocSet.EMPTY_DOC_SET;
    }
    if (sets.size() == 1) {
        return (DocIdSet) sets.get(0);
    }
    if (allAreDocSet) {
        return new OrDocSet(sets);
    }
    return new OrDocIdSet(sets);
}

From source file:com.google.devtools.depan.view_doc.layout.eclipse.ui.widgets.WizardMenuContributions.java

@Override
protected IContributionItem[] getContributionItems() {
    IWorkbenchWindow frame = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    List<LayoutPlanDocument<? extends LayoutPlan>> topLayouts = LayoutResources.getTopLayouts();
    List<IContributionItem> result = Lists.newArrayListWithExpectedSize(topLayouts.size());
    for (LayoutPlanDocument<? extends LayoutPlan> layoutDoc : topLayouts) {
        buildWizardItem(frame, layoutDoc.getName(), layoutDoc);
    }/* ww  w.  j  a v a 2 s.  c  om*/
    return Iterables.toArray(result, IContributionItem.class);
}

From source file:org.gradle.internal.resolve.ModuleVersionNotFoundException.java

private static String format(ModuleComponentSelector selector, Collection<String> locations,
        Collection<String> unmatchedVersions, Collection<RejectedVersion> rejectedVersions) {
    TreeFormatter builder = new TreeFormatter();
    if (unmatchedVersions.isEmpty() && rejectedVersions.isEmpty()) {
        builder.node(String.format("Could not find any matches for %s as no versions of %s:%s are available.",
                selector, selector.getGroup(), selector.getModule()));
    } else {/*from w w  w . j  a  v  a 2  s  .  com*/
        builder.node(String.format("Could not find any version that matches %s.", selector));
        if (!unmatchedVersions.isEmpty()) {
            builder.node("Versions that do not match");
            appendSizeLimited(builder, unmatchedVersions);
        }
        if (!rejectedVersions.isEmpty()) {
            Collection<RejectedVersion> byRule = Lists.newArrayListWithExpectedSize(rejectedVersions.size());
            Collection<RejectedVersion> byAttributes = Lists
                    .newArrayListWithExpectedSize(rejectedVersions.size());
            mapRejections(rejectedVersions, byRule, byAttributes);
            if (!byRule.isEmpty()) {
                builder.node("Versions rejected by component selection rules");
                appendSizeLimited(builder, byRule);
            }
            if (!byAttributes.isEmpty()) {
                builder.node("Versions rejected by attribute matching");
                appendSizeLimited(builder, byAttributes);
            }
        }
    }
    addLocations(builder, locations);
    return builder.toString();
}