Compare commits
2 Commits
381e3cc9ac
...
53cda5688f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
53cda5688f | ||
|
|
8a7ce73739 |
@@ -58,17 +58,11 @@ public abstract class Notification {
|
|||||||
public String getContent() {
|
public String getContent() {
|
||||||
if (isSendable() && content != "") {
|
if (isSendable() && content != "") {
|
||||||
transitionState();
|
transitionState();
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
|
|
||||||
if (decorations.isEmpty())
|
|
||||||
return content;
|
|
||||||
|
|
||||||
builder.append(content);
|
|
||||||
|
|
||||||
for (final NotificationDecoration decoration : decorations)
|
for (final NotificationDecoration decoration : decorations)
|
||||||
builder.append(decoration.transformContent());
|
content = decoration.transformContent(content);
|
||||||
|
|
||||||
return builder.toString();
|
return content;
|
||||||
}
|
}
|
||||||
setKoState();
|
setKoState();
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class DateNotificationDecoration extends NotificationDecoration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String transformContent() {
|
public String transformContent(String content) {
|
||||||
return ": " + date.toString();
|
return date.toString() + ": " + content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,20 +2,10 @@ package notificationsDecorations;
|
|||||||
|
|
||||||
import entities.Notification;
|
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 {
|
public abstract class NotificationDecoration {
|
||||||
protected Notification notification;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Each decoration apply a transformation on the content of the Notifications
|
* Each decoration apply a transformation on the content of the Notifications
|
||||||
* @return the content transformed
|
* @return the content transformed
|
||||||
*/
|
*/
|
||||||
public abstract String transformContent();
|
public abstract String transformContent(String content);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public class WatermarkNotificationDecoration extends NotificationDecoration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String transformContent() {
|
public String transformContent(String content) {
|
||||||
return "\n" + waterMark;
|
return content + "\n" + waterMark;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class NotificationObservable {
|
|||||||
for (final var subscriber : this.subscribers) {
|
for (final var subscriber : this.subscribers) {
|
||||||
for (final var notificationType : subscriber.notificationsTypes()) {
|
for (final var notificationType : subscriber.notificationsTypes()) {
|
||||||
var notification = factory.createNotification(notificationType, content, subscriber, subscriber.chosenNotificationStrategy());
|
var notification = factory.createNotification(notificationType, content, subscriber, subscriber.chosenNotificationStrategy());
|
||||||
// Ici j'applique automatiquement les décorations, évidement, il serait mieux de la faire dynamiquement.
|
|
||||||
BaseDecorator decorator = new WatermarkDecorator(new DateDecorator(notification, new Date()), "Thomas");
|
BaseDecorator decorator = new WatermarkDecorator(new DateDecorator(notification, new Date()), "Thomas");
|
||||||
System.out.println(decorator.getContent());
|
System.out.println(decorator.getContent());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user