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 (default implementation). * 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(); } }