List of usage examples for java.util.stream Collectors joining
public static Collector<CharSequence, ?, String> joining(CharSequence delimiter)
From source file:io.wcm.devops.conga.plugins.aem.util.ContentPackageUtil.java
/** * Merges description and file header to a single string. * @param description Description from configuration - may be null * @param fileHeader File header from file - may be null * @return Merged description or null if all input is null *//*w ww . jav a 2 s . c o m*/ private static String mergeDescriptionFileHeader(String description, FileHeaderContext fileHeader) { boolean hasDescription = StringUtils.isNotBlank(description); boolean hasFileHeader = fileHeader != null && !fileHeader.getCommentLines().isEmpty(); if (!hasDescription && !hasFileHeader) { return null; } StringBuilder result = new StringBuilder(); if (hasDescription) { result.append(description); } if (hasDescription && hasFileHeader) { result.append("\n---\n"); } if (hasFileHeader) { @SuppressWarnings("null") String fileHeaderString = StringUtils .trim(fileHeader.getCommentLines().stream().filter(line -> !StringUtils.contains(line, "*****")) .map(line -> StringUtils.trim(line)).collect(Collectors.joining("\n"))); result.append(fileHeaderString); } return result.toString(); }
From source file:com.blackducksoftware.integration.hub.detect.help.DetectOption.java
public void printOption(final HelpTextWriter writer) { String description = getDetectOptionHelp().description; if (getDetectOptionHelp().isDeprecated) { description = getDeprecationText() + description; }/*from w ww . j a va2 s .co m*/ if (getValidValues().size() > 0) { description += " (" + getValidValues().stream().collect(Collectors.joining("|")) + ")"; } String propertyKey = ""; String defaultValue = ""; if (StringUtils.isNotBlank(detectProperty.getPropertyKey())) { propertyKey = detectProperty.getPropertyKey(); } if (StringUtils.isNotBlank(detectProperty.getDefaultValue())) { defaultValue = detectProperty.getDefaultValue(); } writer.printColumns("--" + propertyKey, defaultValue, description); }
From source file:de.ks.flatadocdb.defaults.ReflectionLuceneDocumentExtractor.java
private ReflectionLuceneDocumentExtractor.DocField createCollectionDocField(Field f, MethodHandle getter) { return new DocField(f, getter, (id, value) -> { @SuppressWarnings("unchecked") String string = ((Collection<Object>) value).stream().map(String::valueOf) .collect(Collectors.joining(", ")); return new StringField(id, string, org.apache.lucene.document.Field.Store.YES); });//from w w w. j av a 2 s. c o m }
From source file:de.pixida.logtest.processing.JobExecutor.java
private void runEvaluations(final ILogReader logReader, final List<Automaton> automatons) { LOG.info("Starting analysis: Source '{}', simultaneous automatons: {}", logReader, automatons.stream()//from www.j a va2 s . c o m .map(automaton -> automaton == null ? "INVALID_AUTOMATON_DEFINITION" : automaton.toString()) .collect(Collectors.joining(", "))); Validate.notNull(logReader); Validate.notNull(automatons); try { logReader.open(); this.pipeLogEntriesIntoAutomatons(logReader, automatons); } finally { logReader.close(); } this.results.add(this.collectResults(automatons)); LOG.debug("Analysis finished. Results: {}", this.results.get(this.results.size() - 1)); }
From source file:com.culturedear.counterpoint.CounterpointSolution.java
private ScorePartwise doScorePartwise() { Measure curMeasure = new Measure(" "); ScorePartwise scorePartwise = new ScorePartwise(); if (notesAllVoices.size() > 0) { scorePartwise.getScoreParts().add(new ScorePart("Cantus firmus", "P1")); for (int voiceIdxA = 1; voiceIdxA < notesAllVoices.size(); voiceIdxA++) { scorePartwise.getScoreParts() .add(new ScorePart("Melody " + (voiceIdxA + 1), "P" + (voiceIdxA + 1))); }//ww w.j a v a 2 s. co m for (int voiceIdxB = 0; voiceIdxB < notesAllVoices.size(); voiceIdxB++) { Part part = new Part("P" + (voiceIdxB + 1)); scorePartwise.getParts().add(part); List<Note> notesForPart = notesAllVoices.get(voiceIdxB); // Iteratate over the notes in this part and insert Measure elements for (Note note : notesForPart) { int onset = note.getOnset(); if (onset % onsetUnitsPerMeasure == 0) { curMeasure = new Measure("" + (onset / onsetUnitsPerMeasure + 1)); part.getMeasures().add(curMeasure); } curMeasure.getNotes().add(note); } } } // Iterate over the measures for all parts, identifying the first chord in each measure boolean keepGoing = true; int measureNum = 0; while (keepGoing) { log.debug("Analyzing chord for measure " + measureNum); Note topMeasureFirstNote = null; List<Note> chordNotes = new ArrayList<>(); List<Part> parts = scorePartwise.getParts(); for (Part part : parts) { List<Measure> measures = part.getMeasures(); if (measureNum < measures.size()) { Measure measure = measures.get(measureNum); List<Note> notes = measure.getNotes(); if (notes.size() > 0) { Note firstNoteInMeasure = notes.get(0); if (measureNum == 0 && firstNoteInMeasure.getPitch().octave <= 3) { // First note in measure is below middle C, so use bass clef Clef clef = new Clef("F", 4); MeasureAttributes measureAttributes = new MeasureAttributes(clef); measure.setMeasureAttributes(measureAttributes); } if (topMeasureFirstNote == null) { topMeasureFirstNote = firstNoteInMeasure; } chordNotes.add(firstNoteInMeasure); } else { // Unexpected, as all measures should have at least one note keepGoing = false; } } else { // We've run out of measures in at least one part keepGoing = false; } } if (topMeasureFirstNote != null) { Collections.sort(chordNotes); String notesString = chordNotes.stream().map(note -> note.getPitch().toString()) .collect(Collectors.joining(" ")); // Call the Chord Analyzer service RestTemplate restTemplate = new RestTemplate(); Lyric lyric = null; try { ClientMusicChord clientMusicChord = restTemplate.getForObject( this.counterpointProperties.getAnalyzerServiceEndpoint(notesString), ClientMusicChord.class); String chordTypeStr = clientMusicChord.getChordType(); String chordNotationStr = clientMusicChord.getRoot(); if (chordTypeStr.equalsIgnoreCase("pow")) { chordNotationStr += "5"; // This is a power chord (triad with no 3) } else { chordNotationStr += " " + chordTypeStr; } // Notate as a slash chord if appropriate if (clientMusicChord.getInversion() != 0) { chordNotationStr += "/" + clientMusicChord.getBassNote(); } lyric = new Lyric(chordNotationStr); } catch (Exception e) { log.info("Caught exception when analyzing chord " + e); //lyric = new Lyric("???"); } topMeasureFirstNote.setLyric(lyric); } measureNum++; } return scorePartwise; }
From source file:ch.ifocusit.plantuml.PlantUmlBuilder.java
public PlantUmlBuilder addType(Clazz clazz) { Validate.notNull(clazz, "No class defined !"); clazz.validate();//from w ww . j av a 2 s . c o m writeClazzDefinition(clazz); // stereotype clazz.getStereotypes().ifPresent(stereotypes -> content.append(SPACE).append(STEREOTYPE_OPEN) .append(stereotypes.stream().collect(Collectors.joining(", "))).append(STEREOTYPE_CLOSE)); // class link clazz.getLink().ifPresent(link -> content.append(SPACE).append(link.toString())); // class color clazz.getBackgroundColor().ifPresent(color -> content.append(SPACE).append(color(color))); if (clazz.hasContent()) { content.append(SPACE).append(BRACE_OPEN).append(NEWLINE); } // add attributes for (Attribute attribute : clazz.getAttributes()) { // name content.append(TAB).append(attribute.getName()); // type attribute.getTypeName() .ifPresent(type -> content.append(SPACE).append(SEMICOLON).append(SPACE).append(type)); // field link attribute.getLink().ifPresent(link -> content.append(SPACE).append(link.toString())); content.append(NEWLINE); } // add methods clazz.getMethods().stream().forEach(method -> { // name content.append(TAB).append(method.getName()); // parameters method.getParameters().ifPresent(params -> { content.append(BRACKET_OPEN); content.append(Stream.of(params).map(param -> param.getTypeName().orElse(param.getName())) .collect(Collectors.joining(COMMA + SPACE))); content.append(BRACKET_CLOSE); }); // type method.getReturnTypeName() .ifPresent(type -> content.append(SPACE).append(SEMICOLON).append(SPACE).append(type)); // method link method.getLink().ifPresent(link -> content.append(SPACE).append(link.toString())); content.append(NEWLINE); }); if (clazz.hasContent()) { content.append(BRACE_CLOSE); } if (!clazz.getAttributes().isEmpty()) { } content.append(NEWLINE).append(NEWLINE); return this; }
From source file:com.epam.catgenome.manager.BiologicalDataItemManager.java
/** * Generates a URL parameters that will open required files on required position, specified by chromosome name, * start and end indexes//from ww w. ja va2s. c o m * * * @param dataset * @param ids bio logical * @param chromosomeName * @param startIndex * @param endIndex * @return * @throws JsonProcessingException */ @Transactional(propagation = Propagation.REQUIRED) public String generateUrl(String dataset, List<String> ids, String chromosomeName, Integer startIndex, Integer endIndex) throws JsonProcessingException { Project project; if (NumberUtils.isDigits(dataset)) { project = projectManager.loadProject(Long.parseLong(dataset)); } else { project = projectManager.loadProject(dataset); } Assert.notNull(project, getMessage(MessagesConstants.ERROR_PROJECT_NOT_FOUND, dataset)); List<String> bioItemNames = new ArrayList<>(); List<Long> bioItemIds = new ArrayList<>(); for (String id : ids) { if (NumberUtils.isDigits(id)) { bioItemIds.add(Long.parseLong(id)); } else { bioItemNames.add(id); } } List<BiologicalDataItem> itemsByNames = biologicalDataItemDao.loadFilesByNamesStrict(bioItemNames); if (itemsByNames.size() != bioItemNames.size()) { throw new IllegalArgumentException(getMessage(MessagesConstants.ERROR_BIO_NAME_NOT_FOUND, bioItemNames.stream().filter(n -> itemsByNames.stream().noneMatch(i -> i.getName().equals(n))) .collect(Collectors.joining(", ")))); } List<BiologicalDataItem> itemsByIds = biologicalDataItemDao.loadBiologicalDataItemsByIds(bioItemIds); if (itemsByIds.size() != bioItemIds.size()) { throw new IllegalArgumentException(getMessage(MessagesConstants.ERROR_BIO_ID_NOT_FOUND, bioItemIds.stream().filter(id -> itemsByIds.stream().noneMatch(i -> i.getId().equals(id))) .map(Object::toString).collect(Collectors.joining(", ")))); } List<BiologicalDataItem> items = new ArrayList<>(itemsByNames.size() + itemsByIds.size()); items.addAll(itemsByNames); items.addAll(itemsByIds); List<Long> references = project.getItems().stream() .filter(item -> item.getBioDataItem().getFormat() == BiologicalDataItemFormat.REFERENCE) .map(item -> item.getBioDataItem().getId()).collect(Collectors.toList()); Assert.notNull(references); Assert.isTrue(!references.isEmpty()); Long referenceId = references.get(0); List<Long> itemIds = new ArrayList<>(items.size()); for (BiologicalDataItem item : items) { if (FeatureFile.class.isAssignableFrom(item.getClass())) { FeatureFile file = (FeatureFile) item; Assert.isTrue( project.getItems().stream().anyMatch(i -> i.getBioDataItem().getId().equals(item.getId())), getMessage(MessagesConstants.ERROR_PROJECT_FILE_NOT_FOUND, item.getName(), project.getName())); Assert.isTrue(referenceId.equals(file.getReferenceId()), "Specified files have different references"); } itemIds.add(BiologicalDataItem.getBioDataItemId(item)); } Reference reference = referenceGenomeManager.loadReferenceGenome(referenceId); return makeUrl(items, project, reference, chromosomeName, startIndex, endIndex); }
From source file:edu.harvard.iq.dataverse.DataCitation.java
public String toString(boolean html) { // first add comma separated parts List<String> citationList = new ArrayList<>(); citationList.add(formatString(authors, html)); citationList.add(year);/*from w w w .j a va 2 s . c o m*/ citationList.add(formatString(title, html, "\"")); if (persistentId != null) { citationList.add(formatURL(persistentId.toString(), persistentId.toURL().toString(), html)); } citationList.add(formatString(distributors, html)); citationList.add(version); StringBuilder citation = new StringBuilder(citationList.stream() .filter(value -> !StringUtils.isEmpty(value)).collect(Collectors.joining(", "))); // append UNF if (!StringUtils.isEmpty(UNF)) { citation.append(", ").append(UNF); } for (DatasetField dsf : optionalValues) { String displayName = dsf.getDatasetFieldType().getDisplayName(); String displayValue; if (dsf.getDatasetFieldType().getFieldType().equals(DatasetFieldType.FieldType.URL)) { displayValue = formatURL(dsf.getDisplayValue(), dsf.getDisplayValue(), html); if (optionalURLcount == 1) { displayName = "URL"; } } else { displayValue = formatString(dsf.getDisplayValue(), html); } citation.append(" [").append(displayName).append(": ").append(displayValue).append("]"); } return citation.toString(); }
From source file:org.rakam.analysis.eventexplorer.EventExplorerHttpService.java
@ApiOperation(value = "Create Pre-computed table", authorizations = @Authorization(value = "master_key")) @JsonRequest//from w w w.ja v a 2s . c o m @Path("/pre_calculate") public CompletableFuture<PrecalculatedTable> createPrecomputedTable(@Named("project") String project, @BodyParam OLAPTable table) { String metrics = table.measures.stream().map(column -> table.aggregations.stream() .map(agg -> getAggregationColumn(agg, table.aggregations) .map(e -> String.format(e, column) + " as " + column + "_" + agg.name().toLowerCase())) .filter(Optional::isPresent).map(Optional::get).collect(Collectors.joining(", "))) .collect(Collectors.joining(", ")); String subQuery; String dimensions = table.dimensions.stream().collect(Collectors.joining(", ")); if (table.collections.size() == 1) { subQuery = table.collections.iterator().next(); } else if (table.collections.size() > 1) { subQuery = table.collections.stream() .map(collection -> String.format("SELECT '%s' as collection, _time %s %s FROM %s", collection, dimensions.isEmpty() ? "" : ", " + dimensions, table.measures.isEmpty() ? "" : ", " + table.measures.stream().collect(Collectors.joining(", ")), collection)) .collect(Collectors.joining(" UNION ALL ")); } else { throw new RakamException("collections is empty", HttpResponseStatus.BAD_REQUEST); } String name = "Dimensions"; String dimensionColumns = !dimensions.isEmpty() ? (dimensions + ",") : ""; String collectionColumn = table.collections.size() != 1 ? ("collection,") : ""; String query = String.format( "SELECT %s _time, %s %s FROM (SELECT %s CAST(_time AS DATE) as _time, %s %s FROM (%s)) GROUP BY CUBE (_time %s %s) ORDER BY 1 ASC", collectionColumn, dimensionColumns, metrics, collectionColumn, dimensionColumns, table.measures.stream().collect(Collectors.joining(", ")), subQuery, table.collections.size() == 1 ? "" : ", collection", dimensions.isEmpty() ? "" : "," + dimensions); return materializedViewService .create(project, new MaterializedView(table.tableName, "Olap table", query, Duration.ofHours(1), null, ImmutableMap.of("olap_table", table))) .thenApply(v -> new PrecalculatedTable(name, table.tableName)); }