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:ru.runa.wfe.user.logic.ProfileLogic.java
public List<Profile> getProfiles(User user, List<Long> actorIds) throws ExecutorDoesNotExistException { List<Profile> result = Lists.newArrayListWithCapacity(actorIds.size()); for (Long actorId : actorIds) { Actor actor = executorDao.getActor(actorId); permissionDao.checkAllowed(user, Permission.LIST, actor); result.add(getProfile(actor));/*from ww w . j a v a2 s . c om*/ } return result; }
From source file:org.terasology.persistence.typeSerialization.typeHandlers.core.ByteTypeHandler.java
@Override public List<Byte> deserializeCollection(EntityData.Value value) { if (value.hasBytes()) { List<Byte> result = Lists.newArrayListWithCapacity(value.getBytes().size()); for (byte b : value.getBytes().toByteArray()) { result.add(b);//from ww w . j ava 2s . c o m } return result; } return null; }
From source file:co.cask.cdap.data.stream.StreamRecordReader.java
/** * Construct a {@link StreamRecordReader} with a given {@link StreamEventDecoder}. * * @param decoder The decoder to use for decoding stream events. *///from w w w . j av a 2 s . c o m StreamRecordReader(StreamEventDecoder<K, V> decoder) { this.decoder = decoder; this.events = Lists.newArrayListWithCapacity(1); this.currentEntry = new StreamEventDecoder.DecodeResult<>(); }
From source file:com.spotify.folsom.client.Request.java
protected static List<byte[]> encodeKeys(List<String> keys, Charset charset) { List<byte[]> res = Lists.newArrayListWithCapacity(keys.size()); for (String key : keys) { res.add(encodeKey(key, charset)); }// ww w.j a va 2 s . c om return res; }
From source file:org.eclipse.milo.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 . ja v a2 s .c o m*/ 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); } FutureUtils.sequence(results).thenAccept(rs -> context.complete(rs)); }
From source file:com.github.steveash.jg2p.train.AbstractEncoderTrainer.java
public static List<Alignment> makeCrfExamples(List<InputRecord> inputs, AlignModel model, TrainOptions opts) { List<Alignment> examples = Lists.newArrayListWithCapacity(inputs.size()); for (InputRecord input : inputs) { List<Alignment> best = model.align(input.xWord, input.yWord, opts.topKAlignCandidates); for (Alignment pairs : best) { if (pairs.getScore() > opts.minAlignScore) { examples.add(pairs);/*from w w w .ja v a 2 s .c om*/ } } // if (!best.isEmpty()) { // of any that are above the threshold find the one with the highest score (where score is calculated by gram size) // // examples.add(best.get(0)); // } } return examples; }
From source file:edu.bsu.cybersec.core.narrative.InputSanitizationEvent.java
@Override public List<? extends Option> options() { List<Option> options = Lists.newArrayListWithCapacity(4); for (Entity e : availableWorkers()) { options.add(new EmployeeAssignmentOption(e.id)); }/*from ww w. j a v a2 s.com*/ options.add(new IgnoreOption()); return options; }
From source file:org.terasology.persistence.typeSerialization.typeHandlers.extension.BlockTypeHandler.java
@Override public List<Block> deserializeCollection(EntityData.Value value) { List<Block> result = Lists.newArrayListWithCapacity(value.getStringCount()); for (String item : value.getStringList()) { result.add(blockManager.getBlock(item)); }/*from ww w.jav a 2 s . c o m*/ return result; }
From source file:org.apache.shindig.gadgets.render.SanitizingProxyUriManager.java
public List<Uri> make(List<ProxyUri> ctx, Integer forcedRefresh) { // Just wraps the original ProxyUriManager and adds a few query params. List<Uri> origUris = wrapped.make(ctx, forcedRefresh); List<Uri> sanitizedUris = Lists.newArrayListWithCapacity(origUris.size()); for (Uri origUri : origUris) { UriBuilder newUri = new UriBuilder(origUri); newUri.addQueryParameter(Param.SANITIZE.getKey(), "1"); if (expectedMime != null) { newUri.addQueryParameter(Param.REWRITE_MIME_TYPE.getKey(), expectedMime); }//from w w w . j a v a 2 s.c o m sanitizedUris.add(newUri.toUri()); } return sanitizedUris; }
From source file:thread.DataAccessor.java
private List<ProcessedResponse> getDataFromService(List<String> requests) { CountDownLatch latch = new CountDownLatch(requests.size()); List<SubmittedJob> sjobs = Lists.newArrayListWithCapacity(requests.size()); for (String request : requests) { Future<ProcessedResponse> future = executor.submit(new GetNProcessResponse(request, latch)); sjobs.add(new SubmittedJob(future, request)); }/*w w w .ja v a2 s . com*/ boolean isAllDone = false; try { isAllDone = latch.await(timeOut, TimeUnit.MILLISECONDS); if (!isAllDone) { System.out.println("Some jobs not done..."); } } catch (InterruptedException e) { //take care of clean up for (SubmittedJob sjob : sjobs) { sjob.getFuture().cancel(true); } } List<ProcessedResponse> results = Lists.newLinkedList(); for (SubmittedJob sjob : sjobs) { try { if (!isAllDone && !sjob.getFuture().isDone()) { //cancel job and continue with others sjob.getFuture().cancel(true); continue; } ProcessedResponse res = sjob.getFuture().get(); results.add(res); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } } return results; //To change body of created methods use File | Settings | File Templates. }