List of usage examples for java.util.stream Stream collect
<R, A> R collect(Collector<? super T, A, R> collector);
From source file:controllers.nwbib.Application.java
/** * @param format The format to show the current stars in * @param ids Comma-separated IDs to show, of empty string * @return A page with all resources starred by the user *//*from ww w. j a v a 2 s . co m*/ public static Promise<Result> showStars(String format, String ids) { uncacheLastSearchUrl(); final List<String> starred = starredIds(); if (ids.isEmpty() && !starred.isEmpty()) { return Promise.pure(redirect( routes.Application.showStars(format, starred.stream().collect(Collectors.joining(","))))); } final List<String> starredIds = starred.isEmpty() && ids.trim().isEmpty() ? starred : Arrays.asList(ids.split(",")); String cacheKey = "starsForIds." + starredIds; Object cachedJson = Cache.get(cacheKey); if (cachedJson != null && cachedJson instanceof List) { @SuppressWarnings("unchecked") List<JsonNode> json = (List<JsonNode>) cachedJson; return Promise.pure(ok(stars.render(starredIds, json, format))); } Stream<Promise<JsonNode>> promises = starredIds.stream() .map(id -> WS.url(String.format("http://lobid.org/resource/%s?format=full", id)).get() .map(response -> response.asJson())); return Promise.sequence(promises.collect(Collectors.toList())).map((List<JsonNode> vals) -> { uncache(starredIds); session("lastSearchUrl", routes.Application.showStars(format, ids).toString()); Cache.set(session("uuid") + "-lastSearch", starredIds.stream().map(s -> "\"" + s + "\"").collect(Collectors.toList()).toString(), Application.ONE_DAY); Cache.set(cacheKey, vals, ONE_DAY); return ok(stars.render(starredIds, vals, format)); }); }
From source file:ru.anr.base.BaseParent.java
/** * A simpler form for stream collecting/*from w w w .j av a 2 s . com*/ * * @param stream * A stream * @return A list * @param <S> * Type of object */ public static <S> List<S> list(Stream<S> stream) { return stream.collect(Collectors.toList()); }
From source file:ru.anr.base.BaseParent.java
/** * A simpler form for stream collecting/*from w w w . j a va2 s . c o m*/ * * @param stream * A stream * @return A set * @param <S> * Type of object */ public static <S> Set<S> set(Stream<S> stream) { return stream.collect(Collectors.toSet()); }
From source file:io.wcm.devops.conga.plugins.aem.tooling.crypto.cli.CryptoKeysTest.java
private void assetFiles(Stream<File> filesStream) { List<File> files = filesStream.collect(Collectors.toList()); assertEquals(2, files.size());/*from w ww.j a v a2s .co m*/ assertTrue(files.get(0).exists()); assertEquals("master", files.get(0).getName()); assertTrue(files.get(1).exists()); assertEquals("hmac", files.get(1).getName()); }
From source file:org.elasticsearch.xpack.security.authc.saml.SamlRealm.java
public static List<SamlRealm> findSamlRealms(Realms realms, String realmName, String acsUrl) { Stream<SamlRealm> stream = realms.stream().filter(r -> r instanceof SamlRealm).map(r -> (SamlRealm) r); if (Strings.hasText(realmName)) { stream = stream.filter(r -> realmName.equals(r.name())); }/*from ww w .ja va 2s .c o m*/ if (Strings.hasText(acsUrl)) { stream = stream.filter(r -> acsUrl.equals(r.assertionConsumerServiceURL())); } return stream.collect(Collectors.toList()); }
From source file:org.moserp.environment.rest.ValueListController.java
@RequestMapping(method = RequestMethod.GET, value = "/valueLists/{key}/values") public Resources<Resource<ValueListItem>> getValuesForKey(@PathVariable String key) { ValueList valueList = valueListRepository.findByKey(key); if (valueList == null) { valueList = new ValueList(key); valueList = valueListRepository.save(valueList); }//from ww w. j a v a 2 s . c o m List<ValueListItem> values = valueList.getValues(); Stream<Resource<ValueListItem>> resourceStream = values.stream().map(item -> new Resource<>(item)); List<Resource<ValueListItem>> resources = resourceStream.collect(Collectors.toList()); return new Resources<>(resources); }
From source file:com.devicehive.dao.rdbms.NetworkDaoRdbmsImpl.java
@Override public List<NetworkVO> findByName(String name) { List<Network> result = createNamedQuery(Network.class, "Network.findByName", Optional.of(CacheConfig.get())) .setParameter("name", name).getResultList(); Stream<NetworkVO> objectStream = result.stream().map(Network::convertNetwork); return objectStream.collect(Collectors.toList()); }
From source file:com.carlomicieli.jtrains.infrastructure.mongo.JongoRepositoryTests.java
@Test public void shouldFindDocuments() { Stream<MyObj> resultStream = repo(jongo()).find(myObjs -> myObjs.find("{'value': 2}")); List<MyObj> results = resultStream.collect(Collectors.toList()); assertThat(results).hasSize(1);/* w w w . j a v a 2 s. c om*/ }
From source file:com.devicehive.dao.rdbms.NetworkDaoRdbmsImpl.java
@Override public List<NetworkVO> list(String name, String namePattern, String sortField, boolean sortOrderAsc, Integer take, Integer skip, Optional<HivePrincipal> principal) { CriteriaBuilder cb = criteriaBuilder(); CriteriaQuery<Network> criteria = cb.createQuery(Network.class); Root<Network> from = criteria.from(Network.class); Predicate[] nameAndPrincipalPredicates = CriteriaHelper.networkListPredicates(cb, from, ofNullable(name), ofNullable(namePattern), principal); criteria.where(nameAndPrincipalPredicates); CriteriaHelper.order(cb, criteria, from, ofNullable(sortField), sortOrderAsc); TypedQuery<Network> query = createQuery(criteria); cacheQuery(query, of(CacheConfig.refresh())); ofNullable(take).ifPresent(query::setMaxResults); ofNullable(skip).ifPresent(query::setFirstResult); List<Network> result = query.getResultList(); Stream<NetworkVO> objectStream = result.stream().map(Network::convertNetwork); return objectStream.collect(Collectors.toList()); }
From source file:org.g_node.mergers.LktMergerJenaTest.java
@Test public void testPlainMergeAndSave() throws Exception { final String useCase = "lkt"; final Path outputFile = this.testFileFolder.resolve("out.ttl"); final String[] cliArgs = new String[7]; cliArgs[0] = useCase;//from w ww . j a va2 s .co m cliArgs[1] = "-m"; cliArgs[2] = this.testMainRdfFile.getAbsolutePath(); cliArgs[3] = "-i"; cliArgs[4] = this.testMergeRdfFile.getAbsolutePath(); cliArgs[5] = "-o"; cliArgs[6] = outputFile.toString(); App.main(cliArgs); assertThat(Files.exists(outputFile)).isTrue(); final Stream<String> fileStream = Files.lines(outputFile); final List<String> readFile = fileStream.collect(Collectors.toList()); assertThat(readFile.size()).isEqualTo(5); fileStream.close(); }