X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fnotify%2FListNotification.java;h=2f43c582c41231d16ec318e88a5ccc0de5898a70;hb=ee05a67b3f1e796b6c4bdcd709ef0983103c455f;hp=64c2ecbac0240a19f0bff32d1ef431e5fd7bf612;hpb=2889127f645d17c4ae0a650e935d1481d9cbd727;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/notify/ListNotification.java b/src/main/java/net/pterodactylus/sone/notify/ListNotification.java index 64c2ecb..2f43c58 100644 --- a/src/main/java/net/pterodactylus/sone/notify/ListNotification.java +++ b/src/main/java/net/pterodactylus/sone/notify/ListNotification.java @@ -18,8 +18,8 @@ package net.pterodactylus.sone.notify; import java.util.ArrayList; -import java.util.Collections; import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; import net.pterodactylus.util.notify.TemplateNotification; import net.pterodactylus.util.template.Template; @@ -34,7 +34,7 @@ import net.pterodactylus.util.template.Template; public class ListNotification extends TemplateNotification { /** The list of new elements. */ - private final List elements = Collections.synchronizedList(new ArrayList()); + private final List elements = new CopyOnWriteArrayList(); /** * Creates a new list notification. @@ -48,7 +48,7 @@ public class ListNotification extends TemplateNotification { */ public ListNotification(String id, String key, Template template) { super(id, template); - template.set(key, elements); + template.getInitialContext().set(key, elements); } // @@ -56,6 +56,15 @@ public class ListNotification extends TemplateNotification { // /** + * Returns the current list of elements. + * + * @return The current list of elements + */ + public List getElements() { + return new ArrayList(elements); + } + + /** * Returns whether there are any new elements. * * @return {@code true} if there are no new elements, {@code false} if there @@ -84,6 +93,9 @@ public class ListNotification extends TemplateNotification { */ public void remove(T element) { elements.remove(element); + if (elements.isEmpty()) { + dismiss(); + } touch(); }