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
41   212   21   3,42
14   81   0,51   12
12     1,75  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  Year       Line # 43 41 0% 21 13 80,6% 0.80597013
 
  (272)
 
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.util.Calendar;
35    import java.util.List;
36    import java.util.LinkedList;
37   
38    /**
39    * Represents a blog at a yearly level. This manages a collection of Month instances.
40    *
41    * @author Simon Brown
42    */
 
43    public class Year extends TimePeriod implements Comparable {
44   
45    /** the year that this blog is for */
46    private int year;
47   
48    /** a collection of the monthly blogs that this instance is managing */
49    private Month[] months;
50   
51    /**
52    * Creates a new Year instance for the specified year.
53    *
54    * @param blog the Blog on which this Year is based
55    * @param year the year that this Year is for
56    */
 
57  352 toggle public Year(Blog blog, int year) {
58  352 super(blog);
59   
60  352 this.year = year;
61  352 init();
62    }
63   
64    /**
65    * Initialises internal data, such as the collection of Month instances.
66    */
 
67  352 toggle private void init() {
68  352 setDate(getCalendar().getTime());
69  352 this.months = new Month[12];
70   
71  4576 for (int i = 1; i <= 12; i++) {
72  4224 months[i-1] = new Month(this, i);
73    }
74    }
75   
 
76  352 toggle private Calendar getCalendar() {
77    // set the date corresponding to the 1st of January of the specified year
78  352 Calendar cal = getBlog().getCalendar();
79  352 cal.set(Calendar.YEAR, year);
80  352 cal.set(Calendar.MONTH, 0);
81  352 cal.set(Calendar.DAY_OF_MONTH, 2);
82  352 cal.set(Calendar.HOUR_OF_DAY, 0);
83  352 cal.set(Calendar.MINUTE, 0);
84  352 cal.set(Calendar.SECOND, 0);
85  352 cal.set(Calendar.MILLISECOND, 0);
86   
87  352 return cal;
88    }
89   
90    /**
91    * Gets an integer representing the year that this yearly blog is for.
92    *
93    * @return an int representing the year (e.g. 2003)
94    */
 
95  135018 toggle public int getYear() {
96  135018 return year;
97    }
98   
99    /**
100    * Gets the Month for the specified month. Months are lazy
101    * loaded as needed.
102    *
103    * @param month the month as an int
104    * @return a Month instance
105    */
 
106  1118 toggle public synchronized Month getBlogForMonth(int month) {
107   
108    // some bounds checking
109  1118 if (month < 1 || month > 12) {
110  6 throw new IllegalArgumentException("Invalid month of " + month + " specified, should be between 1 and 12");
111    }
112   
113  1112 return months[month-1];
114    }
115   
116    /**
117    * Given a Month, this method returns the Month instance for the
118    * previous month.
119    *
120    * @param month a Month instance
121    * @return a Month instance representing the previous month
122    */
 
123  6 toggle Month getBlogForPreviousMonth(Month month) {
124  6 if (month.getMonth() > 1) {
125  4 return this.getBlogForMonth(month.getMonth() - 1);
126    } else {
127  2 return getBlog().getBlogForPreviousYear(this).getBlogForMonth(12);
128    }
129    }
130   
131    /**
132    * Given a Month, this method returns the Month instance for the
133    * next month.
134    *
135    * @param month a Month instance
136    * @return a Month instance representing the next month
137    */
 
138  6 toggle Month getBlogForNextMonth(Month month) {
139  6 if (month.getMonth() < 12) {
140  4 return this.getBlogForMonth(month.getMonth() + 1);
141    } else {
142  2 return getBlog().getBlogForNextYear(this).getBlogForMonth(1);
143    }
144    }
145   
146    /**
147    * Gets the first Month that actually contains blog entries.
148    *
149    * @return a Month instance
150    */
 
151  2 toggle public Month getBlogForFirstMonth() {
152  2 return getBlogForMonth(1);
153    }
154   
155    /**
156    * Gets a collection of all Months managed by this blog.
157    *
158    * @return a Collection of Month instances
159    */
 
160  22 toggle public Month[] getMonths() {
161  22 Month[] months = new Month[12];
162  286 for (int i = 1; i <= 12; i++) {
163  264 months[i-1] = getBlogForMonth(i);
164    }
165   
166  22 return months;
167    }
168   
169    /**
170    * Gets a collection of all Months, to date and in reverse order.
171    *
172    * @return a Collection of Month instances
173    */
 
174  0 toggle public List<Month> getArchives() {
175  0 List<Month> list = new LinkedList<Month>();
176  0 Month thisMonth = getBlog().getBlogForThisMonth();
177  0 Month firstMonth = getBlog().getBlogForFirstMonth();
178  0 for (int i = 12; i >=1; i--) {
179  0 Month month = getBlogForMonth(i);
180  0 if (!month.after(thisMonth) && !month.before(firstMonth)) {
181  0 list.add(month);
182    }
183    }
184   
185  0 return list;
186    }
187   
188    /**
189    * Compares this object with the specified object for order. Returns a
190    * negative integer, zero, or a positive integer as this object is less
191    * than, equal to, or greater than the specified object.<p>
192    *
193    * @param o the Object to be compared.
194    * @return a negative integer, zero, or a positive integer as this object
195    * is less than, equal to, or greater than the specified object.
196    * @throws ClassCastException if the specified object's type prevents it
197    * from being compared to this Object.
198    */
 
199  52 toggle public int compareTo(Object o) {
200  52 return this.getYear() - ((Year)o).getYear();
201    }
202   
203    /**
204    * Gets a string representation of this object.
205    *
206    * @return a String
207    */
 
208  2 toggle public String toString() {
209  2 return "" + this.year;
210    }
211   
212    }