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.cloudera.oryx.computation.common.records.Specs.java
public static List<Integer> getFieldIds(Spec spec, List<String> values) { if (values.isEmpty()) { return ImmutableList.of(); }/*from w ww .ja va 2s . c o m*/ List<Integer> fieldIds = Lists.newArrayListWithExpectedSize(values.size()); if (spec == null || spec.getField(values.get(0)) == null) { for (String value : values) { try { fieldIds.add(Integer.valueOf(value)); } catch (NumberFormatException e) { throw new IllegalArgumentException("Did not recognize column ID: " + value); } } } else { for (String value : values) { FieldSpec f = spec.getField(value); if (f != null) { fieldIds.add(f.position()); } } } return fieldIds; }
From source file:org.apache.druid.query.Queries.java
public static List<PostAggregator> decoratePostAggregators(List<PostAggregator> postAggs, Map<String, AggregatorFactory> aggFactories) { List<PostAggregator> decorated = Lists.newArrayListWithExpectedSize(postAggs.size()); for (PostAggregator aggregator : postAggs) { decorated.add(aggregator.decorate(aggFactories)); }//from w w w.ja v a 2 s. c om return decorated; }
From source file:com.cloudera.exhibit.mongodb.BSONObsDescriptor.java
private static List<String> getColumns(List<String> names, final Map<String, String> mappings) { List<String> ret = Lists.newArrayListWithExpectedSize(names.size()); for (int i = 0; i < names.size(); i++) { String key = names.get(i); String col = mappings.get(key); ret.add(col == null ? key : col); }/*from w ww. j a v a 2s.c o m*/ return ret; }
From source file:nextmethod.web.razor.parser.syntaxtree.BlockExtensions.java
public static Collection<SyntaxTreeNode> buildSpanConstructors(final Collection<SyntaxTreeNode> children) { final List<SyntaxTreeNode> built = Lists.newArrayListWithExpectedSize(children.size()); for (SyntaxTreeNode child : children) { if (ISpanConstructorClass.isAssignableFrom(child.getClass())) { built.add(ISpanConstructorClass.cast(child).build()); } else {//from w w w . ja v a2 s . co m built.add(child); } } return built; }
From source file:com.vmware.photon.controller.api.Component.java
/** * Translates a collection of Strings into Component Enums. *//* ww w .j ava 2 s. c om*/ public static Set<Component> fromStrings(Collection<String> values) { List<Component> result = Lists.newArrayListWithExpectedSize(values.size()); for (String value : values) { result.add(Component.fromString(value)); } return EnumSet.copyOf(result); }
From source file:com.cloudera.science.ml.core.formula.Formula.java
public static Formula compile(List<Term> terms, Summary summary) { Spec spec = summary.getSpec();/*from w w w .j av a 2s .co m*/ List<Term> internalTerms = Lists.newArrayList(terms); Collections.sort(internalTerms); List<CompiledTerm> compiled = Lists.newArrayListWithExpectedSize(terms.size()); int offset = 0; boolean hasIntercept = internalTerms.get(0).isIntercept(); for (Term t : terms) { List<Integer> numerics = Lists.newArrayList(); List<Integer> categoricals = Lists.newArrayList(); List<List<String>> hist = Lists.newArrayList(); for (String field : t) { FieldSpec fs = spec.getField(field); SummaryStats ss = summary.getStats(fs.position()); if (ss.isNumeric()) { numerics.add(fs.position()); } else { categoricals.add(fs.position()); hist.add(ss.getLevels()); } } compiled.add(new CompiledTerm(numerics, categoricals, hist, offset)); if (categoricals.isEmpty()) { offset++; } else { int prod = 1; for (List<String> h : hist) { prod *= h.size(); } offset += prod - (hasIntercept ? 1 : 0); } } return new Formula(compiled, offset, offset > 2 * terms.size(), hasIntercept); }
From source file:javastory.tools.CollectionUtil.java
/** * Copies <code>count</code> items off of list, starting from the beginning. * //from w w w .j a v a 2 s.co m * @param <T> * The type of the list. * @param list * The list to copy from. * @param count * The number of items to copy. * @return The copied list. */ public static <T> List<T> copyFirst(final List<T> list, final int count) { final int size = list.size() < count ? list.size() : count; final List<T> ret = Lists.newArrayListWithExpectedSize(size); int i = 0; for (final T elem : list) { ret.add(elem); if (i++ > count) { break; } } return ret; }
From source file:org.apache.bookkeeper.server.component.ServerLifecycleComponent.java
public static List<ServerLifecycleComponent> loadServerComponents(String[] componentClassNames, BookieConfiguration conf, StatsLogger statsLogger) { List<Class<? extends ServerLifecycleComponent>> componentClasses = Lists .newArrayListWithExpectedSize(componentClassNames.length); for (String componentClsName : componentClassNames) { componentClasses.add(ReflectionUtils.forName(componentClsName, ServerLifecycleComponent.class)); }/* ww w. j a va 2s . c o m*/ return Lists.transform(componentClasses, cls -> newComponent(cls, conf, statsLogger)); }
From source file:com.google.devtools.depan.platform.eclipse.ui.widgets.Selections.java
/** * Use only when it is essential to have the elements in order. *//*from w ww.ja va2 s .c o m*/ public static <T> List<T> getSelectionList(ISelection selection, Class<T> type) { List<?> choices = getObjects(selection); if (choices.isEmpty()) { return Collections.emptyList(); } List<T> result = Lists.newArrayListWithExpectedSize(choices.size()); for (Object item : choices) { if (type.isAssignableFrom(item.getClass())) { result.add(type.cast(item)); } } return result; }
From source file:org.carrot2.source.pubmed.PubMedSearchHandler.java
public void startDocument() throws SAXException { pubMedPrimaryIds = Lists.newArrayListWithExpectedSize(100); handlingId = false;// w w w . j av a 2s .com id = new StringBuffer(); }