List of usage examples for com.google.common.collect Lists newArrayListWithExpectedSize
@GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayListWithExpectedSize(int estimatedSize)
From source file:com.android.tools.idea.rendering.IncludeOverlay.java
/** Computes the set of rectangles we should paint to cover everything up <b>except</b> for * the included root bounds. The coordinates will be in the coordinate system of the given * component./*from www . j av a 2s. c o m*/ */ protected Collection<Rectangle> computeMasks(Component component, List<RenderedView> includedRoots) { Dimension fullImageSize = myContainer.getFullImageSize(); Rectangle whole = new Rectangle(0, 0, fullImageSize.width, fullImageSize.height); whole = myContainer.fromModel(component, whole); List<Rectangle> includedBounds = Lists.newArrayListWithExpectedSize(includedRoots.size()); for (RenderedView view : includedRoots) { includedBounds.add(myContainer.fromModel(component, view.getBounds())); } return subtractRectangles(whole, includedBounds); }
From source file:org.apache.bookkeeper.stream.cluster.StreamCluster.java
private StreamCluster(StreamClusterSpec spec) { super("stream-cluster", new StorageConfiguration(spec.baseConf()), NullStatsLogger.INSTANCE); this.spec = spec; this.servers = Lists.newArrayListWithExpectedSize(spec.numServers()); this.rpcEndpoints = Lists.newArrayListWithExpectedSize(spec.numServers()); this.nextBookiePort = spec.initialBookiePort(); this.nextGrpcPort = spec.initialGrpcPort(); }
From source file:defrac.intellij.psi.MacroMethodReference.java
@NotNull @Override//from w w w.j a va 2s. c om public final ResolveResult[] multiResolve(final boolean incompleteCode) { final ResolveResult[] parentResults = parent.multiResolve(incompleteCode); final ArrayList<ResolveResult> result = Lists.newArrayListWithExpectedSize(parentResults.length); final String value = getValue(); for (final ResolveResult parentResult : parentResults) { final PsiElement parentElement = parentResult.getElement(); if (!(parentElement instanceof PsiClass)) { continue; } final PsiClass klass = (PsiClass) parentElement; final PsiMethod[] methods = klass.findMethodsByName(value, true); for (final PsiMethod method : methods) { result.add(new PsiElementResolveResult(method)); } } return result.toArray(new ResolveResult[result.size()]); }
From source file:eu.project.ttc.termino.engines.TermVariationScorer.java
private void doScoredModel(TermIndex termIndex) { scoredModel = new ScoredModel(); scoredModel.importTermIndex(termIndex); scoredModel.sort(wrComparator);/* www. j ava 2 s . com*/ int size = scoredModel.getTerms().size(); filterTerms(); LOGGER.debug("Filtered {} terms out of {}", size - scoredModel.getTerms().size(), size); int sizeBefore = 0; int sizeAfter = 0; for (ScoredTerm t : scoredModel.getTerms()) { if (t.getVariations().isEmpty()) continue; List<ScoredVariation> sv = Lists.newArrayListWithExpectedSize(t.getVariations().size()); sv.addAll(t.getVariations()); sizeBefore += sv.size(); filterVariations(sv); sizeAfter += sv.size(); Collections.sort(sv, variationScoreComparator); t.setVariations(sv); } LOGGER.debug("Filtered {} variants out of {}", sizeBefore - sizeAfter, sizeBefore); scoredModel.sort(wrComparator); }
From source file:eu.interedition.web.text.TextIndex.java
public List<TextIndexQueryResult> search(TextIndexQuery query) throws IOException, ParseException { if (Strings.isNullOrEmpty(query.getQuery())) { return Collections.emptyList(); }//from w ww . j av a 2 s . c om final Query parsed = new QueryParser(Version.LUCENE_30, "content", analyzer).parse(query.getQuery()); final int pageSize = query.getPageSize(); final int offset = query.getPage() * pageSize; final Map<Long, Integer> scores = Maps.newLinkedHashMap(); final IndexSearcher searcher = indexSearcher(); final TopDocs searchResult = searcher.search(parsed, offset + pageSize); for (int rc = offset; rc < searchResult.scoreDocs.length; rc++) { final ScoreDoc scoreDocument = searchResult.scoreDocs[rc]; final Document document = searcher.doc(scoreDocument.doc); scores.put(Long.parseLong(document.get("id")), Math.round(scoreDocument.score * 100)); } final List<TextIndexQueryResult> results = Lists.newArrayListWithExpectedSize(scores.size()); for (TextMetadata metadata : textService.load(scores.keySet())) { results.add(new TextIndexQueryResult(metadata, scores.get(metadata.getText().getId()))); } return results; }
From source file:com.android.tools.idea.npw.TemplateWizardModuleBuilder.java
/** * Create a template chooser step populated with the correct templates for the new modules. *///from w w w . j a v a 2s . co m private ChooseTemplateStep buildChooseModuleStep(@Nullable Project project) { // We're going to build up our own list of templates here // This is a little hacky, we should clean this up later. ChooseTemplateStep chooseModuleStep = new ChooseTemplateStep(myWizardState, null, project, null, AndroidIcons.Wizards.NewModuleSidePanel, this, this); Set<String> excludedTemplates = Sets.newHashSet(); Set<ChooseTemplateStep.MetadataListItem> builtinTemplateList = new TreeSet<>( new Comparator<ChooseTemplateStep.MetadataListItem>() { @Override public int compare(ChooseTemplateStep.MetadataListItem o1, ChooseTemplateStep.MetadataListItem o2) { return Collator.getInstance().compare(o1.toString(), o2.toString()); } }); for (WizardPath path : myPaths) { excludedTemplates.addAll(path.getExcludedTemplates()); Collection<ChooseTemplateStep.MetadataListItem> templates = path.getBuiltInTemplates(); builtinTemplateList.addAll(templates); for (ChooseTemplateStep.MetadataListItem template : templates) { myWizardState.associateTemplateWithPath(template.toString(), path); } } // Get the list of templates to offer, but exclude the NewModule and NewProject template List<ChooseTemplateStep.MetadataListItem> templateList = ChooseTemplateStep.getTemplateList(myWizardState, CATEGORY_PROJECTS, excludedTemplates); List<ChooseTemplateStep.MetadataListItem> list = Lists .newArrayListWithExpectedSize(builtinTemplateList.size() + templateList.size()); list.addAll(builtinTemplateList); list.addAll(templateList); chooseModuleStep.setListData(list); return chooseModuleStep; }
From source file:ei.ne.ke.cassandra.cql3.SimpleEntitySpecification.java
/** * {@inheritDoc}/* www . ja va2s. c om*/ */ @Override @SuppressWarnings("unchecked") public List<ID> getKey(List<T> entities) { try { List<ID> keys = Lists.newArrayListWithExpectedSize(entities.size()); for (T entity : entities) { keys.add((ID) keyField.get(entity)); } return keys; } catch (IllegalAccessException e) { throw new IllegalStateException("Couldn't access key field annotated", e); } }
From source file:com.cloudera.nav.sdk.client.NavApiCient.java
/** * Call the Navigator API and retrieve all available sources * * @return a collection of available sources *///from ww w. ja v a2 s . c o m public Collection<Source> getAllSources() { String url = entitiesQueryUrl(); SourceAttrs[] sourceAttrs = sendRequest(url, HttpMethod.GET, SourceAttrs[].class); Collection<Source> sources = Lists.newArrayListWithExpectedSize(sourceAttrs.length + 1); for (SourceAttrs info : sourceAttrs) { sources.add(info.createSource()); } return sources; }
From source file:defrac.intellij.projectView.DefracViewProjectNode.java
@NotNull private Collection<AbstractTreeNode> defracModules(@NotNull final Project project, @NotNull final Collection<DefracProject> defracProjects) { final ArrayList<AbstractTreeNode> result = Lists.newArrayListWithExpectedSize(defracProjects.size()); for (final DefracProject defracProject : defracProjects) { result.add(new DefracViewDefracNode(project, defracProject, getSettings())); }//from w ww . ja v a2 s. c o m return result; }
From source file:io.druid.java.util.common.parsers.JSONParser.java
@Override public Map<String, Object> parse(String input) { try {//from w w w . j a v a2 s . co m Map<String, Object> map = new LinkedHashMap<>(); JsonNode root = objectMapper.readTree(input); Iterator<String> keysIter = (fieldNames == null ? root.fieldNames() : fieldNames.iterator()); while (keysIter.hasNext()) { String key = keysIter.next(); if (exclude.contains(key)) { continue; } JsonNode node = root.path(key); if (node.isArray()) { final List<Object> nodeValue = Lists.newArrayListWithExpectedSize(node.size()); for (final JsonNode subnode : node) { final Object subnodeValue = valueFunction.apply(subnode); if (subnodeValue != null) { nodeValue.add(subnodeValue); } } map.put(key, nodeValue); } else { final Object nodeValue = valueFunction.apply(node); if (nodeValue != null) { map.put(key, nodeValue); } } } return map; } catch (Exception e) { throw new ParseException(e, "Unable to parse row [%s]", input); } }