List of usage examples for java.util List parallelStream
default Stream<E> parallelStream()
From source file:pl.edu.icm.comac.vis.server.service.AtomicGraphServiceImpl.java
@Override public Graph constructGraphs(String[] ids) throws OpenRDFException { List<NodeCacheEntry> favCacheNodes = fetchNodes(ids); //build link map Map<String, Set<String>> links = favCacheNodes.parallelStream().filter(x -> !x.isOverflow()) .map(x -> x.getRelations()).flatMap(x -> x.stream()) .flatMap(x -> Arrays.stream( new String[][] { { x.getSubject(), x.getObject() }, { x.getObject(), x.getSubject() } })) .collect(Collectors.groupingBy(x -> x[0], Collectors.mapping(x -> x[1], Collectors.toSet()))); Set<String> large = favCacheNodes.stream().filter(x -> x.isOverflow()).map(x -> x.getId()) .collect(Collectors.toSet()); Set<String> normal = favCacheNodes.stream().filter(x -> !x.isOverflow()).map(x -> x.getId()) .collect(Collectors.toSet()); Set<String> unfav = graphToolkit.calculateAdditions(normal, large, links, MAX_RETURNED_RELATIONS); //now fetch the unfavs: List<NodeCacheEntry> unfavCacheNodes = fetchNodes(unfav.toArray(new String[unfav.size()])); List<NodeCacheEntry> allNodes = new ArrayList<NodeCacheEntry>(); allNodes.addAll(favCacheNodes);//from w w w . j av a 2s. c o m allNodes.addAll(unfavCacheNodes); List<NodeCacheEntry> largeNodes = allNodes.stream().filter(x -> x.isOverflow()) .collect(Collectors.toList()); List<RelationCacheEntry> largeRelations = calculateRelations(largeNodes); //now build the graph: List<Node> nodes = new ArrayList<>(); List<Node> fnodes = favCacheNodes.stream().map(cached -> { Node res = new Node(cached.getId(), cached.getType(), cached.getName(), 1.0); res.setFavourite(true); return res; }).collect(Collectors.toList()); nodes.addAll(fnodes); List<Node> ufnodes = unfavCacheNodes.stream().map(cached -> { Node res = new Node(cached.getId(), cached.getType(), cached.getName(), 1.0); res.setFavourite(false); return res; }).collect(Collectors.toList()); nodes.addAll(ufnodes); Set<String> nodeIdSet = nodes.stream().map(x -> x.getId()).collect(Collectors.toSet()); Set<Link> graphRelations = allNodes.parallelStream().filter(x -> !x.isOverflow()) .flatMap(x -> x.getRelations().stream()) .filter(x -> nodeIdSet.contains(x.subject) && nodeIdSet.contains(x.object)) .map(x -> new Link(x.getPredicate(), x.getSubject(), x.getObject())).collect(Collectors.toSet()); Graph res = new Graph(); res.setNodes(nodes); res.setLinks(new ArrayList<Link>(graphRelations)); return res; }
From source file:org.jhk.pulsing.web.dao.prod.db.redis.RedisPulseDao.java
public List<Pulse> getMapPulseDataPoints(double lat, double lng) { final double _DEFAULT_PULSE_RADIUS = 5; //just for now, push to client config later List<Pulse> pDataPoints = new LinkedList<>(); List<GeoRadiusResponse> response = getJedis().georadius(PULSE_GEO_.toString(), lng, lat, _DEFAULT_PULSE_RADIUS, GeoUnit.M); response.parallelStream().forEach(grResponse -> { try {/*from ww w . j a v a 2s .c om*/ pDataPoints.add(SerializationHelper.deserializeFromJSONStringToAvro(Pulse.class, Pulse.getClassSchema(), grResponse.getMemberByString())); } catch (IOException ioException) { _LOGGER.warn("Failure in parsing of georadiusresponse: " + grResponse); ioException.printStackTrace(); } }); return pDataPoints; }
From source file:org.egov.tl.web.controller.transactions.digisign.LicenseCertificateDigiSignController.java
@PostMapping("/bulk-digisign") public String bulkDigitalSignature(@RequestParam List<Long> licenseIds, Model model) { List<TradeLicense> licenses = licenseCertificateDigiSignService .generateLicenseCertificateForDigiSign(licenseIds); List<String> fileStoreIds = licenses.parallelStream().map(TradeLicense::getDigiSignedCertFileStoreId) .collect(Collectors.toList()); List<String> applicaitonNumbers = licenses.parallelStream().map(TradeLicense::getApplicationNumber) .collect(Collectors.toList()); model.addAttribute("fileStoreIds", String.join(",", fileStoreIds)); model.addAttribute("applicationNo", String.join(",", applicaitonNumbers)); model.addAttribute("ulbCode", ApplicationThreadLocals.getCityCode()); return "license-bulk-digisign-forward"; }
From source file:uk.co.jassoft.markets.crawler.CrawlerListener.java
private boolean isbaseURL(List<SourceUrl> sourceUrls, String url) { return sourceUrls.parallelStream().anyMatch(sourceUrl -> sourceUrl.getUrl().equals(url)); }
From source file:delfos.main.managers.experiment.join.xml.AggregateResultsXML.java
public List<File> filterResultsFiles(List<File> files) { List<File> returnFiles = files.parallelStream().filter(RESULTS_FILES).collect(Collectors.toList()); return returnFiles; }
From source file:com.github.horrorho.inflatabledonkey.DownloadAssistant.java
public void execute(HttpClient httpClient, FileAssembler fileAssembler, List<Set<Asset>> batchedAssets) { logger.debug("-- execute() - threads: {} batch count: {}", forkJoinPool.getParallelism(), batchedAssets.size());//from w w w . j a v a2 s.c o m try { forkJoinPool.submit(() -> batchedAssets.parallelStream() .forEach(u -> donkey.apply(httpClient, forkJoinPoolAux, u, fileAssembler))).get(); } catch (InterruptedException ex) { logger.warn("-- execute() - InterruptedException: {}", ex.getMessage()); Thread.currentThread().interrupt(); } catch (ExecutionException ex) { throw new RuntimeException(ex); } }
From source file:cognition.pipeline.service.DNCPipelineService.java
public void processCoordinates(List<DNCWorkCoordinate> coordinateQueue) { coordinateQueue.parallelStream().forEach(this::processSingleCoordinate); }
From source file:it.polimi.diceH2020.SPACE4CloudWS.core.CoarseGrainedOptimizer.java
void hillClimbing(Solution solution) { logger.info(// w w w. j av a 2s . c o m String.format("---------- Starting hill climbing for instance %s ----------", solution.getId())); Technology technology = solverChecker.enforceSolverSettings(solution.getLstSolutions()); List<SolutionPerJob> lst = solution.getLstSolutions(); Stream<SolutionPerJob> strm = settings.isParallel() ? lst.parallelStream() : lst.stream(); AtomicLong executionTime = new AtomicLong(); boolean overallSuccess = strm.map(s -> { Instant first = Instant.now(); boolean success = hillClimbing(s, technology); Instant after = Instant.now(); executionTime.addAndGet(Duration.between(first, after).toMillis()); return success; }).reduce(true, Boolean::logicalAnd); if (!overallSuccess) stateHandler.sendEvent(Events.STOP); else { solution.setEvaluated(false); evaluator.evaluate(solution); Phase phase = new Phase(); phase.setId(PhaseID.OPTIMIZATION); phase.setDuration(executionTime.get()); solution.addPhase(phase); } }
From source file:org.jenetics.stat.IntMomentStatisticsTest.java
@Test(dataProvider = "parallelSampleCounts") public void parallelSummary(final Integer sampleCounts, final Double epsilon) { final List<Integer> numbers = numbers(sampleCounts); final DescriptiveStatistics expected = new DescriptiveStatistics(); numbers.forEach(expected::addValue); final IntMomentStatistics summary = numbers.parallelStream() .collect(toIntMomentStatistics(Integer::intValue)); Assert.assertEquals(summary.getCount(), numbers.size()); assertEqualsDouble(min(summary.getMin()), expected.getMin(), 0.0); assertEqualsDouble(max(summary.getMax()), expected.getMax(), 0.0); assertEqualsDouble(summary.getSum(), expected.getSum(), epsilon); assertEqualsDouble(summary.getMean(), expected.getMean(), epsilon); assertEqualsDouble(summary.getVariance(), expected.getVariance(), epsilon); assertEqualsDouble(summary.getSkewness(), expected.getSkewness(), epsilon); assertEqualsDouble(summary.getKurtosis(), expected.getKurtosis(), epsilon); }
From source file:org.jenetics.stat.DoubleMomentStatisticsTest.java
@Test(dataProvider = "parallelSampleCounts") public void parallelSummary(final Integer sampleCounts, final Double epsilon) { final List<Double> numbers = numbers(sampleCounts); final DescriptiveStatistics expected = new DescriptiveStatistics(); numbers.forEach(expected::addValue); final DoubleMomentStatistics summary = numbers.parallelStream() .collect(toDoubleMomentStatistics(Double::doubleValue)); Assert.assertEquals(summary.getCount(), numbers.size()); assertEqualsDouble(min(summary.getMin()), expected.getMin(), 0.0); assertEqualsDouble(max(summary.getMax()), expected.getMax(), 0.0); assertEqualsDouble(summary.getSum(), expected.getSum(), epsilon); assertEqualsDouble(summary.getMean(), expected.getMean(), epsilon); assertEqualsDouble(summary.getVariance(), expected.getVariance(), epsilon); assertEqualsDouble(summary.getSkewness(), expected.getSkewness(), epsilon); assertEqualsDouble(summary.getKurtosis(), expected.getKurtosis(), epsilon); }