View Javadoc

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