1 package com.atlassian.johnson;
2
3 import com.atlassian.johnson.event.Event;
4
5 import javax.servlet.ServletContext;
6 import java.util.Collections;
7 import java.util.List;
8 import java.util.concurrent.CopyOnWriteArrayList;
9
10 /**
11 * A default implementation of {@link JohnsonEventContainer} which stores events in a list.
12 * <p/>
13 * Note: This implementation is thread-safe.
14 *
15 * @since 2.0
16 */
17 public class DefaultJohnsonEventContainer implements JohnsonEventContainer
18 {
19 private final List<Event> events = new CopyOnWriteArrayList<Event>();
20
21 /**
22 * Adds the provided {@link Event} to the list.
23 *
24 * @param event the event to add
25 */
26 @Override
27 public void addEvent(Event event)
28 {
29 events.add(event);
30 }
31
32 /**
33 * Retrieves an <i>unmodifiable</i> view of the current {@link Event} list.
34 *
35 * @return an unmodifiable collection of zero or more events
36 */
37 @Override
38 public List<Event> getEvents()
39 {
40 return Collections.unmodifiableList(events);
41 }
42
43 /**
44 * Retrieves a flag indicating whether there are any {@link Event}s in the list.
45 *
46 * @return {@link true} if the event list is not empty; otherwise, {@code false}
47 */
48 @Override
49 public boolean hasEvents()
50 {
51 return !events.isEmpty();
52 }
53
54 /**
55 * Removes the provided {@link Event} from the list, if it can be found.
56 *
57 * @param event the event to remove
58 */
59 @Override
60 public void removeEvent(Event event)
61 {
62 events.remove(event);
63 }
64 }