List of usage examples for java.util List parallelStream
default Stream<E> parallelStream()
From source file:com.epam.catgenome.manager.FeatureIndexManager.java
/** * Filer chromosomes that contain variations, specified by filter * * @param filterForm a {@code VcfFilterForm} to filter out chromosomes * @param projectId a {@code Project}s ID to filter * @return a {@code List} of {@code Chromosome} that corresponds to specified filter * @throws IOException/* w w w .j a va 2 s. c o m*/ */ public List<Chromosome> filterChromosomes(VcfFilterForm filterForm, long projectId) throws IOException { Assert.isTrue(filterForm.getVcfFileIds() != null && !filterForm.getVcfFileIds().isEmpty(), MessageHelper.getMessage(MessagesConstants.ERROR_NULL_PARAM, VCF_FILE_IDS_FIELD)); Project project = projectManager.loadProject(projectId); List<VcfFile> vcfFiles = project.getItems().stream() .filter(i -> i.getBioDataItem().getFormat() == BiologicalDataItemFormat.VCF) .map(i -> (VcfFile) i.getBioDataItem()).collect(Collectors.toList()); List<Chromosome> chromosomes = referenceGenomeManager.loadChromosomes(vcfFiles.get(0).getReferenceId()); Map<Long, Chromosome> chromosomeMap = chromosomes.parallelStream() .collect(Collectors.toMap(BaseEntity::getId, chromosome -> chromosome)); List<Long> chromosomeIds = featureIndexDao.getChromosomeIdsWhereVariationsPresentFacet(vcfFiles, filterForm.computeQuery(FeatureType.VARIATION)); return chromosomeIds.stream().map(chromosomeMap::get).collect(Collectors.toList()); }
From source file:com.gs.collections.impl.parallel.SerialParallelLazyPerformanceTest.java
private double basicJava8ParallelLazyToListPerformance(List<Integer> iterable, int count) { return TimeKeeper.logAverageMillisecondsToRun( "Parallel Java8 toList: " + this.getSimpleName(iterable) + " size: " + this.formatSizeOf(iterable) + " cores: ?", () -> Verify.assertSize(iterable.size(), iterable.parallelStream().collect(Collectors.toList())), count, WARM_UP_COUNT);//from w ww . j a v a 2 s. c o m }
From source file:de.steilerdev.myVerein.server.controller.admin.SettingsController.java
/** * This function is saving the settings for the system durable. In case the database connection changed, the system is restarted. The function is invoked by POSTing the parameters to the URI /api/admin/settings. * NOTE: At the moment the restarting of the application is not working correctly. To apply changed database settings the application needs to be redeployed manually from the management interface. * @param currentAdmin If the logged in user is a super admin, this field specifies the new super admin. If the logged in user is a normal admin, this field needs to contain his email. * @param adminPasswordNew The new password for the currently logged in admin. * @param adminPasswordNewRe The retyped new password for the currently logged in admin. * @param clubName The club name.// w w w . ja v a 2s .com * @param clubLogo The club logo. If this parameter is present the former club logo is going to be replaced. * @param databaseHost The hostname of the used MongoDB server. * @param databasePort The port of the used MongoDB server. * @param databaseUser The username, used to authenticate against the MongoDB server. * @param databasePassword The password, used to authenticate against the MongoDB server. * @param databaseCollection The name of the database collection, where the data of this system is stored in. * @param rememberMeTokenKey The phrase used to secure the remember me cookies. * @param parameters The complete map of all parameters, containing the custom user fields. * @param currentAdminPassword The password of the currently logged in user, used to authenticate the changes. * @param currentUser The currently logged in user. * @return An HTTP response with a status code. If an error occurred an error message is bundled into the response, otherwise a success message is available. */ @RequestMapping(method = RequestMethod.POST) public ResponseEntity<String> saveSettings(@RequestParam(required = false) String currentAdmin, @RequestParam(required = false) String adminPasswordNew, @RequestParam(required = false) String adminPasswordNewRe, @RequestParam(required = false) String clubName, @RequestParam(required = false) MultipartFile clubLogo, @RequestParam(required = false) String databaseHost, @RequestParam(required = false) String databasePort, @RequestParam(required = false) String databaseUser, @RequestParam(required = false) String databasePassword, @RequestParam(required = false) String databaseCollection, @RequestParam Map<String, String> parameters, @RequestParam String currentAdminPassword, @CurrentUser User currentUser) { logger.trace("[" + currentUser + "] Starting to save settings"); Settings settings = Settings.loadSettings(settingsRepository); if (!passwordEncoder.isPasswordValid(currentUser.getPassword(), currentAdminPassword, currentUser.getSalt())) { logger.warn("[" + currentUser + "] The stated password is invalid"); return new ResponseEntity<>("The stated password is incorrect, please try again", HttpStatus.FORBIDDEN); } else if (currentUser.isAdmin()) { if (currentUser.isSuperAdmin()) { logger.debug("[" + currentUser + "] The user is a super admin"); if (currentAdmin != null && !currentAdmin.equals(currentUser.getEmail())) { logger.warn("[" + currentUser + "] The super admin user is changing to " + currentAdmin); Division rootDivision = divisionRepository.findByName(settings.getClubName()); if (rootDivision == null) { logger.warn("[" + currentUser + "] Unable to find root division " + settings.getClubName()); return new ResponseEntity<>("Unable to find root division", HttpStatus.INTERNAL_SERVER_ERROR); } User newSuperAdmin = userRepository.findByEmail(currentAdmin); if (newSuperAdmin == null) { logger.warn("[" + currentUser + "] Unable to find new super admin " + currentAdmin); return new ResponseEntity<>("Unable to find new super admin", HttpStatus.INTERNAL_SERVER_ERROR); } logger.debug("[" + currentUser + "] Saving new super admin"); rootDivision.setAdminUser(newSuperAdmin); divisionRepository.save(rootDivision); logger.info("[" + currentUser + "] Successfully saved " + currentAdmin + " as new super admin"); } try { if (clubName != null && !clubName.isEmpty()) { logger.debug("[" + currentUser + "] Setting club name to " + clubName); Division rootDivision = divisionRepository.findByName(settings.getClubName()); if (rootDivision == null) { logger.warn("[" + currentUser + "] Unable to find former root division."); return new ResponseEntity<>("Unable to find former root division", HttpStatus.INTERNAL_SERVER_ERROR); } //Changing and saving the root division rootDivision.setName(clubName); divisionRepository.save(rootDivision); settings.setClubName(clubName); } if (clubLogo != null && !clubLogo.isEmpty()) { logger.debug("[" + currentUser + "] Saving club logo"); try { gridFSRepository.storeClubLogo(clubLogo); } catch (MongoException e) { logger.warn("[" + currentUser + "] Problem while saving club logo: " + e.getMessage()); return new ResponseEntity<>("Problem while saving club logo: " + e.getMessage(), HttpStatus.BAD_REQUEST); } } if (databaseHost != null && !databaseHost.isEmpty()) { logger.debug("[" + currentUser + "] Setting database host to " + databaseHost); settings.setDatabaseHost(databaseHost); } if (databasePort != null && !databasePort.isEmpty()) { logger.debug("[" + currentUser + "] Setting database port to " + databasePort); settings.setDatabasePort(databasePort); } if (databaseUser != null) { logger.debug("[" + currentUser + "] Setting database user to " + databaseUser); settings.setDatabaseUser(databaseUser); } if (databasePassword != null) { logger.debug("[" + currentUser + "] Setting database password"); settings.setDatabasePassword(databasePassword); } if (databaseCollection != null && !databaseCollection.isEmpty()) { logger.debug( "[" + currentUser + "] Setting database collection name " + databaseCollection); settings.setDatabaseName(databaseCollection); } logger.debug("[" + currentUser + "] Gathering all custom user fields"); //Reducing parameters to custom user field parameters only and the value of the input List<String> reducedValues = parameters.keySet().parallelStream() .filter(key -> key.startsWith("cuf_") && !parameters.get(key).trim().isEmpty()) .distinct() //Only allowing distinct keys .map(key -> key.substring(4)) //Reducing the key to the initial 'name' value, used to create the fields by jQuery .collect(Collectors.toList()); //Analysing the values and checking, if if (!reducedValues.isEmpty()) { logger.debug("[" + currentUser + "] There are custom user fields available"); ArrayList<String> customUserFieldValues = new ArrayList<>(); reducedValues.parallelStream().forEach(key -> { if (parameters.get("delete" + key) != null) { logger.warn("[" + currentUser + "] Deleting custom user field " + key); if (parameters.get("deleteContent" + key) != null) { logger.warn("[" + currentUser + "] Deleting content of custom user field " + key + " on every user object"); List<User> user = mongoTemplate.find( new Query(Criteria.where("customUserField." + key).exists(true)), User.class); if (user != null && !user.isEmpty()) { user.parallelStream().forEach(thisUser -> { thisUser.removeCustomUserField(key); try { logger.trace( "[" + currentUser + "] Deleting custom user field content " + key + " for user " + thisUser.getEmail()); userRepository.save(thisUser); } catch (ConstraintViolationException e) { logger.warn("[" + currentUser + "] A database constraint was violated while trying to delete the custom user field " + key + " for user " + thisUser.getEmail() + ": " + e.getMessage()); } }); } } } else { String value = parameters.get("cuf_" + key).trim(); if (!key.equals(value) && settings.getCustomUserFields().contains(key)) //The key was renamed { logger.debug("[" + currentUser + "] The custom user field " + key + " changed to " + value); List<User> user = mongoTemplate.find( new Query(Criteria.where("customUserField." + key).exists(true)), User.class); if (user != null && !user.isEmpty()) { user.parallelStream().forEach(thisUser -> { thisUser.renameCustomUserField(key, value); try { logger.trace("[" + currentUser + "] Renaming custom user field " + key + " to " + value + " for user " + thisUser.getEmail()); userRepository.save(thisUser); } catch (ConstraintViolationException e) { logger.warn("[" + currentUser + "] A database constraint was violated while trying to rename the custom user field " + key + " for user " + thisUser.getEmail() + ": " + e.getMessage()); } }); } } logger.debug("[" + currentUser + "] Adding " + value + " as custom user field"); customUserFieldValues.add(value); } }); settings.setCustomUserFields(customUserFieldValues); } logger.debug("[" + currentUser + "] Saving updated settings file"); settings.saveSettings(currentUser, settingsRepository); logger.info("[" + currentUser + "] Successfully saved updated settings file"); } catch (IOException e) { logger.warn("[" + currentUser + "] Unable to update settings file: " + e.getMessage()); return new ResponseEntity<>("Unable to update settings file", HttpStatus.INTERNAL_SERVER_ERROR); } } else { logger.debug("[" + currentUser + "] The user is an admin"); if (currentAdmin != null && !currentAdmin.equals(currentUser.getEmail())) { logger.warn("[" + currentUser + "] The current user differs from the stated user"); return new ResponseEntity<>("The current user differs from the stated user", HttpStatus.BAD_REQUEST); } } if (adminPasswordNew != null && adminPasswordNewRe != null && !adminPasswordNew.isEmpty() && !adminPasswordNewRe.isEmpty()) { logger.info("[" + currentUser + "] The user wants to change his password."); if (!adminPasswordNew.equals(adminPasswordNewRe)) { logger.warn("[" + currentUser + "] The stated passwords did not match"); return new ResponseEntity<>("The stated passwords did not match", HttpStatus.BAD_REQUEST); } else { currentUser.setPassword(adminPasswordNew); try { logger.debug("[" + currentUser + "] Saving new user password."); userRepository.save(currentUser); logger.info("[" + currentUser + "] Successfully saved new user password"); } catch (ConstraintViolationException e) { logger.warn("[" + currentUser + "] A database constraint was violated while saving the user: " + e.getMessage()); return new ResponseEntity<>("A database constraint was violated while saving the user.", HttpStatus.BAD_REQUEST); } } } } else { logger.warn("[" + currentUser + "] A user who is not an admin tries to change the settings "); return new ResponseEntity<>("You are not allowed to change these settings", HttpStatus.FORBIDDEN); } logger.info("[" + currentUser + "] Successfully updated all settings"); return new ResponseEntity<>("Successfully updated settings", HttpStatus.OK); }
From source file:com.gs.collections.impl.parallel.SerialParallelLazyPerformanceTest.java
private double basicJava8ParallelLazyForEachPerformance(List<Integer> iterable, String parameterType, Consumer<Integer> consumer, int count) { return TimeKeeper.logAverageMillisecondsToRun( "Parallel Java8 ForEach using: " + parameterType + ' ' + this.getSimpleName(iterable) + " size: " + this.formatSizeOf(iterable) + " cores: ?", () -> iterable.parallelStream().forEach(consumer), count, WARM_UP_COUNT); }
From source file:com.gs.collections.impl.parallel.SerialParallelLazyPerformanceTest.java
private double basicJava8ParallelLazySelectPerformance(List<Integer> iterable, String parameterType, MutableList<java.util.function.Predicate<Integer>> predicatesList, int count) { return TimeKeeper.logAverageMillisecondsToRun("Parallel Java8 Select using: " + parameterType + ' ' + this.getSimpleName(iterable) + " size: " + this.formatSizeOf(iterable) + " cores: ?", () -> { iterable.parallelStream().filter(predicatesList.get(0)).collect(Collectors.toList()); iterable.parallelStream().filter(predicatesList.get(1)).collect(Collectors.toList()); iterable.parallelStream().filter(predicatesList.get(2)).collect(Collectors.toList()); }, count, WARM_UP_COUNT);/*from w w w . j av a2s . com*/ }
From source file:com.gs.collections.impl.parallel.SerialParallelLazyPerformanceTest.java
private double basicJava8ParallelLazyRejectPerformance(List<Integer> iterable, String parameterType, MutableList<java.util.function.Predicate<Integer>> predicateList, int count) { return TimeKeeper.logAverageMillisecondsToRun("Parallel Java8 Reject using: " + parameterType + ' ' + this.getSimpleName(iterable) + " size: " + this.formatSizeOf(iterable) + " cores: ?", () -> { Verify.assertNotEmpty(iterable.parallelStream().filter(predicateList.get(0).negate()) .collect(Collectors.toList())); Verify.assertNotEmpty(iterable.parallelStream().filter(predicateList.get(1).negate()) .collect(Collectors.toList())); Verify.assertNotEmpty(iterable.parallelStream().filter(predicateList.get(2).negate()) .collect(Collectors.toList())); }, count, WARM_UP_COUNT);/* w w w . j a v a2 s. com*/ }
From source file:com.gs.collections.impl.parallel.SerialParallelLazyPerformanceTest.java
private double basicJava8ParallelLazyCollectPerformance(List<Integer> iterable, String parameterType, MutableList<java.util.function.Function<Integer, ?>> functionsList, int count) { return TimeKeeper.logAverageMillisecondsToRun("Parallel Java8 Collect using: " + parameterType + ' ' + this.getSimpleName(iterable) + " size: " + this.formatSizeOf(iterable) + " cores: ?", () -> { Verify.assertNotEmpty(/* w w w. j a v a 2s .c om*/ iterable.parallelStream().map(functionsList.get(0)).collect(Collectors.toList())); Verify.assertNotEmpty( iterable.parallelStream().map(functionsList.get(1)).collect(Collectors.toList())); }, count, 10); }
From source file:com.gs.collections.impl.parallel.SerialParallelLazyPerformanceTest.java
private double basicJava8ParallelLazyAnySatisfyPerformance(List<Integer> iterable, String parameterType, java.util.function.Predicate<? super Integer> predicate, boolean expectedResult, int count) { return TimeKeeper.logAverageMillisecondsToRun( "Parallel Java8 AnySatisfy using: " + parameterType + ' ' + this.getSimpleName(iterable) + " size: " + this.formatSizeOf(iterable) + " cores: ?", () -> Assert.assertEquals(expectedResult, iterable.parallelStream().anyMatch(predicate)), count, WARM_UP_COUNT);// w w w. j a v a2s . c om }
From source file:com.tascape.reactor.report.SuiteResultExportTestRailView.java
private void share0() throws NamingException, SQLException { LOG.debug("srid {}", srid); LOG.debug("logBaseUrl {}", logBaseUrl); LOG.debug("url {}", url); LOG.debug("user {}", user); LOG.debug("pass {}", pass); LOG.debug("project {}", projectId); LOG.debug("suite {}", suiteId); LOG.debug("sections {}", sectionIds); LOG.debug("complete {}", complete); if (StringUtils.isBlank(srid)) { return;/*www. j a v a 2 s. co m*/ } TestRail testRail = TestRail.builder(url, user, pass).applicationName(Reactor.class.getSimpleName()) .build(); int pid = Integer.parseInt(projectId); int sid = Integer.parseInt(suiteId); List<Integer> sids = Stream.of(sectionIds.split(",")).map(id -> Integer.parseInt(id.trim())) .collect(Collectors.toList()); Project project = testRail.projects().get(pid).execute(); LOG.debug("testrail project {}", project.getName()); Suite suite = testRail.suites().get(sid).execute(); LOG.debug("testrail suite {}", suite.getName()); final List<String> names = Lists.newArrayList(suite.getName()); sids.forEach(sectionId -> { Section section = testRail.sections().get(sectionId).execute(); names.add(section.getName()); LOG.debug("testrail section {} - {}", sectionId, section.getName()); }); Map<String, Object> sr = this.db.getSuiteResult(srid); List<Map<String, Object>> trs = this.db.getCasesResult(srid); srid = ""; List<CaseField> cfs = testRail.caseFields().list().execute(); List<Integer> cids = testRail.cases().list(pid, sid, cfs).execute().stream() .filter(c -> sids.isEmpty() || sids.contains(c.getSectionId())).map(c -> { int id = c.getId(); LOG.debug("{} - {}", c.getSectionId(), id); return id; }).collect(Collectors.toList()); Run run = testRail.runs() .add(pid, new Run().setSuiteId(sid).setIncludeAll(false).setCaseIds(cids) .setName(StringUtils.join(names, " - ") + ": " + DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT .format(sr.get(SuiteResult.START_TIME)))) .execute(); this.runLink = run.getUrl(); try { List<ResultField> customResultFields = testRail.resultFields().list().execute(); trs.parallelStream().forEach(cr -> { String exid = cr.get(CaseResult.EXTERNAL_ID) + ""; LOG.debug("case result external id {}", exid); try { int crid = Integer.parseInt(exid); int status = ExecutionResult.isPass(((String) cr.get(CaseResult.EXECUTION_RESULT))) ? 1 : 5; testRail.results() .addForCase(run.getId(), crid, new Result().setStatusId(status).addCustomField("custom_execmode", 0) .setComment(this.logBaseUrl + cr.get(CaseResult.LOG_DIR) + "/log.html"), customResultFields) .execute(); } catch (Exception ex) { LOG.error("cannot add a new test case result", ex); } }); } finally { if (complete) { testRail.runs().close(run.getId()).execute(); } } }