List of usage examples for java.util.stream Collectors joining
public static Collector<CharSequence, ?, String> joining(CharSequence delimiter)
From source file:com.kantenkugel.discordbot.moduleutils.DocParser.java
public static String get(String name) { String[] split = name.toLowerCase().split("[#\\.]", 2); if (split.length != 2) return "Incorrect Method declaration"; List<Documentation> methods; synchronized (docs) { if (!docs.containsKey(split[0])) return "Class not Found!"; methods = docs.get(split[0]);//w ww .j av a 2 s .co m } methods = methods.parallelStream().filter(doc -> doc.matches(split[1])) .sorted(Comparator.comparingInt(doc -> doc.argTypes.size())).collect(Collectors.toList()); if (methods.size() == 0) return "Method not found/documented in Class!"; if (methods.size() > 1 && methods.get(0).argTypes.size() != 0) return "Multiple methods found: " + methods.parallelStream() .map(m -> '(' + StringUtils.join(m.argTypes, ", ") + ')').collect(Collectors.joining(", ")); Documentation doc = methods.get(0); StringBuilder b = new StringBuilder(); b.append("```\n").append(doc.functionHead).append("\n```\n").append(doc.desc); if (doc.args.size() > 0) { b.append('\n').append('\n').append("**Arguments:**"); doc.args.entrySet().stream().map(e -> "**" + e.getKey() + "** - " + e.getValue()) .forEach(a -> b.append('\n').append(a)); } if (doc.returns != null) b.append('\n').append('\n').append("**Returns:**\n").append(doc.returns); if (doc.throwing.size() > 0) { b.append('\n').append('\n').append("**Throws:**"); doc.throwing.entrySet().stream().map(e -> "**" + e.getKey() + "** - " + e.getValue()) .forEach(a -> b.append('\n').append(a)); } return b.toString(); }
From source file:com.github.ljtfreitas.restify.http.spring.contract.metadata.reflection.SpringWebRequestMappingMetadata.java
private Optional<String> produces() { return Optional.ofNullable(mapping).map(m -> m.produces()).filter(c -> c.length >= 1) .map(h -> Arrays.stream(h).filter(c -> c != null && !c.isEmpty()).collect(Collectors.joining(", "))) .map(c -> HttpHeaders.ACCEPT + "=" + c); }
From source file:com.ikanow.aleph2.data_model.interfaces.data_analytics.IAnalyticsAccessContext.java
/** Describes the current access context, defaults to some semi-useful description but can be overriden * at the point of creation/*w w w . j a va2s . co m*/ * @return a string describing the access context */ default String describe() { //(by default return the keys but not the values in case there's a massive number of them) return ErrorUtils.get("service_name={0} options={1}", this.getAccessService().<String>either(l -> l.getClass().getSimpleName(), r -> r.getSimpleName()), this.getAccessConfig().<String>map(cfg -> cfg.keySet().stream().collect(Collectors.joining(";"))) .orElse("")); }
From source file:de.thingweb.servient.impl.MultiBindingThingServer.java
private static String urlizeTokens(String url) { return Arrays.stream(url.split("/")).map(MultiBindingThingServer::urlize).collect(Collectors.joining("/")); }
From source file:io.syndesis.jsondb.impl.JsonRecordSupport.java
public static String convertToDBPath(String base) { String value = Arrays.stream(base.split("/")).filter(x -> !x.isEmpty()).map( x -> INTEGER_PATTERN.matcher(validateKey(x)).matches() ? toArrayIndexPath(Integer.parseInt(x)) : x) .collect(Collectors.joining("/")); return Strings.suffix(Strings.prefix(value, "/"), "/"); }
From source file:ddf.catalog.transformer.output.rtf.model.ExportCategory.java
private String attributeKeyFrom(String key) { if (key.startsWith(EXTENDED_ATTRIBUTE_PREFIX)) { key = key.replaceFirst(EXTENDED_ATTRIBUTE_PREFIX, ""); }//from ww w . j a v a2 s . c o m String formattedAttribute = Stream.of(key.split("\\.")).map(part -> part.replaceAll("-", " ")) .collect(Collectors.joining(" ")); return WordUtils.capitalize(formattedAttribute); }
From source file:com.intuit.wasabi.tests.service.priority.BatchPriorityAssignmentTest.java
@Test(groups = { "setup" }, dependsOnMethods = { "setup" }) public void setupMutexAndPriority() { String exclusion = "{\"experimentIDs\": [" + validExperimentsLists.stream().map(s -> "\"" + s.id + "\"").collect(Collectors.joining(",")) + "]}"; response = apiServerConnector.doPost("experiments/" + validExperimentsLists.get(0).id + "/exclusions", exclusion);//from w w w .j a v a 2s .c o m assertReturnCode(response, HttpStatus.SC_CREATED); response = apiServerConnector .doPut("applications/" + validExperimentsLists.get(0).applicationName + "/priorities", exclusion); assertReturnCode(response, HttpStatus.SC_NO_CONTENT); response = apiServerConnector .doGet("applications/" + validExperimentsLists.get(0).applicationName + "/priorities"); LOGGER.info("retrieved priorities: " + response.asString()); Type listType = new TypeToken<Map<String, ArrayList<Map<String, Object>>>>() { }.getType(); Map<String, List<Map<String, Object>>> result = new Gson().fromJson(response.asString(), listType); List<Map<String, Object>> prioritizedExperiments = result.get("prioritizedExperiments"); Assert.assertEquals(prioritizedExperiments.size(), validExperimentsLists.size()); for (int i = 0; i < validExperimentsLists.size(); i++) { Assert.assertEquals(prioritizedExperiments.get(i).get("id"), validExperimentsLists.get(i).id); } }
From source file:com.epam.ta.reportportal.demo_data.DemoLogsService.java
List<Log> generateDemoLogs(String itemId, String status) { try (BufferedReader errorsBufferedReader = new BufferedReader( new InputStreamReader(errorLogsResource.getInputStream(), UTF_8)); BufferedReader demoLogsBufferedReader = new BufferedReader( new InputStreamReader(demoLogs.getInputStream(), UTF_8))) { String error = errorsBufferedReader.lines().collect(Collectors.joining("\n")); List<String> logMessages = demoLogsBufferedReader.lines().collect(toList()); int t = random.nextInt(30); List<Log> logs = IntStream.range(1, t + 1).mapToObj(it -> { Log log = new Log(); log.setLevel(logLevel());// w w w. j av a 2s .c o m log.setLogTime(new Date()); log.setTestItemRef(itemId); log.setLogMsg(logMessages.get(random.nextInt(logMessages.size()))); return log; }).collect(toList()); if (FAILED.name().equals(status)) { String file = dataStorage.saveData( new BinaryData(IMAGE_PNG_VALUE, img.contentLength(), img.getInputStream()), "file"); Log log = new Log(); log.setLevel(ERROR); log.setLogTime(new Date()); log.setTestItemRef(itemId); log.setLogMsg(error); final BinaryContent binaryContent = new BinaryContent(file, file, IMAGE_PNG_VALUE); log.setBinaryContent(binaryContent); logs.add(log); } return logRepository.save(logs); } catch (IOException e) { throw new ReportPortalException("Unable to generate demo logs", e); } }
From source file:com.ikanow.aleph2.analytics.storm.assets.PassthroughTopology.java
@Override public Tuple2<Object, Map<String, String>> getTopologyAndConfiguration(final DataBucketBean bucket, final IEnrichmentModuleContext context) { final TopologyBuilder builder = new TopologyBuilder(); final Collection<Tuple2<BaseRichSpout, String>> entry_points = context .getTopologyEntryPoints(BaseRichSpout.class, Optional.of(bucket)); //DEBUG/*from www . j av a 2 s. c o m*/ _logger.debug("Passthrough topology: loaded: " + entry_points.stream().map(x -> x.toString()).collect(Collectors.joining(":"))); entry_points.forEach(spout_name -> builder.setSpout(spout_name._2(), spout_name._1())); entry_points.stream() .reduce(builder.setBolt(BOLT_NAME, context.getTopologyStorageEndpoint(BaseRichBolt.class, Optional.of(bucket))), (acc, v) -> acc.localOrShuffleGrouping(v._2()), (acc1, acc2) -> acc1 // (not possible in practice) ); return Tuples._2T(builder.createTopology(), Collections.emptyMap()); }
From source file:fi.helsinki.opintoni.dto.CourseDto.java
@Override public String toString() { return new ToStringBuilder(this).append("code", code).append("typeCode", typeCode).append("name", name) .append("imageUri", imageUri).append("coursePageUri", coursePageUri) .append("courseMaterial", courseMaterial).append("webOodiUri", webOodiUri) .append("startDate", startDate).append("endDate", endDate).append("realisationId", realisationId) .append("parentId", parentId) .append("teachers", teachers.stream().collect(Collectors.joining(", "))).append("isExam", isExam) .append("isCancelled", isCancelled).toString(); }