List of usage examples for java.util Map forEach
default void forEach(BiConsumer<? super K, ? super V> action)
From source file:org.obiba.agate.web.rest.notification.NotificationsResource.java
/** * Send an email by processing a template with request form parameters and the recipient * {@link org.obiba.agate.domain.User} as a context. The Template is expected to be located in a folder having * the application name.//from w w w . j a v a 2 s . c o m * * @param subject * @param templateName * @param context * @param recipients */ private void sendTemplateEmail(String subject, String templateName, Map<String, String[]> context, Set<User> recipients) { org.thymeleaf.context.Context ctx = new org.thymeleaf.context.Context(); context.forEach((k, v) -> { if (v != null && v.length == 1) { ctx.setVariable(k, v[0]); } else { ctx.setVariable(k, v); } }); String templateLocation = getApplicationName() + "/" + templateName; recipients.forEach(rec -> { ctx.setVariable("user", rec); ctx.setLocale(LocaleUtils.toLocale(rec.getPreferredLanguage())); mailService.sendEmail(rec.getEmail(), subject, templateEngine.process(templateLocation, ctx)); }); }
From source file:com.android.tools.idea.diagnostics.crash.GoogleCrash.java
@NotNull @Override/*from w w w . j a v a 2 s.c om*/ public CompletableFuture<String> submit(@NotNull Map<String, String> kv) { Map<String, String> parameters = getDefaultParameters(); kv.forEach(parameters::put); return submit(newMultipartEntityBuilderWithKv(parameters).build()); }
From source file:cc.redpen.server.api.RedPenConfigurationResource.java
@Path("/redpens") @GET/* ww w. ja v a 2 s. c o m*/ @Produces(MediaType.APPLICATION_JSON) @WinkAPIDescriber.Description("Return the configuration for available redpens matching the supplied language (default is any language)") public Response getRedPens(@QueryParam("lang") @DefaultValue("") String lang) throws RedPenException { JSONObject response = new JSONObject(); // add the known document formats try { response.put("version", RedPen.VERSION); response.put("documentParsers", DocumentParser.PARSER_MAP.keySet()); // add matching configurations Map<String, RedPen> redpens = getRedPenService().getRedPens(); final JSONObject redpensJSON = new JSONObject(); response.put("redpens", redpensJSON); redpens.forEach((configurationName, redPen) -> { if ((lang == null) || lang.isEmpty() || redPen.getConfiguration().getLang().contains(lang)) { try { // add specific configuration items JSONObject config = new JSONObject(); config.put("lang", redPen.getConfiguration().getLang()); config.put("variant", redPen.getConfiguration().getVariant()); config.put("tokenizer", redPen.getConfiguration().getTokenizer().getClass().getName()); // add the names of the validators JSONObject validatorConfigs = new JSONObject(); for (Validator validator : redPen.getValidators()) { JSONObject validatorJSON = new JSONObject(); String name = validator.getClass().getSimpleName().endsWith("Validator") ? validator.getClass().getSimpleName().substring(0, validator.getClass().getSimpleName().length() - 9) : validator.getClass().getSimpleName(); validatorJSON.put("languages", validator.getSupportedLanguages()); validatorJSON.put("properties", validator.getConfigAttributes()); validatorConfigs.put(name, validatorJSON); } config.put("validators", validatorConfigs); // add the symbol table JSONObject symbolConfigs = new JSONObject(); for (SymbolType symbolType : redPen.getConfiguration().getSymbolTable().getNames()) { JSONObject symbolJSON = new JSONObject(); Symbol symbol = redPen.getConfiguration().getSymbolTable().getSymbol(symbolType); symbolJSON.put("value", String.valueOf(symbol.getValue())); symbolJSON.put("invalid_chars", String.valueOf(symbol.getInvalidChars())); symbolJSON.put("after_space", symbol.isNeedAfterSpace()); symbolJSON.put("before_space", symbol.isNeedBeforeSpace()); symbolConfigs.put(symbolType.toString(), symbolJSON); } config.put("symbols", symbolConfigs); redpensJSON.put(configurationName, config); } catch (Exception e) { LOG.error("Exception when rendering RedPen to JSON for configuration " + configurationName, e); } } }); } catch (Exception e) { LOG.error("Exception when rendering RedPen to JSON", e); } return Response.ok().entity(response).build(); }
From source file:org.janusgraph.graphdb.management.ConfigurationManagementGraph.java
private Map<String, Object> deserializeVertexProperties(Map<String, Object> map) { map.forEach((key, value) -> { if (value instanceof List) { if (((List) value).size() > 1) { log.warn("Your configuration management graph is an a bad state. Please " + "ensure each vertex property is not supplied a Collection as a value. The behavior " + "of the class' APIs are henceforth unpredictable until this is fixed."); }/*from w w w . jav a2 s . c o m*/ map.put(key, ((List) value).get(0)); } }); return map; }
From source file:io.github.swagger2markup.internal.component.ResponseComponent.java
@Override public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) { PathOperation operation = params.operation; Map<String, Response> responses = operation.getOperation().getResponses(); MarkupDocBuilder responsesBuilder = copyMarkupDocBuilder(markupDocBuilder); applyPathsDocumentExtension(new PathsDocumentExtension.Context( PathsDocumentExtension.Position.OPERATION_RESPONSES_BEGIN, responsesBuilder, operation)); if (MapUtils.isNotEmpty(responses)) { StringColumn.Builder httpCodeColumnBuilder = StringColumn .builder(StringColumnId.of(labels.getLabel(HTTP_CODE_COLUMN))) .putMetaData(TableComponent.WIDTH_RATIO, "2"); StringColumn.Builder descriptionColumnBuilder = StringColumn .builder(StringColumnId.of(labels.getLabel(DESCRIPTION_COLUMN))) .putMetaData(TableComponent.WIDTH_RATIO, "14") .putMetaData(TableComponent.HEADER_COLUMN, "true"); StringColumn.Builder schemaColumnBuilder = StringColumn .builder(StringColumnId.of(labels.getLabel(SCHEMA_COLUMN))) .putMetaData(TableComponent.WIDTH_RATIO, "4").putMetaData(TableComponent.HEADER_COLUMN, "true"); Map<String, Response> sortedResponses = toSortedMap(responses, config.getResponseOrdering()); sortedResponses.forEach((String responseName, Response response) -> { String schemaContent = labels.getLabel(NO_CONTENT); if (response.getSchema() != null) { Property property = response.getSchema(); Type type = new PropertyAdapter(property).getType(definitionDocumentResolver); if (config.isInlineSchemaEnabled()) { type = createInlineType(type, labels.getLabel(RESPONSE) + " " + responseName, operation.getId() + " " + labels.getLabel(RESPONSE) + " " + responseName, params.inlineDefinitions); }//from w w w. j a va 2 s . co m schemaContent = type.displaySchema(markupDocBuilder); } MarkupDocBuilder descriptionBuilder = copyMarkupDocBuilder(markupDocBuilder); descriptionBuilder.text(markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, response.getDescription())); Map<String, Property> headers = response.getHeaders(); if (MapUtils.isNotEmpty(headers)) { descriptionBuilder.newLine(true).boldText(labels.getLabel(HEADERS_COLUMN)).text(COLON); for (Map.Entry<String, Property> header : headers.entrySet()) { descriptionBuilder.newLine(true); Property headerProperty = header.getValue(); PropertyAdapter headerPropertyAdapter = new PropertyAdapter(headerProperty); Type propertyType = headerPropertyAdapter.getType(null); String headerDescription = markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, headerProperty.getDescription()); Optional<Object> optionalDefaultValue = headerPropertyAdapter.getDefaultValue(); descriptionBuilder.literalText(header.getKey()) .text(String.format(" (%s)", propertyType.displaySchema(markupDocBuilder))); if (isNotBlank(headerDescription) || optionalDefaultValue.isPresent()) { descriptionBuilder.text(COLON); if (isNotBlank(headerDescription) && !headerDescription.endsWith(".")) headerDescription += "."; descriptionBuilder.text(headerDescription); optionalDefaultValue.ifPresent( o -> descriptionBuilder.text(" ").boldText(labels.getLabel(DEFAULT_COLUMN)) .text(COLON).literalText(Json.pretty(o))); } } } httpCodeColumnBuilder.add(boldText(markupDocBuilder, responseName)); descriptionColumnBuilder.add(descriptionBuilder.toString()); schemaColumnBuilder.add(schemaContent); }); responsesBuilder = tableComponent.apply(responsesBuilder, TableComponent.parameters( httpCodeColumnBuilder.build(), descriptionColumnBuilder.build(), schemaColumnBuilder.build())); } applyPathsDocumentExtension(new PathsDocumentExtension.Context( PathsDocumentExtension.Position.OPERATION_RESPONSES_END, responsesBuilder, operation)); String responsesContent = responsesBuilder.toString(); applyPathsDocumentExtension(new PathsDocumentExtension.Context( PathsDocumentExtension.Position.OPERATION_RESPONSES_BEFORE, markupDocBuilder, operation)); if (isNotBlank(responsesContent)) { markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(RESPONSES)); markupDocBuilder.text(responsesContent); } applyPathsDocumentExtension(new PathsDocumentExtension.Context( PathsDocumentExtension.Position.OPERATION_RESPONSES_AFTER, markupDocBuilder, operation)); return markupDocBuilder; }
From source file:ufo.test.spark.service.WordCountServiceTest.java
@Test public void should_return_10_longest_words() { int returnWords = 10; Map<String, Integer> wordsCount = WordCountService.getLongestWords(sparkContext, INPUT_FILE_PATH, returnWords);/*from w w w . ja va 2 s . c o m*/ assertEquals(returnWords, wordsCount.size()); System.out.println("Printing most used words"); wordsCount.forEach((key, value) -> { System.out.println("word [" + key + "] is used " + value + " times"); }); assertTrue(wordsCount.containsKey("www.gutenberg.org/contact")); }
From source file:org.silverpeas.core.calendar.CalendarComponentDiffDescriptor.java
/** * Merges the detected differences into the given component. * @param component the component to merge. * @return true if something has been merged, false otherwise. *//* ww w. j a v a 2 s . c o m*/ @SuppressWarnings("unchecked") boolean mergeInto(CalendarComponent component) { Mutable<Boolean> dataMerged = Mutable.of(false); if (diff.containsKey(TITLE_ATTR)) { component.setTitle((String) diff.get(TITLE_ATTR)); dataMerged.set(true); } if (diff.containsKey(DESCRIPTION_ATTR)) { component.setDescription((String) diff.get(DESCRIPTION_ATTR)); dataMerged.set(true); } if (diff.containsKey(LOCATION_ATTR)) { component.setLocation((String) diff.get(LOCATION_ATTR)); dataMerged.set(true); } if (diff.containsKey(PRIORITY_ATTR)) { component.setPriority((Priority) diff.get(PRIORITY_ATTR)); dataMerged.set(true); } if (diff.containsKey(SAVE_ATTRIBUTE_ATTR)) { Map<String, String> attributesToSave = (Map) diff.get(SAVE_ATTRIBUTE_ATTR); attributesToSave.forEach((key, value) -> component.getAttributes().set(key, value)); dataMerged.set(true); } if (diff.containsKey(REMOVE_ATTRIBUTE_ATTR)) { Set<String> attributesToRemove = (Set) diff.get(REMOVE_ATTRIBUTE_ATTR); attributesToRemove.forEach(a -> component.getAttributes().remove(a)); dataMerged.set(true); } if (diff.containsKey(SAVE_ATTENDEE_ATTR)) { Set<Attendee> attendeesToSave = (Set) diff.get(SAVE_ATTENDEE_ATTR); attendeesToSave.forEach(a -> { Optional<Attendee> attendee = component.getAttendees().get(a.getId()); if (attendee.isPresent()) { attendee.get().setPresenceStatus(a.getPresenceStatus()); } else { component.getAttendees().add(a.cloneFor(component)); } }); dataMerged.set(true); } if (diff.containsKey(REMOVE_ATTENDEE_ATTR)) { Set<Attendee> attendeesToRemove = (Set) diff.get(REMOVE_ATTENDEE_ATTR); attendeesToRemove.forEach(atr -> component.getAttendees().removeIf(a -> a.getId().equals(atr.getId()))); dataMerged.set(true); } if (diff.containsKey(UPDATE_ATTENDEE_STATUS_ATTR)) { Set<Attendee> attendeeStatusesToUpdate = (Set) diff.get(UPDATE_ATTENDEE_STATUS_ATTR); attendeeStatusesToUpdate.forEach(aS -> { Optional<Attendee> attendee = component.getAttendees().get(aS.getId()); attendee.ifPresent(a -> a.setParticipationStatus(aS.getParticipationStatus())); dataMerged.set(attendee.isPresent()); }); } return dataMerged.is(true); }
From source file:ufo.test.spark.service.WordCountServiceTest.java
@Test public void should_return_10_most_used_words() { int returnWords = 10; Map<String, Integer> wordsCount = WordCountService.getMostUsedWords(sparkContext, INPUT_FILE_PATH, returnWords);// w w w. j av a 2s .c o m assertEquals(returnWords, wordsCount.size()); System.out.println("Printing most used words"); wordsCount.forEach((key, value) -> { System.out.println("word [" + key + "] is used " + value + " times"); }); assertTrue(wordsCount.containsKey("the")); assertTrue(wordsCount.containsKey("a")); }
From source file:com.oneops.antenna.senders.slack.SlackService.java
/** * Creates an attachment from the notification message. * * @param msg OneOps notification message. * @param includeFields <code>true</code> if the raw {@link NotificationMessage} * fields need to be included in the attachment. * @return {@link Attachment}//from ww w .ja v a2 s. c o m * @see <a href="https://goo.gl/c4JCBG">Slack Formatting doc</a> */ private Attachment getAttachment(NotificationMessage msg, boolean includeFields) { String env = BOT_NAME; String[] paths = msg.getNsPath().split("/"); if (paths.length >= 4) { env = paths[3]; } String color = getColor(msg.getSeverity()); StringBuilder buf = new StringBuilder(); buf.append(String.format("`%s` | %s | <%s|%s>", env, msg.getType(), URLUtil.getNotificationUrl(msg), msg.getNsPath())); String text = msg.getText(); if (isNotEmpty(text)) { buf.append('\n').append(text); } Attachment attachment = new Attachment().color(color).text(buf.toString()); // Add notification fields if enabled. if (includeFields) { // Filter fields with non empty value. List<Field> nonEmptyFields = new ArrayList<Field>() { { long epocTs = msg.getTimestamp() / 1000; add(new Field("CmsId", msg.getCmsId() + "", true)); add(new Field("Cloud", msg.getCloudName(), true)); add(new Field("EnvProfile", msg.getEnvironmentProfileName(), true)); add(new Field("Severity", msg.getSeverity().getName(), true)); add(new Field("Source", msg.getSource(), true)); add(new Field("TemplateName", msg.getTemplateName(), true)); add(new Field("ManifestCiId", msg.getManifestCiId() + "", true)); add(new Field("AdminStatus", msg.getAdminStatus(), true)); add(new Field("Timestamp", String.format("<!date^%d^{date_num} {time_secs}|%d>", epocTs, epocTs), true)); Map<String, Object> payload = msg.getPayload(); if (payload != null) { payload.forEach((key, value) -> add(new Field(key, String.valueOf(value), true))); } } }.stream().filter((f) -> isNotEmpty(f.getValue())).collect(Collectors.toList()); attachment.fields(nonEmptyFields); } return attachment; }
From source file:org.trustedanalytics.servicebroker.h2o.service.H2oProvisionerClient.java
public H2oProvisionerClient(String memory, String nodesCount, boolean kerberos, Map<String, String> yarnConf, H2oProvisionerRestApi h2oRest) { this.memory = memory; this.nodesCount = nodesCount; this.kerberos = kerberos; this.yarnConf = yarnConf; this.h2oRest = h2oRest; LOGGER.info("YARN CONFIG"); yarnConf.forEach((k, v) -> LOGGER.info(k + ": " + v)); }