blob: 94d44620c594d8f7731a938efa22576c85ee286b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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<String> 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<String> 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();
}
}
|