List of usage examples for com.google.common.collect Lists newArrayListWithCapacity
@GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayListWithCapacity(int initialArraySize)
From source file:org.terasology.persistence.typeSerialization.typeHandlers.extension.CollisionGroupTypeHandler.java
public List<CollisionGroup> deserializeCollection(EntityData.Value value) { List<CollisionGroup> result = Lists.newArrayListWithCapacity(value.getStringCount()); for (String name : value.getStringList()) { CollisionGroup group = groupManager.getCollisionGroup(name); if (group != null) { result.add(group);//from w w w . j av a 2 s .c o m } } return result; }
From source file:org.apache.hadoop.metrics2.impl.MetricsCollectorImpl.java
public List<MetricsRecordImpl> getRecords() { List<MetricsRecordImpl> recs = Lists.newArrayListWithCapacity(rbs.size()); for (MetricsRecordBuilderImpl rb : rbs) { MetricsRecordImpl mr = rb.getRecord(); if (mr != null) { recs.add(mr);/*from w w w . j a v a 2 s. co m*/ } } return recs; }
From source file:com.google.template.soy.basetree.AbstractReturningNodeVisitor.java
/** * Helper to visit all the children of a node, in order. * @param node The parent node whose children to visit. * @return The list of return values from visiting the children. * @see #visitChildrenAllowingConcurrentModification *//* ww w . j ava 2s .c o m*/ protected List<R> visitChildren(ParentNode<? extends N> node) { List<R> results = Lists.newArrayListWithCapacity(node.numChildren()); for (N child : node.getChildren()) { results.add(visit(child)); } return results; }
From source file:com.continuuity.weave.common.Services.java
/** * Performs the actual logic of chain Service start/stop. *//*w ww .j a v a 2s .co m*/ private static ListenableFuture<List<ListenableFuture<Service.State>>> doChain(boolean doStart, Service firstService, Service... moreServices) { SettableFuture<List<ListenableFuture<Service.State>>> resultFuture = SettableFuture.create(); List<ListenableFuture<Service.State>> result = Lists.newArrayListWithCapacity(moreServices.length + 1); ListenableFuture<Service.State> future = doStart ? firstService.start() : firstService.stop(); future.addListener( createChainListener(future, moreServices, new AtomicInteger(0), result, resultFuture, doStart), Threads.SAME_THREAD_EXECUTOR); return resultFuture; }
From source file:org.terasology.utilities.collection.TypeListMultimap.java
private <U extends T> List<U> convertList(Class<U> type, Collection<T> values) { List<U> results = Lists.newArrayListWithCapacity(values.size()); for (T value : values) { results.add(type.cast(value));//w w w .j a v a2 s .c om } return results; }
From source file:com.opengamma.web.analytics.Inliner.java
private static List<ColumnMeta> getTenorLabelledLocalDateDoubleTimeSeriesMatrix1DColumnMeta( TenorLabelledLocalDateDoubleTimeSeriesMatrix1D matrix) { List<ColumnMeta> meta = Lists.newArrayListWithCapacity(matrix.size()); meta.add(new ColumnMeta(matrix.getKeys()[0], matrix.getKeys()[0].toString(), LocalDateDoubleTimeSeries.class, TenorLabelledLocalDateDoubleTimeSeriesMatrix1D.class)); for (int i = 1; i < matrix.size(); i++) { meta.add(new ColumnMeta(matrix.getKeys()[i], matrix.getKeys()[i].toString(), LocalDateDoubleTimeSeries.class, null)); }//from w ww . j av a 2s. co m return meta; }
From source file:com.google.gerrit.server.index.PredicateWrapper.java
public PredicateWrapper(Predicate<ChangeData> pred, Collection<ChangeIndex> indexes) throws QueryParseException { this.pred = pred; sources = Lists.newArrayListWithCapacity(indexes.size()); for (ChangeIndex index : indexes) { sources.add(index.getSource(pred)); }//from w w w . j a v a 2s . co m }
From source file:org.ambraproject.wombat.util.HttpDebug.java
private static List<String> formatCookies(Cookie[] cookies) { if (cookies == null) { return null; }//from w w w . ja v a 2 s . co m List<String> cookieStrings = Lists.newArrayListWithCapacity(cookies.length); for (Cookie cookie : cookies) { cookieStrings.add(MoreObjects.toStringHelper(Cookie.class).add("Comment", cookie.getComment()) .add("Domain", cookie.getDomain()).add("MaxAge", cookie.getMaxAge()) .add("Path", cookie.getPath()).add("Secure", cookie.getSecure()).add("Name", cookie.getName()) .add("Value", cookie.getValue()).add("Version", cookie.getVersion()).toString()); } return cookieStrings; }
From source file:com.android.tools.idea.rendering.TagSnapshot.java
@NotNull public static TagSnapshot createTagSnapshot(@NotNull XmlTag tag) { // Attributes List<AttributeSnapshot> attributes = AttributeSnapshot.createAttributesForTag(tag); // Children//ww w. j a v a 2 s . c o m List<TagSnapshot> children; XmlTag[] subTags = tag.getSubTags(); if (subTags.length > 0) { TagSnapshot last = null; children = Lists.newArrayListWithCapacity(subTags.length); for (XmlTag subTag : subTags) { TagSnapshot child = createTagSnapshot(subTag); children.add(child); if (last != null) { last.myNext = child; } last = child; } } else { children = Collections.emptyList(); } return new TagSnapshot(tag, tag.getName(), tag.getNamespacePrefix(), tag.getNamespace(), attributes, children); }
From source file:com.digitalpetri.opcua.sdk.server.api.MethodServices.java
/** * Invoke one or more methods belonging to this {@link MethodServices}. * * @param context the {@link CallContext}. * @param requests The {@link CallMethodRequest}s for the methods to invoke. *///from ww w . j av a2s . c om default void call(CallContext context, List<CallMethodRequest> requests) { List<CompletableFuture<CallMethodResult>> results = Lists.newArrayListWithCapacity(requests.size()); for (CallMethodRequest request : requests) { MethodInvocationHandler handler = getInvocationHandler(request.getMethodId()) .orElse(new NodeIdUnknownHandler()); CompletableFuture<CallMethodResult> resultFuture = new CompletableFuture<>(); try { handler.invoke(request, resultFuture); } catch (Throwable t) { LoggerFactory.getLogger(getClass()).error( "Uncaught Throwable invoking method handler for methodId={}.", request.getMethodId(), t); resultFuture.complete(new CallMethodResult(new StatusCode(StatusCodes.Bad_InternalError), new StatusCode[0], new DiagnosticInfo[0], new Variant[0])); } results.add(resultFuture); } sequence(results).thenAccept(rs -> context.getFuture().complete(rs)); }