List of usage examples for java.util List parallelStream
default Stream<E> parallelStream()
From source file:org.egov.infra.web.support.ui.menu.ApplicationMenuRenderingService.java
private List<MenuLink> extractSelfServiceMenus(List<MenuLink> menuLinks, User user) { return menuLinks.parallelStream().filter(menuLink -> SELF_SERVICE_MODULE_NAME.equals(menuLink.getName())) .findFirst()/* w ww. j av a 2 s.c o m*/ .map(menuLink -> moduleService.getMenuLinksByParentModuleId(menuLink.getId(), user.getId())) .orElse(Collections.emptyList()); }
From source file:org.lightjason.agentspeak.action.buildin.math.statistic.CAddStatisticValue.java
@Override public final IFuzzyValue<Boolean> execute(final IContext p_context, final boolean p_parallel, final List<ITerm> p_argument, final List<ITerm> p_return, final List<ITerm> p_annotation) { final List<ITerm> l_arguments = CCommon.flatcollection(p_argument).collect(Collectors.toList()); final double[] l_values = l_arguments.parallelStream() .filter(i -> CCommon.rawvalueAssignableTo(i, Number.class)).map(ITerm::<Number>raw) .mapToDouble(Number::doubleValue).toArray(); return CFuzzyValue.from(l_arguments.parallelStream() .filter(i -> CCommon.rawvalueAssignableTo(i, StatisticalSummary.class)).allMatch(i -> { if (CCommon.rawvalueAssignableTo(i, SummaryStatistics.class)) { Arrays.stream(l_values).forEach(j -> i.<SummaryStatistics>raw().addValue(j)); return true; }// w w w. j a v a2 s .c o m if (CCommon.rawvalueAssignableTo(i, DescriptiveStatistics.class)) { Arrays.stream(l_values).forEach(j -> i.<DescriptiveStatistics>raw().addValue(j)); return true; } return false; })); }
From source file:org.lightjason.agentspeak.action.builtin.math.statistic.CAddStatisticValue.java
@Nonnull @Override//from www . j a va 2 s.c o m public final IFuzzyValue<Boolean> execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List<ITerm> p_argument, @Nonnull final List<ITerm> p_return) { final List<ITerm> l_arguments = CCommon.flatten(p_argument).collect(Collectors.toList()); final double[] l_values = l_arguments.parallelStream() .filter(i -> CCommon.rawvalueAssignableTo(i, Number.class)).map(ITerm::<Number>raw) .mapToDouble(Number::doubleValue).toArray(); return CFuzzyValue.from(l_arguments.parallelStream() .filter(i -> CCommon.rawvalueAssignableTo(i, StatisticalSummary.class)).allMatch(i -> { if (CCommon.rawvalueAssignableTo(i, SummaryStatistics.class)) { Arrays.stream(l_values).forEach(j -> i.<SummaryStatistics>raw().addValue(j)); return true; } if (CCommon.rawvalueAssignableTo(i, DescriptiveStatistics.class)) { Arrays.stream(l_values).forEach(j -> i.<DescriptiveStatistics>raw().addValue(j)); return true; } return false; })); }
From source file:com.firewallid.crawling.FacebookIDSearch.java
public long countPostID(List<String> posts) { return posts.parallelStream().filter(post -> { try {/*from w w w . ja va 2 s . co m*/ return idLanguageDetector.detect(post); } catch (LangDetectException ex) { LOG.error(ex.toString()); return false; } }).count(); }
From source file:edu.umd.umiacs.clip.tools.scor.PSQW2VBM25Scorer.java
private float scoreWeighted(List<Map<String, Float>> wightedQuery, Map<String, Integer> docTerms) { int length = docTerms.values().parallelStream().mapToInt(f -> f).sum(); return (float) wightedQuery.parallelStream().mapToDouble(weightedTerm -> { List<Triple<Float, Float, Float>> list = weightedTerm.entrySet().stream() .filter(entry -> docTerms.containsKey(entry.getKey())) .map(entry -> ImmutableTriple.of(docTerms.get(entry.getKey()).floatValue(), (float) df(entry.getKey()), entry.getValue())) .collect(toList());//from www .jav a 2 s .com float averageTF = (float) list.parallelStream() .mapToDouble(triple -> triple.getLeft() * triple.getRight()).sum(); float averageDF = (float) list.parallelStream() .mapToDouble(triple -> triple.getMiddle() * triple.getRight()).sum(); return bm25(averageTF, averageDF, length); }).sum(); }
From source file:org.xwiki.contrib.repository.pypi.internal.searching.PypiPackageListIndexUpdateTask.java
private void addAllValidPackagesToIndex(IndexWriter indexWriter, List<String> packageNames) { packageNames.parallelStream().forEach(packageName -> { try {//from www . j a va 2 s .com PypiPackageJSONDto packageDataFromApi = this.pypiExtensionRepository.getPypiPackageData(packageName, Optional.empty()); if (PypiUtils.isPackageValidForXwiki(packageDataFromApi)) { Document newDocument = createNewDocument(packageDataFromApi); indexWriter.addDocument(newDocument); } } catch (ExtensionNotFoundException | HttpException e) { logger.debug("Could not resolve " + packageName + " package", e); } catch (IOException e) { logger.debug("IO problems whilst serializing " + packageName + " package extension", e); } }); }
From source file:HSqlManager.java
private static void commonInitialize(int bps, Connection connection) throws SQLException, IOException { String base = new File("").getAbsolutePath(); CSV.makeDirectory(new File(base + "/PhageData")); INSTANCE = ImportPhagelist.getInstance(); INSTANCE.parseAllPhages(bps);/*from www .j a v a2 s . c o m*/ written = true; Connection db = connection; db.setAutoCommit(false); Statement stat = db.createStatement(); stat.execute("SET FILES LOG FALSE\n"); PreparedStatement st = db.prepareStatement("Insert INTO Primerdb.Primers" + "(Bp,Sequence, CommonP, UniqueP, Picked, Strain, Cluster)" + " Values(?,?,true,false,false,?,?)"); ResultSet call = stat.executeQuery("Select * From Primerdb.Phages;"); List<String[]> phages = new ArrayList<>(); while (call.next()) { String[] r = new String[3]; r[0] = call.getString("Strain"); r[1] = call.getString("Cluster"); r[2] = call.getString("Name"); phages.add(r); } phages.parallelStream().map(x -> x[0]).collect(Collectors.toSet()).parallelStream().forEach(x -> { phages.stream().filter(y -> y[0].equals(x)).map(y -> y[1]).collect(Collectors.toSet()).forEach(z -> { try { List<String> clustphages = phages.stream().filter(a -> a[0].equals(x) && a[1].equals(z)) .map(a -> a[2]).collect(Collectors.toList()); Set<String> primers = Collections.synchronizedSet(CSV .readCSV(base + "/PhageData/" + Integer.toString(bps) + clustphages.get(0) + ".csv")); clustphages.remove(0); clustphages.parallelStream().forEach(phage -> { primers.retainAll( CSV.readCSV(base + "/PhageData/" + Integer.toString(bps) + phage + ".csv")); }); int i = 0; for (CharSequence a : primers) { try { //finish update st.setInt(1, bps); st.setString(2, a.toString()); st.setString(3, x); st.setString(4, z); st.addBatch(); } catch (SQLException e) { e.printStackTrace(); System.out.println("Error occurred at " + x + " " + z); } i++; if (i == 1000) { i = 0; st.executeBatch(); db.commit(); } } if (i > 0) { st.executeBatch(); db.commit(); } } catch (SQLException e) { e.printStackTrace(); System.out.println("Error occurred at " + x + " " + z); } }); }); stat.execute("SET FILES LOG TRUE\n"); st.close(); stat.close(); System.out.println("Common Updated"); }
From source file:com.github.camellabs.iot.cloudlet.geofencing.service.DefaultRouteService.java
private List<List<String>> exportRoutes(String client) { List<Route> routes = routes(client); List<String> routesIds = routes.parallelStream().map(Route::getId).collect(toList()); Query commentsQuery = new Query().addCriteria(where("routeId").in(routesIds)); List<RouteComment> routeComments = mongoTemplate.find(commentsQuery, RouteComment.class, "RouteComment"); Map<String, List<String>> commentsForRoute = newHashMap(); for (RouteComment comment : routeComments) { String routeId = comment.getRouteId(); if (!commentsForRoute.containsKey(routeId)) { commentsForRoute.put(routeId, newLinkedList()); }/*from w ww . j ava 2 s . co m*/ commentsForRoute.get(routeId).add(comment.getCreated().toString()); commentsForRoute.get(routeId).add(comment.getText()); } return routes.parallelStream() .map(route -> ImmutableList.<String>builder().add(route.getCreated().toString()) .addAll(commentsForRoute.getOrDefault(route.getId(), emptyList())).build()) .collect(toList()); }
From source file:uk.co.jassoft.markets.api.SystemController.java
@PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/queues", method = RequestMethod.GET) public @ResponseBody List<String> getQueues(final HttpServletResponse response) throws IOException { response.setHeader("Cache-Control", "no-cache"); // http://activemq.apache.org/jmx.html // http://localhost:32783/api/jolokia/read/org.apache.activemq:type=Broker,brokerName=localhost String plainCreds = "admin:admin"; byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic " + base64Creds); String url = String.format( "http://%s:%s/api/jolokia/read/org.apache.activemq:type=Broker,brokerName=localhost", activeMQHost, activeMQPort);/*from www.j a va 2 s . c o m*/ LOG.info("Requesting Queues from url [{}]", url); HttpEntity<String> request = new HttpEntity<String>(headers); ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, String.class); JsonNode root = mapper.readTree(responseEntity.getBody()); JsonNode queues = root.get("value").get("Queues"); List<String> objectnames = queues.findValuesAsText("objectName"); return objectnames.parallelStream() .map(objectname -> objectname .replace("org.apache.activemq:brokerName=localhost,destinationName=", "") .replace(",destinationType=Queue,type=Broker", "")) .collect(Collectors.toList()); }
From source file:delfos.rs.trustbased.WeightedGraph.java
private static void validateWeightsGraph(AdjMatrixEdgeWeightedDigraph adjMatrixEdgeWeightedDigraph) { List<DirectedEdge> allEdges = IntStream.range(0, adjMatrixEdgeWeightedDigraph.V()).boxed().parallel() .map(vertex -> {//from w w w. ja v a 2s .c o m Iterable<DirectedEdge> iterator = adjMatrixEdgeWeightedDigraph.adj(vertex); ArrayList<DirectedEdge> listOfEdges = new ArrayList<>(); for (DirectedEdge edge : iterator) { listOfEdges.add(edge); } return listOfEdges; }).flatMap(listOfEdges -> listOfEdges.parallelStream()).collect(Collectors.toList()); List<DirectedEdge> badEdges = allEdges.parallelStream() .filter(edge -> (edge.weight() < 0) || (edge.weight() > 1)).collect(Collectors.toList()); if (!badEdges.isEmpty()) { System.out.println("List of bad edges:"); badEdges.forEach(edge -> System.out.println("\t" + edge)); throw new IllegalStateException("arg"); } }