List of usage examples for java.util.stream Collectors joining
public static Collector<CharSequence, ?, String> joining(CharSequence delimiter)
From source file:org.fenixedu.start.controller.StartController.java
@RequestMapping(value = "/module.txt", method = RequestMethod.POST) @ResponseBody/*from w ww. ja va 2 s.co m*/ String moduleText(@ModelAttribute ProjectRequest request) throws IOException, PebbleException { return projectService.buildModule(request).entrySet().stream() .map(entry -> "Path: " + entry.getKey() + "\nValue:\n" + new String(entry.getValue())) .collect(Collectors.joining("\n\n---------\n\n")); }
From source file:com.nextdoor.bender.config.Source.java
public String toString() { String patterns = this.regexPatterns.stream().map(c -> { return c.toString(); }).collect(Collectors.joining(", ")); String operations = this.operationProcessors.stream().map(c -> { return c.getOperation().getClass().getSimpleName(); }).collect(Collectors.joining(", ")); return this.sourceName + "[" + "sourceRegex=" + this.sourceRegex + ", containsStrings=[" + StringUtils.join(this.containsStrings, ',') + "], regexPatterns=[" + patterns + "]" + "], deserializers=[" + this.deserProcessor + "]" + "], operations=[" + operations + "]]"; }
From source file:com.thinkbiganalytics.metadata.modeshape.datasource.JcrDatasourceDefinition.java
@Override public String getIdentityString() { String identityString = JcrPropertyUtil.getProperty(this.node, IDENTITY_STRING, true); if (StringUtils.isBlank(identityString)) { identityString = getDatasourcePropertyKeys().stream().map(key -> "${" + key + "}") .collect(Collectors.joining(",")); }//from ww w . j a v a2 s . co m return identityString; }
From source file:com.linecorp.armeria.server.docs.ThriftDocString.java
/** * Gets the namespace key of names.// ww w . j a v a 2 s . c om * @param names name list. * @return merged key. */ static String key(String... names) { return Stream.of(names).filter(s -> !Strings.isNullOrEmpty(s)).collect(Collectors.joining(DELIM)); }
From source file:com._4dconcept.springframework.data.marklogic.core.cts.CTSQuerySerializer.java
private String serializeCriteria(@Nullable Criteria criteria) { if (criteria != null) { if (criteria.getOperator() == null) { return handleSimpleValue(criteria); } else {/*from w w w .j a va 2 s. com*/ List<Criteria> criteriaList = retrieveCriteriaList(criteria); String ctsQueries = criteriaList.stream().map(this::serializeCriteria) .collect(Collectors.joining(", ")); switch (criteria.getOperator()) { case and: return String.format("cts:and-query((%s))", ctsQueries); case or: return String.format("cts:or-query((%s))", ctsQueries); } } } return "()"; }
From source file:com.hazelcast.qasonar.listpullrequests.ListPullRequests.java
public void run() throws IOException { print("Connecting to GitHub..."); GitHub github = GitHub.connect();/*from w ww . j a va 2 s.co m*/ GHRepository repo = github.getRepository(gitHubRepository); print("Searching milestone \"%s\"...", milestoneTitle); GHMilestone milestone = getMilestone(milestoneTitle, repo); if (milestone == null) { printRed("Could not find milestone \"%s\"!", milestoneTitle); return; } print("Searching merged PRs for milestone \"%s\"...", milestoneTitle); List<Integer> pullRequests = getPullRequests(repo, milestone, calendar); print("Sorting %d PRs...", pullRequests.size()); pullRequests.sort(Integer::compareTo); String pullRequestString = pullRequests.stream().map(String::valueOf).collect(Collectors.joining(",")); String command = (pullRequests.size() > 0) ? format("qa-sonar%s%s%s --pullRequests %s --outputFile %s%n", optionalParameters, outputGithubRepository, outputDefaultModule, pullRequestString, outputFile) : format("No PRs have been found for milestone %s in this repository!", milestone); if (scriptFile != null && pullRequests.size() > 0) { File file = new File(scriptFile); String script = readFileToString(file); writeStringToFile(file, format("%s%s%n", script, command)); } printTimeTracks(); printGreen("Done!\n"); print(command); }
From source file:net.kemitix.checkstyle.ruleset.builder.ReadmeWriter.java
private String readmeRules(final Predicate<Rule> predicate) { return rulesProperties.getRules().stream().filter(predicate).flatMap(ruleReadmeLoader::load) .collect(Collectors.joining(NEWLINE)); }
From source file:eu.crydee.stanfordcorenlp.Tokenizer.java
/** * Tokenize only./*from w w w.j a v a 2 s . c om*/ * * @param input the String to tokenize. * @return a String of the tokenized text with space separated words. */ public String tokenize(String input) { Annotation annotation = new Annotation(input); pipelineWithoutSS.annotate(annotation); return annotation.get(TokensAnnotation.class).stream().map(ann -> ann.get(TextAnnotation.class)) .collect(Collectors.joining(" ")); }
From source file:dk.dbc.rawrepo.oai.OAIIdentifierCollection.java
/** * Fetch identifiers from database//from w w w . java 2 s . com * * json argument is object with: null null null null null {@literal * f: fromTimestamp* * u: untilTimestamp* * m: metadataPrefix * o: fromOffset (how many records with fromTimestamp has been seen)* * s: set* * } * * @param json as described * @param limit how many records to fetch * @return json as described or null if no more records */ @SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING") public ObjectNode fetch(ObjectNode json, int limit) { log.debug("limit = " + limit); StringBuilder sb = new StringBuilder(); String set = json.path("s").asText(null); String from = json.path("f").asText(null); String until = json.path("u").asText(null); String metadataPrefix = json.path("m").asText(""); int offset = json.path("o").asInt(0); sb.append("SELECT pid, changed, deleted FROM oairecords JOIN oairecordsets USING (pid) WHERE"); if (set != null) { sb.append(" setSpec = ?"); } else if (allowedSets.isEmpty()) { return null; } else { sb.append(" setSpec IN ('"); sb.append(allowedSets.stream().sorted().collect(Collectors.joining("', '"))); sb.append("')"); } sb.append(" AND ? in (SELECT prefix FROM oaiformats)"); if (from != null) { sb.append(" AND"); if (from.contains(".")) { sb.append( " DATE_TRUNC('milliseconds', changed) >= DATE_TRUNC('milliseconds', ?::timestamp AT TIME ZONE 'UTC')"); } else if (from.contains("T")) { sb.append( " DATE_TRUNC('second', changed) >= DATE_TRUNC('second', ?::timestamp AT TIME ZONE 'UTC')"); } else { sb.append(" DATE_TRUNC('day', changed) >= DATE_TRUNC('day', ?::timestamp AT TIME ZONE 'UTC')"); } } if (until != null) { sb.append(" AND"); if (until.contains(".")) { sb.append( " DATE_TRUNC('milliseconds', changed) <= DATE_TRUNC('milliseconds', ?::timestamp AT TIME ZONE 'UTC')"); } else if (until.contains("T")) { sb.append( " DATE_TRUNC('second', changed) <= DATE_TRUNC('second', ?::timestamp AT TIME ZONE 'UTC')"); } else { sb.append(" DATE_TRUNC('day', changed) <= DATE_TRUNC('day', ?::timestamp AT TIME ZONE 'UTC')"); } } sb.append(" GROUP BY pid"); if (set != null) { sb.append(", gone"); } sb.append(" ORDER BY changed, pid OFFSET ? LIMIT ?"); String query = sb.toString(); log.debug("query = " + query); sb = new StringBuilder(); sb.append("SELECT setSpec FROM oairecordsets WHERE pid = ? AND setSpec IN ('") .append(allowedSets.stream().sorted().collect(Collectors.joining("', '"))) .append("') AND NOT gone ORDER BY setSpec"); String setQuery = sb.toString(); Timestamp last = null; int row = 0; try (PreparedStatement stmt = connection.prepareStatement(query); PreparedStatement sets = connection.prepareStatement(setQuery)) { int i = 1; if (set != null) { stmt.setString(i++, set); } stmt.setString(i++, metadataPrefix); if (from != null) { stmt.setString(i++, from); } if (until != null) { stmt.setString(i++, until); } stmt.setInt(i++, offset); stmt.setInt(i++, limit + 1); try (ResultSet resultSet = stmt.executeQuery()) { while (resultSet.next()) { row++; String pid = resultSet.getString(1); Timestamp changed = resultSet.getTimestamp(2); Boolean deleted = resultSet.getBoolean(3); if (row <= limit) { OAIIdentifier oaiRecord = new OAIIdentifier(pid, changed, deleted); sets.setString(1, pid); try (ResultSet setsResult = sets.executeQuery()) { while (setsResult.next()) { oaiRecord.add(setsResult.getString(1)); } } if (oaiRecord.isEmpty() && !oaiRecord.isDeleted()) { oaiRecord = new OAIIdentifier(pid, changed, true); } add(oaiRecord); if (changed.equals(last)) { offset++; } else { last = changed; offset = 1; } } else { ObjectNode obj = OBJECT_MAPPER.createObjectNode(); String continueFrom = changed.toInstant().atZone(ZoneId.systemDefault()) .format(DateTimeFormatter.ISO_INSTANT); obj.put("f", continueFrom); if (changed.equals(last)) { obj.put("o", offset); } if (until != null) { obj.put("u", until); } if (set != null) { obj.put("s", set); } if (metadataPrefix != null) { obj.put("m", metadataPrefix); } log.debug("continueFrom = " + obj); return obj; } } } } catch (SQLException ex) { log.error("Exception: " + ex.getMessage()); log.debug("Exception:", ex); throw new ServerErrorException(Response.Status.INTERNAL_SERVER_ERROR, "Internal Error"); } return null; }
From source file:eu.crydee.alignment.aligner.cr.MetricsCR.java
@Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); whitelistFile = new File(whitelistFilePath); List<String> errs = new ArrayList<>(); if (!whitelistFile.isFile()) { errs.add("The run file doesn't resolve to a file."); } else if (!whitelistFile.canRead()) { errs.add("The run file can't be read."); }/*from w w w .j a v a 2 s .com*/ if (!errs.isEmpty()) { logger.error(errs.stream().collect(Collectors.joining("\n"))); throw new ResourceInitializationException(); } try { Set<String> lines = new HashSet<>(FileUtils.readLines(whitelistFile, StandardCharsets.UTF_8)); it = Sets.cartesianProduct(lines, lines).iterator(); } catch (FileNotFoundException e) { logger.error("Couldn't find the run file.", e); throw new ResourceInitializationException(e); } catch (IOException e) { logger.error("Couldn't read the whitelist file.", e); throw new ResourceInitializationException(e); } currentIndex = 0; }