List of usage examples for java.util.stream Collectors toCollection
public static <T, C extends Collection<T>> Collector<T, ?, C> toCollection(Supplier<C> collectionFactory)
From source file:starnubserver.resources.connections.Players.java
public HashSet<ChannelHandlerContext> getOnlinePlayersCtxs() { return this.keySet().stream().collect(Collectors.toCollection(HashSet::new)); }
From source file:org.opencb.opencga.app.cli.main.executors.catalog.SampleCommandExecutor.java
private QueryResponse<Individual> getIndividuals() throws CatalogException, IOException { logger.debug("Getting individuals of sample(s)"); ObjectMap params = new ObjectMap(); params.putIfNotEmpty(SampleDBAdaptor.QueryParams.STUDY.key(), resolveStudy(samplesCommandOptions.individualCommandOptions.study)); params.put("lazy", false); // Obtain the whole individual entity params.putIfNotNull(QueryOptions.INCLUDE, samplesCommandOptions.individualCommandOptions.dataModelOptions.include); params.putIfNotNull(QueryOptions.EXCLUDE, samplesCommandOptions.individualCommandOptions.dataModelOptions.exclude); QueryResponse<Sample> sampleQueryResponse = openCGAClient.getSampleClient() .get(samplesCommandOptions.individualCommandOptions.sample, params); if (sampleQueryResponse.allResultsSize() == 0) { return new QueryResponse<>(sampleQueryResponse.getApiVersion(), -1, sampleQueryResponse.getWarning(), sampleQueryResponse.getError(), sampleQueryResponse.getQueryOptions(), new LinkedList<>()); }//from w w w.j a va 2s. c om // We get the individuals from the sample response List<Individual> individualList = sampleQueryResponse.allResults().stream().map(Sample::getIndividual) .collect(Collectors.toCollection(LinkedList::new)); return new QueryResponse<>(sampleQueryResponse.getApiVersion(), -1, sampleQueryResponse.getWarning(), sampleQueryResponse.getError(), sampleQueryResponse.getQueryOptions(), Arrays.asList(new QueryResult<>(samplesCommandOptions.individualCommandOptions.sample, -1, individualList.size(), individualList.size(), "", "", individualList))); }
From source file:chatbot.Chatbot.java
/** ************************************************************************************************** * @return an ArrayList of the string split by spaces. *///from w ww. ja va 2s . co m private static ArrayList<String> splitToArrayList(String st) { if (isNullOrEmpty(st)) { System.out.println("Error in TFIDF.splitToArrayList(): empty string input"); return null; } String[] sentar = st.split(" "); return new ArrayList<String>(Arrays.asList(sentar)).stream() .filter(s -> s != null && !s.equals("") && !s.matches("\\s*")) .collect(Collectors.toCollection(ArrayList<String>::new)); }
From source file:starnubserver.resources.connections.Players.java
public HashSet<PlayerSession> getOnlinePlayersSessions() { return this.values().stream().collect(Collectors.toCollection(HashSet::new)); }
From source file:starnubserver.resources.connections.Players.java
public HashSet<PlayerCharacter> getOnlinePlayersCharacters() { return this.values().stream().map(PlayerSession::getPlayerCharacter) .collect(Collectors.toCollection(HashSet::new)); }
From source file:starnubserver.resources.connections.Players.java
public HashSet<UUID> getOnlinePlayersUuids() { return this.values().stream().map(playerSession -> playerSession.getPlayerCharacter().getUuid()) .collect(Collectors.toCollection(HashSet::new)); }
From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java
public static <V extends Node> void applyNodeHighlights(RenderContext<V, Edge<V>> renderContext, Collection<V> nodes, HighlightConditionList nodeHighlightConditions, int nodeSize, Integer nodeMaxSize, String metaNodeProperty) { HighlightResult<V> result = getResult(nodes, nodeHighlightConditions); Set<V> metaNodes = nodes.stream().filter(n -> Boolean.TRUE.equals(n.getProperties().get(metaNodeProperty))) .collect(Collectors.toCollection(LinkedHashSet::new)); renderContext.setVertexShapeTransformer( JungUtils.newNodeShapeTransformer(nodeSize, nodeMaxSize, result.thicknessValues, result.shapes)); renderContext.setVertexFillPaintTransformer(JungUtils.newNodeFillTransformer(renderContext, result.colors)); renderContext.setVertexLabelTransformer(node -> result.labels.get(node)); renderContext.setVertexStrokeTransformer(JungUtils.newNodeStrokeTransformer(renderContext, metaNodes)); }
From source file:org.lambdamatic.mongodb.apt.template.TemplateType.java
/** * Constructor for a parameterized type//from w ww . j a v a 2 s.c o m * * @param fullyQualifiedName the fully qualified name of the corresponding Java field type. * @param parameterTypes the Java parameter types. */ TemplateType(final String fullyQualifiedName, final List<TemplateType> parameterTypes) { this.fullyQualifiedName = fullyQualifiedName; this.javaTypeParameterNames = parameterTypes.stream().map(p -> p.fullyQualifiedName) .collect(Collectors.toCollection(LinkedList::new)); final StringBuilder simpleNameBuilder = new StringBuilder(); simpleNameBuilder.append(ClassUtils.getShortCanonicalName(fullyQualifiedName)); if (!parameterTypes.isEmpty()) { simpleNameBuilder.append('<') .append(parameterTypes.stream().map(p -> p.getSimpleName()).collect(Collectors.joining(", "))) .append('>'); } this.simpleName = simpleNameBuilder.toString(); this.requiredTypes = parameterTypes.stream().flatMap(p -> { return p.getRequiredJavaTypes().stream(); }).collect(Collectors.toSet()); final Class<?> javaType = ElementUtils.toClass(fullyQualifiedName); if (javaType != null && javaType.isArray()) { final Class<?> componentType = javaType.getComponentType(); if (!ClassUtils.isPrimitiveOrWrapper(componentType)) { this.requiredTypes.add(componentType.getName()); } } else if (!ClassUtils.isPrimitiveOrWrapper(javaType)) { this.requiredTypes.add(fullyQualifiedName); } }
From source file:com.joyent.manta.client.multipart.JobsMultipartManagerIT.java
public void canListMultipartUploadsInProgress() throws IOException { final String[] objects = new String[] { testPathPrefix + uploadName("can-list-multipart-uploads-in-progress-1"), testPathPrefix + uploadName("can-list-multipart-uploads-in-progress-2"), testPathPrefix + uploadName("can-list-multipart-uploads-in-progress-3") }; final List<MantaMultipartUpload> uploads = new ArrayList<>(objects.length); for (String object : objects) { uploads.add(multipart.initiateUpload(object)); }/* www.j av a 2s.c om*/ final List<MantaMultipartUpload> list; try (Stream<MantaMultipartUpload> inProgress = multipart.listInProgress()) { list = inProgress.collect(Collectors.toCollection(ArrayList::new)); } try { assertFalse(list.isEmpty(), "List shouldn't be empty"); for (MantaMultipartUpload upload : uploads) { assertTrue(list.contains(upload), "Upload wasn't present in results: " + upload); } } finally { for (MantaMultipartUpload upload : uploads) { if (upload instanceof JobsMultipartUpload) { multipart.abort((JobsMultipartUpload) upload); } } } }
From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java
private void searchIndexByScoreBlocking(String fieldName, String indexName, Double min, Double max, Integer offset, Integer limit, AsyncResultHandler<List<String>> resultHandler) { redissonOther//from w w w .ja v a2 s .c o m .<String>getScoredSortedSet(getScoredSortedIndexKey(fieldName, indexName), StringCodec.INSTANCE) .valueRangeAsync(min, true, max, true, offset, limit).addListener(future -> { Collection<String> res = (Collection<String>) future.get(); try { ArrayList<String> ids = res.stream().map(r -> lookupIdFromIndex(r, fieldName, indexName)) .collect(Collectors.toCollection(ArrayList::new)); resultHandler .handle(future.isSuccess() ? (future.get() != null || ids == null ? Future.succeededFuture(ids) : Future.failedFuture( new RepositoryException("No search result returned"))) : Future.failedFuture(new RepositoryException(future.cause()))); if (future.isSuccess()) { logger.debug("[" + getStorageKey() + "] Search Index By Score Success. Records: " + ((Collection<String>) future.get()).size()); } else { logger.debug("[" + getStorageKey() + "] Search Index By Score Failure.", future.cause()); } } catch (RuntimeException e) { resultHandler.handle(Future.failedFuture(e.getCause())); logger.debug("[" + getStorageKey() + "] Search Index By Score Failure.", e); } }); }