From: David ‘Bombe’ Roden Date: Tue, 5 Apr 2011 07:57:19 +0000 (+0200) Subject: Add copy constructor. X-Git-Tag: 0.6.1^2~42 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=5dfc6973e3f089ddc33327ad42fe25142150c206;p=Sone.git Add copy constructor. --- diff --git a/src/main/java/net/pterodactylus/sone/notify/ListNotification.java b/src/main/java/net/pterodactylus/sone/notify/ListNotification.java index 2f43c58..2217b70 100644 --- a/src/main/java/net/pterodactylus/sone/notify/ListNotification.java +++ b/src/main/java/net/pterodactylus/sone/notify/ListNotification.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.notify; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; @@ -33,6 +34,9 @@ import net.pterodactylus.util.template.Template; */ public class ListNotification extends TemplateNotification { + /** The key under which to store the elements in the template. */ + private final String key; + /** The list of new elements. */ private final List elements = new CopyOnWriteArrayList(); @@ -48,9 +52,24 @@ public class ListNotification extends TemplateNotification { */ public ListNotification(String id, String key, Template template) { super(id, template); + this.key = key; template.getInitialContext().set(key, elements); } + /** + * Creates a new list notification that copies its ID and the template from + * the given list notification. + * + * @param listNotification + * The list notification to copy + */ + public ListNotification(ListNotification listNotification) { + super(listNotification.getId(), new Template()); + this.key = listNotification.key; + getTemplate().add(listNotification.getTemplate()); + getTemplate().getInitialContext().set(key, elements); + } + // // ACTIONS //