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.eclipse.xtext.common.types.xtext.ui.JdtBasedConstructorScope.java

@Override
protected Iterable<IEObjectDescription> internalGetAllElements() {
    IJavaProject javaProject = getTypeProvider().getJavaProject();
    if (javaProject == null)
        return Collections.emptyList();
    final List<IEObjectDescription> allScopedElements = Lists.newArrayListWithExpectedSize(25000);
    try {// w  w w .  j a v a 2s  .c  o  m
        IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject });
        SearchRequestor searchRequestor = new SearchRequestor() {
            @Override
            public void acceptSearchMatch(SearchMatch match) throws CoreException {
                Object element = match.getElement();
                if (element instanceof IMethod) {
                    IMethod constructor = (IMethod) element;
                    allScopedElements.add(createScopedElement(constructor));
                } else if (element instanceof IType) {
                    allScopedElements.add(createScopedElement((IType) element));
                }
            }
        };
        collectContents(searchScope, searchRequestor);
    } catch (CoreException e) {
        logger.error("CoreException when searching for constructors.", e);
    }
    return allScopedElements;
}

From source file:com.android.tools.idea.res.ProjectResourceRepository.java

private static List<LocalResourceRepository> computeRepositories(@NotNull final AndroidFacet facet) {
    LocalResourceRepository main = ModuleResourceRepository.getModuleResources(facet, true);

    // List of module facets the given module depends on
    List<AndroidFacet> dependentFacets = AndroidUtils.getAllAndroidDependencies(facet.getModule(), true);
    if (dependentFacets.isEmpty()) {
        return Collections.singletonList(main);
    }//w  ww.j  a  va  2  s .c om

    List<LocalResourceRepository> resources = Lists.newArrayListWithExpectedSize(dependentFacets.size());

    for (AndroidFacet f : dependentFacets) {
        LocalResourceRepository r = ModuleResourceRepository.getModuleResources(f, true);
        resources.add(r);
    }

    resources.add(main);

    return resources;
}

From source file:com.flaptor.indextank.util.Union.java

@Override
public SkippableIterator<V> iterator() {
    return new AbstractSkippableIterator<V>() {
        private List<PeekingSkippableIterator<K>> iterators = Lists
                .newArrayList(Iterables.transform(cursors, Union.<K>peekingIteratorFunction()));
        /*// w w w  .  ja  v  a 2  s. co  m
         * SortedSet with all the heads (first elements) for all the iterators and the position in the iterators list of the
         * SkippableIterator the element is in.
         */
        private TreeSet<Head<K>> heads = new TreeSet<Head<K>>(new Comparator<Head<K>>() {
            @Override
            public int compare(Head<K> o1, Head<K> o2) {
                int compare = comp(o1.value, o2.value);
                if (compare != 0) {
                    return compare;
                } else {
                    return o1.position - o2.position;
                }
            }
        });

        private List<Head<K>> prebuiltHeads = Lists.newArrayListWithExpectedSize(iterators.size());
        {
            for (int i = 0; i < iterators.size(); i++) {
                prebuiltHeads.add(new Head<K>(i));
            }
        }

        private Head<K> getHead(int position, K value) {
            Head<K> head = prebuiltHeads.get(position);
            head.value = value;
            return head;
        }

        {
            /*
             *  Keep all the heads of all the iterators sorted.  
             */
            for (int i = 0; i < iterators.size(); i++) {
                PeekingSkippableIterator<K> it = iterators.get(i);
                if (it.hasNext()) {
                    heads.add(getHead(i, it.next()));
                }
            }

        }

        private List<K> ks = Lists.newArrayList();
        private BitSet nextsToDo = new BitSet();

        @Override
        protected V computeNext() {
            while (true) {
                int pos = 0;
                while (true) {
                    pos = nextsToDo.nextSetBit(pos);
                    if (pos < 0) {
                        break;
                    }
                    if (iterators.get(pos).hasNext()) {
                        heads.add(getHead(pos, iterators.get(pos).next()));
                    }
                    nextsToDo.clear(pos);
                    pos++;
                }

                Head<K> currentElement = heads.pollFirst();
                if (currentElement == null) {
                    return endOfData();
                }
                int position = currentElement.position;
                nextsToDo.set(position);

                // advance the iterator from which we took the last element
                PeekingSkippableIterator<K> peekingSkippableIterator = iterators.get(position);

                ks.clear();

                K currentK = currentElement.value;
                ks.add(currentK);

                // add all other heads while the key is the same
                while (heads.size() > 0 && comp(heads.first().value, currentK) == 0) {
                    Head<K> newElement = heads.pollFirst();
                    nextsToDo.set(newElement.position);

                    PeekingSkippableIterator<K> newElementIterator = iterators.get(newElement.position);
                    ks.add(newElement.value);
                }

                V v = transform(ks.get(0));
                if (shouldUse(v, ks)) {
                    return v;
                }
            }
        }

        @Override
        public void skipTo(int i) {
            for (SkippableIterator<K> it : iterators) {
                it.skipTo(i);
            }
        }
    };
}

From source file:com.android.tools.idea.run.tasks.SplitApkDeployTask.java

@Override
public boolean perform(@NotNull IDevice device, @NotNull LaunchStatus launchStatus,
        @NotNull ConsolePrinter printer) {
    InstantRunBuildInfo buildInfo = myInstantRunContext.getInstantRunBuildInfo();
    assert buildInfo != null;

    List<InstantRunArtifact> artifacts = buildInfo.getArtifacts();

    List<String> installOptions = Lists.newArrayList(); // TODO: should we pass in pm install options?

    if (buildInfo.isPatchBuild()) {
        installOptions.add("-p"); // partial install
        installOptions.add(myInstantRunContext.getApplicationId());
    }/*from w w w  .j  a  va2  s . co m*/

    List<File> apks = Lists.newArrayListWithExpectedSize(artifacts.size());
    for (InstantRunArtifact artifact : artifacts) {
        if (artifact.type == InstantRunArtifactType.SPLIT_MAIN
                || artifact.type == InstantRunArtifactType.SPLIT) {
            apks.add(artifact.file);
        }
    }

    RetryingInstaller.Installer installer = new SplitApkInstaller(printer, apks, installOptions);

    RetryingInstaller retryingInstaller = new RetryingInstaller(myProject, device, installer,
            myInstantRunContext.getApplicationId(), printer, launchStatus);
    boolean status = retryingInstaller.install();
    if (status) {
        printer.stdout("Split APKs installed");
    }

    assert myInstantRunContext.getBuildSelection() != null;
    InstantRunStatsService.get(myProject).notifyDeployType(DeployType.SPLITAPK, myInstantRunContext, device);

    return status;
}

From source file:com.google.devtools.depan.remap_doc.eclipse.ui.plugins.RemapRegistry.java

public Collection<RemapContributor> getRemapContributions() {
    Collection<ContributionEntry<RemapContributor>> contribs = getContributions();
    List<RemapContributor> result = Lists.newArrayListWithExpectedSize(contribs.size());
    for (ContributionEntry<RemapContributor> item : contribs) {
        result.add(item.getInstance());/*w  ww .  j a v a2 s .c o m*/
    }
    return result;
}

From source file:org.apache.mahout.clustering.streaming.mapreduce.StreamingKMeansThread.java

@Override
public Iterable<Centroid> call() {
    UpdatableSearcher searcher = StreamingKMeansUtilsMR.searcherFromConfiguration(conf);
    int numClusters = conf.getInt(StreamingKMeansDriver.ESTIMATED_NUM_MAP_CLUSTERS, 1);
    double estimateDistanceCutoff = conf.getFloat(StreamingKMeansDriver.ESTIMATED_DISTANCE_CUTOFF,
            StreamingKMeansDriver.INVALID_DISTANCE_CUTOFF);

    Iterator<Centroid> dataPointsIterator = dataPoints.iterator();

    if (estimateDistanceCutoff == StreamingKMeansDriver.INVALID_DISTANCE_CUTOFF) {
        List<Centroid> estimatePoints = Lists.newArrayListWithExpectedSize(NUM_ESTIMATE_POINTS);
        while (dataPointsIterator.hasNext() && estimatePoints.size() < NUM_ESTIMATE_POINTS) {
            Centroid centroid = dataPointsIterator.next();
            estimatePoints.add(centroid);
        }//w w  w.j ava  2 s  . c  o  m

        if (log.isInfoEnabled()) {
            log.info("Estimated Points: {}", estimatePoints.size());
        }
        estimateDistanceCutoff = ClusteringUtils.estimateDistanceCutoff(estimatePoints,
                searcher.getDistanceMeasure());
    }

    StreamingKMeans streamingKMeans = new StreamingKMeans(searcher, numClusters, estimateDistanceCutoff);

    // datapointsIterator could be empty if no estimate distance was initially provided
    // hence creating the iterator again here for the clustering
    if (!dataPointsIterator.hasNext()) {
        dataPointsIterator = dataPoints.iterator();
    }

    while (dataPointsIterator.hasNext()) {
        streamingKMeans.cluster(dataPointsIterator.next());
    }

    streamingKMeans.reindexCentroids();
    return streamingKMeans;
}

From source file:com.palantir.ptoss.cinch.swing.JListWiringHarness.java

private static void updateListModel(JList list, List<?> newContents) {
    if (newContents == null) {
        newContents = ImmutableList.of();
    }/*from w w w  .  j  a  v a  2 s .  c  o  m*/
    ListModel oldModel = list.getModel();
    List<Object> old = Lists.newArrayListWithExpectedSize(oldModel.getSize());
    for (int i = 0; i < oldModel.getSize(); i++) {
        old.add(oldModel.getElementAt(i));
    }
    if (old.equals(newContents)) {
        return;
    }
    Object[] selected = list.getSelectedValues();
    DefaultListModel listModel = new DefaultListModel();
    for (Object obj : newContents) {
        listModel.addElement(obj);
    }
    list.setModel(listModel);
    List<Integer> newIndices = Lists.newArrayListWithCapacity(selected.length);
    Set<Object> selectedSet = Sets.newHashSet(selected);
    for (int i = 0; i < listModel.size(); i++) {
        if (selectedSet.contains(listModel.elementAt(i))) {
            newIndices.add(i);
        }
    }
    list.setSelectedIndices(ArrayUtils.toPrimitive(newIndices.toArray(new Integer[0])));
}

From source file:org.thingsboard.server.dao.attributes.BaseAttributesService.java

@Override
public ListenableFuture<List<Void>> save(TenantId tenantId, EntityId entityId, String scope,
        List<AttributeKvEntry> attributes) {
    validate(entityId, scope);/* ww  w. ja v a  2  s  . co m*/
    attributes.forEach(attribute -> validate(attribute));
    List<ListenableFuture<Void>> futures = Lists.newArrayListWithExpectedSize(attributes.size());
    for (AttributeKvEntry attribute : attributes) {
        futures.add(attributesDao.save(tenantId, entityId, scope, attribute));
    }
    return Futures.allAsList(futures);
}

From source file:gr.forth.ics.swkm.model2.labels.MainMemoryHierarchy.java

@Override
protected Collection<Node> exploreAdjacent(Node node, Direction direction) {
    Collection<Node> nodes = Lists.newArrayListWithExpectedSize(exploredGraph().degree(node, direction));
    for (Edge e : exploredGraph().edges(node, direction)) {
        nodes.add(e.opposite(node));//ww w. ja  va 2 s .  co m
    }
    return nodes;
}

From source file:cosmos.web.servlet.MostRecent.java

protected List<TracerResponse> transform(List<Tracer> tracers) {
    List<TracerResponse> tracerResponses = Lists.newArrayListWithExpectedSize(tracers.size());

    for (Tracer tracer : tracers) {
        tracerResponses.add(transform(tracer));
    }/*from   w  w w. j ava  2  s.  c  om*/

    return tracerResponses;
}