List of usage examples for java.util List forEach
default void forEach(Consumer<? super T> action)
From source file:com.epam.ta.reportportal.job.InterruptBrokenLaunchesJob.java
private void interruptItems(List<TestItem> testItems, Launch launch) { if (testItems.isEmpty()) { return;/*from ww w . j a va 2s.co m*/ } testItems.forEach(this::interruptItem); Launch launchReloaded = launchRepository.findOne(launch.getId()); launchReloaded.setStatus(Status.INTERRUPTED); launchReloaded.setEndTime(Calendar.getInstance().getTime()); launchRepository.save(launchReloaded); /* * Delete references on failed\skipped tests in launch. It cannot be * used in main function cause break operators for valid launches. For * valid launches references from FailReference collections should be * kept. */ this.clearIssueReferences(launch.getId()); }
From source file:com.nike.cerberus.service.MetaDataService.java
protected Map<String, String> getCategoryIdToStringMap() { List<CategoryRecord> categoryRecords = categoryDao.getAllCategories(); Map<String, String> catIdToStringMap = new HashMap<>(categoryRecords.size()); categoryRecords.forEach( categoryRecord -> catIdToStringMap.put(categoryRecord.getId(), categoryRecord.getDisplayName())); return catIdToStringMap; }
From source file:edu.jhu.hlt.concrete.stanford.ConcreteStanfordTokensSentenceAnalytic.java
@Override public TokenizedCommunication annotate(SectionedCommunication arg0) throws AnalyticException { final Communication cp = new Communication(arg0.getRoot()); if (!cp.isSetText()) throw new AnalyticException("communication.text must be set to run this analytic."); AnalyticUUIDGeneratorFactory f = new AnalyticUUIDGeneratorFactory(cp); AnalyticUUIDGenerator g = f.create(); List<Section> sList = arg0.getSections().stream() // temporary hack - filter out // any zero-length TextSpans. .filter(s -> {/* ww w.ja v a 2 s . co m*/ final TextSpan ts = s.getTextSpan(); return ts.getStart() != ts.getEnding(); }) // temporary hack - filter out any // TextSpans that contain only whitespace. .filter(s -> { final TextSpan ts = s.getTextSpan(); final int b = ts.getStart(); final int e = ts.getEnding(); if (e < b) { LOGGER.warn("Invalid text span: end is less than start. Document: {}; TextSpan: {}", cp.getId(), ts.toString()); return false; } String txt = cp.getText().substring(b, e); // that isn't enough, could get HTML encoded blank spaces. if (txt.contains(" ")) txt = StringEscapeUtils.unescapeHtml4(txt); String slim = txt.trim().replaceAll("\\p{Zs}", ""); return !slim.isEmpty(); }).collect(Collectors.toList()); final int newSize = sList.size(); final int oSize = arg0.getSections().size(); if (newSize < oSize) LOGGER.info("Dropped {} section(s) because they were zero-length or contained only whitespace.", oSize - newSize); // for each section, run stanford tokenization and sentence splitting for (Section s : sList) { LOGGER.debug("Annotating section: {}", s.getUuid().getUuidString()); final TextSpan sts = s.getTextSpan(); final String sectTxt = cp.getText().substring(sts.getStart(), sts.getEnding()); // final String sectTxt = new SuperTextSpan(sts, cp).getText(); LOGGER.debug("Section text: {}", sectTxt); final Annotation sectAnnotation = new Annotation(sectTxt); LOGGER.debug("Got annotation keys:"); sectAnnotation.keySet().forEach(k -> LOGGER.debug("{}", k)); this.pipeline.annotate(sectAnnotation); LOGGER.trace("Post annotation annotation keys:"); sectAnnotation.keySet().forEach(k -> LOGGER.trace("{}", k)); List<CoreLabel> tokensOnly = sectAnnotation.get(TokensAnnotation.class); tokensOnly.forEach( cl -> LOGGER.trace("Got non-sent Stanford token: {}", cl.toShorterString(new String[0]))); // LOGGER.debug("Got first sentence text annotation: {}", sectAnnotation.get(SentencesAnnotation.class).get(0).get(TextAnnotation.class)); List<Sentence> stList = annotationToSentenceList(sectAnnotation, sts.getStart(), g); s.setSentenceList(stList); } cp.setSectionList(sList); try { return new CachedTokenizationCommunication(cp); } catch (MiscommunicationException e) { throw new AnalyticException(e); } }
From source file:com.epam.ta.reportportal.core.launch.impl.DeleteLaunchHandler.java
@Override public List<OperationCompletionRS> deleteLaunches(String[] ids, String projectName, String userName) { final List<String> toDelete = asList(ids); final List<Launch> launches = launchRepository.find(toDelete); final User user = userRepository.findOne(userName); final Project project = projectRepository.findOne(projectName); launches.forEach(launch -> validate(launch, user, project)); launchRepository.delete(toDelete);/*from w w w . j a v a2 s .co m*/ return launches.stream().map(launch -> { eventPublisher.publishEvent(new LaunchDeletedEvent(launch, userName)); return new OperationCompletionRS("Launch with ID = '" + launch.getId() + "' successfully deleted."); }).collect(toList()); }
From source file:natalia.dymnikova.cluster.scheduler.impl.find.optimal.FindOptimalAddressesStrategy.java
private <T> List<List<T>> getAllCombines(final List<List<T>> values, final int i) { if (i == values.size()) { final List<List<T>> list = new LinkedList<>(); list.add(emptyList());// ww w.j a va 2 s .c om return list; } final List<List<T>> result = new LinkedList<>(); final List<List<T>> previous = getAllCombines(values, i + 1); values.get(i).forEach(value -> { previous.forEach(combine -> { final LinkedList<T> e = new LinkedList<>(combine); e.add(0, value); result.add(e); }); }); return result; }
From source file:com.epam.ngb.cli.manager.command.handler.http.DatasetRegistrationHandler.java
/** * Verifies that input arguments contain the required parameters: * first argument must be reference ID or name, second dataset name and optional following * arguments may specify files to be added to the dataset (registered on the server files are * addressed by name or ID, for new files path should be provided). * If new files are registered by this command, all rules and restrictions that are * applied to file registration are used. * If a dataset is a part of hierarchical project, it's parent dataset may ne specified * by 'parentID' option (name or ID of parent dataset). * @param arguments command line arguments for 'register_dataset' command * @param options to specify a parentID of the dataset and output options *///from w w w .j a v a 2s .co m @Override public void parseAndVerifyArguments(List<String> arguments, ApplicationOptions options) { if (arguments.size() < 2) { throw new IllegalArgumentException( MessageConstants.getMessage(MINIMUM_COMMAND_ARGUMENTS, getCommand(), 2, arguments.size())); } name = arguments.get(1); prettyName = options.getPrettyName(); if (options.getParent() != null) { parentId = parseProjectId(options.getParent()); } items = new ArrayList<>(); Long referenceId = parseFileId(arguments.get(0)); printJson = options.isPrintJson(); printTable = options.isPrintTable(); items.add(new ProjectItem(referenceId, false)); Long referenceUniqueId = null; for (int i = 2; i < arguments.size(); i++) { String file = arguments.get(i); try { Long id = parseFileId(file); items.add(new ProjectItem(id, false)); continue; } catch (ApplicationException e) { LOGGER.debug(e.getMessage(), e); } ApplicationOptions registerOptions = new ApplicationOptions(); registerOptions.setDoIndex(options.isDoIndex()); referenceUniqueId = referenceUniqueId == null ? loadReferenceId(arguments.get(0)) : referenceUniqueId; FileRegistrationHandler handler = new FileRegistrationHandler(file, referenceUniqueId, this, registerOptions); handler.setRequestUrl(handler.getServerParameters().getRegistrationUrl()); handler.setRequestType("POST"); List<BiologicalDataItem> registeredFiles = handler.registerItems(); if (!registeredFiles.isEmpty()) { registeredFiles.forEach(f -> items.add(new ProjectItem(f.getBioDataItemId(), false))); } } }
From source file:ch.admin.suis.msghandler.signer.SignerTest.java
public void testSigningWithTwoOutboxes() throws SignerException, IOException, ConfigurationException { initialize();//from w ww.j a va2 s . c om System.out.println("testSigningWithTwoOutboxes"); SigningOutbox signOutbox1 = new SigningOutboxMHCfg(p12File, "12345678", signingOutbox1, signatureProperties, null); SigningOutbox signOutbox2 = new SigningOutboxMHCfg(p12File, "12345678", signingOutbox2, signatureProperties, null); List<SigningOutbox> outboxes = Arrays.asList(signOutbox1, signOutbox2); final File workingDir = createWorkingDir(); final File corruptedDir = new File(workingDir, ClientCommons.CORRUPTED_DIR); Signer signer = new Signer(outboxes, workingDir, corruptedDir); List<File> signedFiles = signer.sign(); signedFiles.forEach((f) -> { f.deleteOnExit(); }); assertEquals(signOutbox1.getAllPDFsToSign().size() + signOutbox2.getAllPDFsToSign().size(), signedFiles.size()); signer.cleanUp(signedFiles); assertEquals(0, signOutbox1.getAllPDFsToSign().size()); signer.cleanUp(signedFiles); assertEquals(0, signOutbox2.getAllPDFsToSign().size()); // The corrupted directory must be empty assert FileUtils.listFiles(corruptedDir, TrueFileFilter.INSTANCE, null).isEmpty(); }
From source file:com.klaussoft.springtest.CostumerController.java
@RequestMapping("/costumer") public Costumer costumer(@RequestParam(value = "name", defaultValue = "World") String cname) { log.info("Creating tables"); jdbcTemplate.execute("DROP TABLE customers IF EXISTS"); jdbcTemplate//from w w w.ja v a2s . c o m .execute("CREATE TABLE customers(" + "id SERIAL, first_name VARCHAR(255), last_name VARCHAR(255))"); // Split up the array of whole names into an array of first/last names List<Object[]> splitUpNames = Arrays.asList("John Woo", "Jeff Dean", "Josh Bloch", "Josh Long").stream() .map(name -> name.split(" ")).collect(Collectors.toList()); // Use a Java 8 stream to print out each tuple of the list splitUpNames .forEach(name -> log.info(String.format("Inserting customer record for %s %s", name[0], name[1]))); // Uses JdbcTemplate's batchUpdate operation to bulk load data jdbcTemplate.batchUpdate("INSERT INTO customers(first_name, last_name) VALUES (?,?)", splitUpNames); log.info("Querying for customer records where first_name = 'Josh':"); jdbcTemplate .query("SELECT id, first_name, last_name FROM customers WHERE first_name = ?", new Object[] { "Josh" }, (rs, rowNum) -> new Costumer(rs.getLong("id"), rs.getString("first_name"), rs.getString("last_name"))) .forEach(customer -> log.info(customer.toString())); return null; }
From source file:org.createnet.raptor.models.auth.User.java
@JsonProperty("roles") public void setListRoles(List<String> list) { list.forEach(r -> addRole(new Role(r))); }
From source file:com.lupinenetwork.commandwhitelister.database.MySQLWhitelistDatabase.java
/** * Inserts a list of arguments into the database. * * @param args the arguments to serialize * @return the encoded object//from w w w. j av a2 s . c o m * @throws SQLException if there is an error with the database */ @SuppressWarnings("unchecked") protected String JSONEncode(List<String> args) throws SQLException { JSONArray array = new JSONArray(); args.forEach(s -> array.put(s)); return array.toString(); }