Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
../../../../img/srcFileCovDistChart8.png 29% of files have more coverage
61   310   30   3,05
16   122   0,49   20
20     1,5  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  Month       Line # 42 61 0% 30 28 71,1% 0.7113402
 
  (270)
 
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 java.text.SimpleDateFormat;
35    import java.util.*;
36   
37    /**
38    * Represents a blog at a monthly level. This manages a collection of Day instances.
39    *
40    * @author Simon Brown
41    */
 
42    public class Month extends TimePeriod implements Permalinkable {
43   
44    /** the parent, Year instance */
45    private Year year;
46   
47    /** an integer representing the month that this Month is for */
48    private int month;
49   
50    /** the collection of Day instances that this blog is managing */
51    private Day[] dailyBlogs;
52   
53    /** the last day in this month */
54    private int lastDayInMonth;
55   
56    /**
57    * Creates a new Month based upon the specified Year and month.
58    *
59    * @param year the owning Year instance
60    * @param month the month as an int
61    */
 
62  4264 toggle Month(Year year, int month) {
63  4264 super(year.getBlog());
64   
65  4264 this.year = year;
66  4264 this.month = month;
67  4264 setDate(getCalendar().getTime());
68   
69  4264 Calendar cal = getBlog().getCalendar();
70  4264 cal.setTime(getDate());
71  4264 this.lastDayInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
72   
73    // and create all days
74  4264 dailyBlogs = new Day[lastDayInMonth];
75  134006 for (int day = 1; day <= lastDayInMonth; day++) {
76  129742 dailyBlogs[day-1] = new Day(this, day);
77    }
78    }
79   
 
80  4264 toggle private Calendar getCalendar() {
81    // set the date corresponding to the 1st of the month
82    // (this is used in determining whether another Month is
83    // before or after this one)
84  4264 Calendar cal = getBlog().getCalendar();
85  4264 cal.set(Calendar.YEAR, year.getYear());
86  4264 cal.set(Calendar.MONTH, month - 1);
87  4264 cal.set(Calendar.DAY_OF_MONTH, 1);
88  4264 cal.set(Calendar.HOUR_OF_DAY, 0);
89  4264 cal.set(Calendar.MINUTE, 0);
90  4264 cal.set(Calendar.SECOND, 0);
91  4264 cal.set(Calendar.MILLISECOND, 0);
92   
93  4264 return cal;
94    }
95   
96    /**
97    * Gets a reference to the parent Year instance.
98    *
99    * @return a Year instance
100    */
 
101  129782 toggle public Year getYear() {
102  129782 return year;
103    }
104   
105    /**
106    * Gets an integer representing the month that this monthly blog is for.
107    *
108    * @return an int representing the month (i.e. 1 to 12)
109    */
 
110  130070 toggle public int getMonth() {
111  130070 return month;
112    }
113   
114    /**
115    * Gets the permalink to display all entries for this Month.
116    *
117    * @return an absolute URL
118    */
 
119  4 toggle public String getPermalink() {
120  4 String s = getBlog().getPermalinkProvider().getPermalink(this);
121  4 if (s != null && s.length() > 0) {
122  4 return getBlog().getUrl() + s.substring(1);
123    } else {
124  0 return "";
125    }
126    }
127   
128    /**
129    * Determines whether this monthly blog has entries.
130    *
131    * @return true if this blog contains entries, false otherwise
132    */
 
133  0 toggle public boolean hasBlogEntries() {
134  0 for (int i = 1; i <= lastDayInMonth; i++) {
135  0 if (getBlogForDay(i).hasBlogEntries()) {
136  0 return true;
137    }
138    }
139   
140  0 return false;
141    }
142   
143    /**
144    * Gets all blog entries for this month.
145    *
146    * @return a List of BlogEntry instances, reverse ordered by date
147    */
 
148  266 toggle public List<String> getBlogEntries() {
149  266 Day days[] = getAllDays();
150  266 List blogEntries = new ArrayList();
151  266 for (Day day : days) {
152  8092 blogEntries.addAll(day.getBlogEntries());
153    }
154  266 return blogEntries;
155    }
156   
157    /**
158    * Gets the number of blog entries for this month.
159    *
160    * @return an int
161    */
 
162  0 toggle public int getNumberOfBlogEntries() {
163  0 int count = 0;
164  0 Day days[] = getAllDays();
165  0 for (Day day : days) {
166  0 count += day.getNumberOfBlogEntries();
167    }
168   
169  0 return count;
170    }
171   
172    /**
173    * Gets an array of all Days.
174    *
175    * @return a Collection of Day instances for all those days
176    * that have entries (this can return an empty collection)
177    */
 
178  268 toggle public Day[] getAllDays() {
179  268 Day blogs[] = new Day[dailyBlogs.length];
180  8422 for (int day = 0; day < dailyBlogs.length; day++) {
181  8154 blogs[day] = getBlogForDay(day + 1);
182    }
183   
184  268 return blogs;
185    }
186   
187    /**
188    * Gets a Day instance for the specified day. This lazy loads Day
189    * instances as needed.
190    *
191    * @param day the day as an int (i.e. 1 to 31)
192    * @return the corresponding Day instance
193    */
 
194  8726 toggle public synchronized Day getBlogForDay(int day) {
195    // some bounds checking
196  8726 if (day < 1 || day > lastDayInMonth) {
197  6 throw new IllegalArgumentException("Invalid day of " + day + " specified, should be between 1 and " + lastDayInMonth);
198    }
199   
200  8720 return dailyBlogs[day-1];
201    }
202   
203    /**
204    * Gets a Day instance for the first day of the month.
205    *
206    * @return the Day instance representing the first day in the month
207    */
 
208  6 toggle public Day getBlogForFirstDay() {
209  6 return getBlogForDay(1);
210    }
211   
212    /**
213    * Gets a Day instance for the last day of the month.
214    *
215    * @return the Day instance representing the last day in the month
216    */
 
217  0 toggle public Day getBlogForLastDay() {
218  0 return getBlogForDay(lastDayInMonth);
219    }
220   
221    /**
222    * Gets the last day of the month.
223    *
224    * @return an int representing the last day in the month
225    */
 
226  8 toggle public int getLastDayInMonth() {
227  8 return lastDayInMonth;
228    }
229   
230    /**
231    * Gets the Month instance for the previous month.
232    *
233    * @return a Month instance
234    */
 
235  6 toggle public Month getPreviousMonth() {
236  6 return year.getBlogForPreviousMonth(this);
237    }
238   
239    /**
240    * Gets the Month instance for the next month.
241    *
242    * @return a Month instance
243    */
 
244  6 toggle public Month getNextMonth() {
245  6 return year.getBlogForNextMonth(this);
246    }
247   
248    /**
249    * Determines if the this Month is before (in the calendar) the
250    * specified Month.
251    *
252    * @return true if this instance represents an earlier month than the
253    * specified Month instance, false otherwise
254    */
 
255  10 toggle public boolean before(Month month) {
256  10 return getDate().before(month.getDate());
257    }
258   
259    /**
260    * Determines if the this Month is after (in the calendar) the
261    * specified Month.
262    *
263    * @return true if this instance represents a later month than the
264    * specified Month instance, false otherwise
265    */
 
266  0 toggle public boolean after(Month month) {
267  0 return getDate().after(month.getDate());
268    }
269   
270    /**
271    * Given a Day, this method returns the Day instance for the
272    * previous day.
273    *
274    * @param day a Day instance
275    * @return a Day instance representing the previous day
276    */
 
277  34 toggle Day getBlogForPreviousDay(Day day) {
278  34 if (day.getDay() > 1) {
279  34 return this.getBlogForDay(day.getDay() - 1);
280    } else {
281  0 return year.getBlogForPreviousMonth(this).getBlogForLastDay();
282    }
283    }
284   
285    /**
286    * Given a Day, this method returns the Day instance for the
287    * next day.
288    *
289    * @param day a Day instance
290    * @return a Day instance representing the next day
291    */
 
292  4 toggle Day getBlogForNextDay(Day day) {
293  4 if (day.getDay() < lastDayInMonth) {
294  4 return this.getBlogForDay(day.getDay() + 1);
295    } else {
296  0 return year.getBlogForNextMonth(this).getBlogForFirstDay();
297    }
298    }
299   
300    /**
301    * Gets a string representation of this object.
302    *
303    * @return a String
304    */
 
305  0 toggle public String toString() {
306  0 SimpleDateFormat sdf = new SimpleDateFormat("MMMM");
307  0 return sdf.format(getDate());
308    }
309   
310    }