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;
public class ListNotification<T> extends TemplateNotification {
/** The list of new elements. */
- private final List<T> elements = Collections.synchronizedList(new ArrayList<T>());
+ private final List<T> elements = new CopyOnWriteArrayList<T>();
/**
* Creates a new list notification.
*/
public ListNotification(String id, String key, Template template) {
super(id, template);
- template.set(key, elements);
+ template.getInitialContext().set(key, elements);
}
//
//
/**
+ * Returns the current list of elements.
+ *
+ * @return The current list of elements
+ */
+ public List<T> getElements() {
+ return new ArrayList<T>(elements);
+ }
+
+ /**
* Returns whether there are any new elements.
*
* @return {@code true} if there are no new elements, {@code false} if there
*/
public void remove(T element) {
elements.remove(element);
+ if (elements.isEmpty()) {
+ dismiss();
+ }
touch();
}