1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.eventstream

File EventGroup.java

 

Coverage histogram

../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

12
23
9
1
143
69
16
0.7
2.56
9
1.78

Classes

Class Line # Actions
EventGroup 33 23 0% 16 2
0.9545454495.5%
 

Contributing tests

This file is covered by 9 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.eventstream;
21   
22    import java.util.Collections;
23    import java.util.LinkedHashSet;
24    import java.util.List;
25    import java.util.Set;
26   
27    /**
28    * A group of related events, all happening as a consequence of the same action.
29    *
30    * @version $Id: 05fdc0f8424d70eefc6246887099801b586cc1c6 $
31    * @since 3.0M2
32    */
 
33    public class EventGroup
34    {
35    /** The events inside this group. */
36    private Set<Event> events = new LinkedHashSet<Event>();
37   
38    /** Default constructor that creates an empty event group. */
 
39  9 toggle public EventGroup()
40    {
41    // Nothing to do
42    }
43   
44    /**
45    * Constructor that creates a group containing the passed events.
46    *
47    * @param events the list of initial events to put in the group
48    */
 
49  3 toggle public EventGroup(List<Event> events)
50    {
51  3 if (events != null) {
52  2 this.events.addAll(events);
53  2 this.events.remove(null);
54    }
55    }
56   
57    /**
58    * Constructor that creates a group containing the passed events.
59    *
60    * @param events the list of initial events to put in the group
61    */
 
62  4 toggle public EventGroup(Set<Event> events)
63    {
64  4 if (events != null) {
65  3 this.events.addAll(events);
66  3 this.events.remove(null);
67    }
68    }
69   
70    /**
71    * Constructor that creates a group containing the passed events.
72    *
73    * @param events the list of initial events to put in the group
74    */
 
75  3 toggle public EventGroup(Event... events)
76    {
77  3 if (events != null) {
78  2 for (Event e : events) {
79  6 if (e != null) {
80  4 this.events.add(e);
81    }
82    }
83    }
84    }
85   
86    /**
87    * List the events that are part of this group.
88    *
89    * @return a read only snapshot of the events in this group; future changes in this group will not be reflected in
90    * the returned snapshot
91    */
 
92  43 toggle public Set<Event> getEvents()
93    {
94  43 Set<Event> clone = new LinkedHashSet<Event>(this.events.size(), 1f);
95  43 clone.addAll(this.events);
96  43 return Collections.unmodifiableSet(clone);
97    }
98   
99    /**
100    * Add more events to this group. Duplicate events are added only once, since this is a {@link Set}.
101    *
102    * @param events the new events to add
103    */
 
104  28 toggle public void addEvents(Event... events)
105    {
106  28 for (Event e : events) {
107  37 if (e != null) {
108  35 this.events.add(e);
109    }
110    }
111    }
112   
113    /** Remove all the events from this group. */
 
114  8 toggle public void clearEvents()
115    {
116  8 this.events.clear();
117    }
118   
119    /**
120    * Get the most important event in this group. The "importance" is given by the {@link Event#getImportance()
121    * importance} property of events. If more events have the same maximal importance, the first one found in the group
122    * is returned. Usually this corresponds to the order the events were created, but this is not a guaranteed
123    * property.
124    *
125    * @return the most important event found in this group, {@code null} if the group is empty.
126    */
 
127  14 toggle public Event getMainEvent()
128    {
129  14 Event result = null;
130  14 for (Event e : this.events) {
131  22 if (result == null || e.getImportance().ordinal() > result.getImportance().ordinal()) {
132  14 result = e;
133    }
134    }
135  14 return result;
136    }
137   
 
138  0 toggle @Override
139    public String toString()
140    {
141  0 return this.events.toString();
142    }
143    }