Feat: Decoration can transform notification content more freely
Some checks failed
SonarQube Scan / SonarQube Trigger (push) Failing after 19s
Some checks failed
SonarQube Scan / SonarQube Trigger (push) Failing after 19s
This commit is contained in:
@@ -58,17 +58,11 @@ public abstract class Notification {
|
||||
public String getContent() {
|
||||
if (isSendable() && content != "") {
|
||||
transitionState();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
if (decorations.isEmpty())
|
||||
return content;
|
||||
|
||||
builder.append(content);
|
||||
|
||||
for (final NotificationDecoration decoration : decorations)
|
||||
builder.append(decoration.transformContent());
|
||||
content = decoration.transformContent(content);
|
||||
|
||||
return builder.toString();
|
||||
return content;
|
||||
}
|
||||
setKoState();
|
||||
return "";
|
||||
|
||||
@@ -11,7 +11,7 @@ public class DateNotificationDecoration extends NotificationDecoration {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String transformContent() {
|
||||
return ": " + date.toString();
|
||||
public String transformContent(String content) {
|
||||
return date.toString() + ": " + content;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,20 +2,10 @@ package notificationsDecorations;
|
||||
|
||||
import entities.Notification;
|
||||
|
||||
/**
|
||||
* On cherche à pouvoir ajouter des décorations aux notifications.
|
||||
*
|
||||
* Pour ce faire, on part de cette classe abstraite qui permettra de faire du polymorphisme.
|
||||
*
|
||||
* Ensuite, les décorateurs ajouteront une décoration aux notifications qui ont une liste de
|
||||
* décorations.
|
||||
*/
|
||||
public abstract class NotificationDecoration {
|
||||
protected Notification notification;
|
||||
|
||||
/**
|
||||
* Each decoration apply a transformation on the content of the Notifications
|
||||
* @return the content transformed
|
||||
*/
|
||||
public abstract String transformContent();
|
||||
public abstract String transformContent(String content);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ public class WatermarkNotificationDecoration extends NotificationDecoration {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String transformContent() {
|
||||
return "\n" + waterMark;
|
||||
public String transformContent(String content) {
|
||||
return content + "\n" + waterMark;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user