From e03b55be17261ed13ddf421bcf4a804a083a7614 Mon Sep 17 00:00:00 2001 From: Thorsten Ortlepp Date: Fri, 26 Apr 2024 00:30:46 +0200 Subject: added implementation --- .../service/NotificationSender.java | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/main/java/eu/ortlepp/notificationsender/service/NotificationSender.java (limited to 'src/main/java/eu/ortlepp/notificationsender/service/NotificationSender.java') diff --git a/src/main/java/eu/ortlepp/notificationsender/service/NotificationSender.java b/src/main/java/eu/ortlepp/notificationsender/service/NotificationSender.java new file mode 100644 index 0000000..8c39c72 --- /dev/null +++ b/src/main/java/eu/ortlepp/notificationsender/service/NotificationSender.java @@ -0,0 +1,41 @@ +package eu.ortlepp.notificationsender.service; + +import java.util.List; + +/** + * Interface for notification senders. + */ +public interface NotificationSender { + + /** + * Send a list of notifications. + * + * @param notifications The notifications to send + * @return The result of the sending; true = successful, false = error occurred + */ + boolean sendNotifications(final List notifications); + + + /** + * Format notifications for sending. + * If only one notification is passed, it is returned as is. + * If multiple notifications are passed, a numbered list of notifications is returned. + * + * @param notifications The notifications to format + * @return The formatted notifications + */ + default String formatNotifications(final List notifications) { + if (notifications.size() == 1) { + return notifications.getFirst() + "\n\n"; + } + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < notifications.size(); i++) { + builder.append(i + 1) + .append(". Notification:\n") + .append(notifications.get(i)) + .append("\n\n"); + } + return builder.toString(); + } + +} -- cgit v1.2.3