Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
../../../../img/srcFileCovDistChart0.png 48% of files have more coverage
55   301   28   2,5
12   116   0,51   22
22     1,27  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  ResponseManager       Line # 48 55 0% 28 89 0% 0.0
 
No Tests
 
1    /*
2    * Copyright (c) 2003-2006, Simon Brown
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * - Redistributions of source code must retain the above copyright
9    * notice, this list of conditions and the following disclaimer.
10    *
11    * - Redistributions in binary form must reproduce the above copyright
12    * notice, this list of conditions and the following disclaimer in
13    * the documentation and/or other materials provided with the
14    * distribution.
15    *
16    * - Neither the name of Pebble nor the names of its contributors may
17    * be used to endorse or promote products derived from this software
18    * without specific prior written permission.
19    *
20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23    * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30    * POSSIBILITY OF SUCH DAMAGE.
31    */
32    package net.sourceforge.pebble.domain;
33   
34    import net.sourceforge.pebble.comparator.ResponseByDateComparator;
35    import net.sourceforge.pebble.api.event.comment.CommentEvent;
36    import net.sourceforge.pebble.api.event.comment.CommentListener;
37    import net.sourceforge.pebble.api.event.trackback.TrackBackEvent;
38    import net.sourceforge.pebble.api.event.trackback.TrackBackListener;
39   
40    import java.util.*;
41   
42    /**
43    * Internal comment and TrackBack listener used to manage the list of
44    * responses for the associated blog.
45    *
46    * @author Simon Brown
47    */
 
48    public class ResponseManager implements CommentListener, TrackBackListener {
49   
50    /** the owning blog */
51    private Blog blog;
52   
53    /** the set of recent comments */
54    private SortedSet recentComments;
55   
56    /** the set of recent TrackBacks */
57    private SortedSet recentTrackBacks;
58   
59    /** the set of recent responses (comments and TrackBacks) */
60    private SortedSet approvedResponses;
61   
62    /** the set of pending responses (comments and TrackBacks) */
63    private SortedSet pendingResponses;
64   
65    /** the set of rejected responses (comments and TrackBacks) */
66    private SortedSet rejectedResponses;
67   
68    /**
69    * Creates a new instance associated with the specified blog.
70    *
71    * @param blog a Blog instance
72    */
 
73  0 toggle public ResponseManager(Blog blog) {
74  0 this.blog = blog;
75   
76  0 recentComments = new TreeSet(new ResponseByDateComparator());
77  0 recentTrackBacks = new TreeSet(new ResponseByDateComparator());
78  0 approvedResponses = new TreeSet(new ResponseByDateComparator());
79  0 pendingResponses = new TreeSet(new ResponseByDateComparator());
80  0 rejectedResponses = new TreeSet(new ResponseByDateComparator());
81    }
82   
83    /**
84    * Gets recent comments.
85    *
86    * @return a collection containing comments that have been left most recently
87    */
 
88  0 toggle public Collection getRecentComments() {
89  0 return this.recentComments;
90    }
91   
92    /**
93    * Gets recent TrackBacks.
94    *
95    * @return a collection containing TrackBacks that have been left most recently
96    */
 
97  0 toggle public Collection getRecentTrackBacks() {
98  0 return this.recentTrackBacks;
99    }
100   
101    /**
102    * Gets recent responses (combined comments and TrackBacks).
103    *
104    * @return a collection containing comments and TrackBacks that have been left
105    * most recently
106    */
 
107  0 toggle public Collection getRecentResponses() {
108  0 List list = new ArrayList();
109  0 list.addAll(approvedResponses);
110  0 return list;
111    }
112   
113    /**
114    * Gets the number of approved responses.
115    *
116    * @return an int
117    */
 
118  0 toggle public int getNumberOfApprovedResponses() {
119  0 return approvedResponses.size();
120    }
121   
122    /**
123    * Gets pending responses (combined comments and TrackBacks).
124    *
125    * @return a collection containing comments and TrackBacks that are pending
126    */
 
127  0 toggle public Collection getPendingResponses() {
128  0 List list = new ArrayList();
129  0 list.addAll(pendingResponses);
130  0 return list;
131    }
132   
133    /**
134    * Gets the number of pending responses.
135    *
136    * @return an int
137    */
 
138  0 toggle public int getNumberOfPendingResponses() {
139  0 return pendingResponses.size();
140    }
141   
142    /**
143    * Gets rejected responses (combined comments and TrackBacks).
144    *
145    * @return a collection containing comments and TrackBacks that are rejected
146    */
 
147  0 toggle public Collection getRejectedResponses() {
148  0 List list = new ArrayList();
149  0 list.addAll(rejectedResponses);
150  0 return list;
151    }
152   
153    /**
154    * Gets the number of rejected responses.
155    *
156    * @return an int
157    */
 
158  0 toggle public int getNumberOfRejectedResponses() {
159  0 return rejectedResponses.size();
160    }
161   
162    /**
163    * Called when a comment has been added.
164    *
165    * @param comment a Comment instance
166    */
 
167  0 toggle synchronized void addRecentComment(Comment comment) {
168  0 if (comment.isApproved()) {
169  0 recentComments.add(comment);
170  0 approvedResponses.add(comment);
171  0 } else if (comment.isPending()) {
172  0 pendingResponses.add(comment);
173  0 } else if (comment.isRejected()) {
174  0 rejectedResponses.add(comment);
175    }
176    }
177   
178    /**
179    * Called when a comment has been removed.
180    *
181    * @param comment a Comment instance
182    */
 
183  0 toggle synchronized void removeRecentComment(Comment comment) {
184  0 recentComments.remove(comment);
185  0 approvedResponses.remove(comment);
186  0 pendingResponses.remove(comment);
187  0 rejectedResponses.remove(comment);
188    }
189   
190    /**
191    * Called when a TrackBack has been added.
192    *
193    * @param trackBack a TrackBack instance
194    */
 
195  0 toggle synchronized void addRecentTrackBack(TrackBack trackBack) {
196  0 if (trackBack.isApproved()) {
197  0 recentTrackBacks.add(trackBack);
198  0 approvedResponses.add(trackBack);
199  0 } else if (trackBack.isPending()) {
200  0 pendingResponses.add(trackBack);
201  0 } else if (trackBack.isRejected()) {
202  0 rejectedResponses.add(trackBack);
203    }
204    }
205   
206    /**
207    * Called when a TrackBack has been removed.
208    *
209    * @param trackBack a TrackBack instance
210    */
 
211  0 toggle synchronized void removeRecentTrackBack(TrackBack trackBack) {
212  0 recentTrackBacks.remove(trackBack);
213  0 approvedResponses.remove(trackBack);
214  0 pendingResponses.remove(trackBack);
215  0 rejectedResponses.remove(trackBack);
216    }
217   
218    /**
219    * Called when a comment has been added.
220    *
221    * @param event a CommentEvent instance
222    */
 
223  0 toggle public void commentAdded(CommentEvent event) {
224  0 addRecentComment(event.getComment());
225    }
226   
227    /**
228    * Called when a comment has been removed.
229    *
230    * @param event a CommentEvent instance
231    */
 
232  0 toggle public void commentRemoved(CommentEvent event) {
233  0 removeRecentComment(event.getComment());
234    }
235   
236    /**
237    * Called when a comment has been approved.
238    *
239    * @param event a CommentEvent instance
240    */
 
241  0 toggle public void commentApproved(CommentEvent event) {
242  0 removeRecentComment(event.getComment());
243  0 addRecentComment(event.getComment());
244    }
245   
246    /**
247    * Called when a comment has been rejected.
248    *
249    * @param event a CommentEvent instance
250    */
 
251  0 toggle public void commentRejected(CommentEvent event) {
252  0 removeRecentComment(event.getComment());
253  0 addRecentComment(event.getComment());
254    }
255   
256    /**
257    * Called when a TrackBack has been added.
258    *
259    * @param event a TrackBackEvent instance
260    */
 
261  0 toggle public void trackBackAdded(TrackBackEvent event) {
262  0 addRecentTrackBack(event.getTrackBack());
263    }
264   
265    /**
266    * Called when a TrackBack has been removed.
267    *
268    * @param event a TrackBackEvent instance
269    */
 
270  0 toggle public void trackBackRemoved(TrackBackEvent event) {
271  0 removeRecentTrackBack(event.getTrackBack());
272    }
273   
274    /**
275    * Called when a TrackBack has been approved.
276    *
277    * @param event a TrackBackEvent instance
278    */
 
279  0 toggle public void trackBackApproved(TrackBackEvent event) {
280  0 removeRecentTrackBack(event.getTrackBack());
281  0 addRecentTrackBack(event.getTrackBack());
282    }
283   
284    /**
285    * Called when a TrackBack has been rejected.
286    *
287    * @param event a TrackBackEvent instance
288    */
 
289  0 toggle public void trackBackRejected(TrackBackEvent event) {
290  0 removeRecentTrackBack(event.getTrackBack());
291  0 addRecentTrackBack(event.getTrackBack());
292    }
293   
294    /**
295    * Gets the number of responses.
296    */
 
297  0 toggle public int getNumberOfResponses() {
298  0 return approvedResponses.size() + pendingResponses.size() + rejectedResponses.size();
299    }
300   
301    }