Clover Coverage Report - AnCal Coverage Report
Coverage timestamp: gio dic 18 2014 12:18:42 EST
../../../../img/srcFileCovDistChart9.png 40% of files have more coverage
117   292   58   5,85
54   215   0,5   20
20     2,9  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  RepeatData       Line # 8 117 58 83,8% 0.8376963
 
No Tests
 
1   
2    package pl.magot.vetch.ancal;
3   
4   
5    import java.util.Calendar;
6   
7   
 
8    public class RepeatData
9    {
10    //fields
11    //RepeatType
12    // 0: None
13    // 1: Daily
14    // 2: Weekly
15    // 3: Monthly
16    // 4: Yearly
17    private final int iRepeatTypeMin = 0;
18    private final int iRepeatTypeMax = 4;
19   
20    //fields
21    private int iRepeatType = 0;
22    private int iEvery = 1; //repeat frequency (every day/week/month)
23   
24    //cached values
25    private RepeatDataValue dvStartDate = new RepeatDataValue();
26    private RepeatDataValue dvTestDate = new RepeatDataValue();
27   
28    //fields
29    private Calendar calEndOnDate = Calendar.getInstance();
30   
31    //cached values
32    private long lEndDateMs = 0;
33    private int lEndDate_DST_OFFSET = 0;
34   
35    //methods
 
36  39 toggle public RepeatData()
37    {
38    }
39   
 
40  443 toggle public void SetStartDate(Calendar value)
41    {
42  443 dvStartDate.getFromCalendar(value);
43    }
44   
 
45  9 toggle public int GetEvery()
46    {
47  9 return iEvery;
48    }
49   
 
50  4512 toggle public boolean UsingEndOnDate()
51    {
52  4512 return (lEndDateMs > 0);
53    }
54   
 
55  8 toggle public Calendar GetEndOnDate()
56    {
57  8 return calEndOnDate;
58    }
59   
 
60  11 toggle public int GetRepeatTypeAsInt()
61    {
62  11 return iRepeatType;
63    }
64   
 
65  835 toggle public void SetEvery(int value)
66    {
67  835 iEvery = value;
68    }
69   
 
70  447 toggle public void SetEndOnDate(Calendar value)
71    {
72  447 if (value == null)
73    {
74  446 calEndOnDate.setTimeInMillis(0);
75  446 lEndDateMs = 0;
76    } else {
77  1 calEndOnDate.set(value.get(Calendar.YEAR), value.get(Calendar.MONTH), value.get(Calendar.DAY_OF_MONTH), 12, 0, 0);
78  1 calEndOnDate.set(Calendar.MILLISECOND, 0);
79  1 lEndDateMs = calEndOnDate.getTimeInMillis();
80    }
81   
82  447 lEndDate_DST_OFFSET = calEndOnDate.get(Calendar.DST_OFFSET);
83    }
84   
 
85  140 toggle public void SetEndOnDate(long value)
86    {
87  140 if (value == 0)
88    {
89  6 calEndOnDate.setTimeInMillis(0);
90  6 lEndDateMs = 0;
91    } else {
92  134 calEndOnDate.setTimeInMillis(value);
93  134 calEndOnDate.set(Calendar.HOUR_OF_DAY, 12);
94  134 calEndOnDate.set(Calendar.MINUTE, 0);
95  134 calEndOnDate.set(Calendar.SECOND, 0);
96  134 calEndOnDate.set(Calendar.MILLISECOND, 0);
97  134 lEndDateMs = value;
98    }
99   
100  140 lEndDate_DST_OFFSET = calEndOnDate.get(Calendar.DST_OFFSET);
101    }
102   
 
103  454 toggle public void SetRepeatTypeAsInt(int value)
104    {
105  454 if (value < iRepeatTypeMin)
106  0 value = iRepeatTypeMin;
107  454 if (value > iRepeatTypeMax)
108  0 value = iRepeatTypeMax;
109  454 iRepeatType = value;
110    }
111   
112    //date part compare, returns diffrence value
 
113  4062 toggle private int GetDayDiff()
114    {
115    //calc days
116  4062 long lMsDiff = (dvStartDate.lMS - (dvTestDate.lMS + dvTestDate.lDST_OFFSET));
117  4062 return (int)(lMsDiff / 86400000);
118    }
119   
 
120  103 toggle private int GetMonthDiff()
121    {
122  103 int iYears = dvTestDate.iYear - dvStartDate.iYear;
123  103 int iMonths = dvTestDate.iMonth - dvStartDate.iMonth;
124  103 iMonths += (iYears * 12);
125  103 return iMonths;
126    }
127   
 
128  4506 toggle private boolean IsDateOutOfEnd()
129    {
130  4506 if (UsingEndOnDate())
131    {
132    //calc days
133  1377 long lMsDiff = (dvTestDate.lMS - (lEndDateMs + lEndDate_DST_OFFSET));
134  1377 float iDays = (lMsDiff / 86400000);
135  1377 if ((int)iDays > 0)
136  98 return true;
137    }
138  4408 return false;
139    }
140   
 
141  444 toggle private boolean IsDateEqualOnce()
142    {
143  444 boolean bResult = false;
144   
145  444 if (dvStartDate.iDay == dvTestDate.iDay)
146  48 if (dvStartDate.iMonth == dvTestDate.iMonth)
147  46 if (dvStartDate.iYear == dvTestDate.iYear)
148  46 bResult = true;
149   
150  444 if (IsDateOutOfEnd())
151  0 bResult = false;
152   
153  444 return bResult;
154    }
155   
 
156  15 toggle private boolean IsDateEqualDaily()
157    {
158  15 boolean bResult = false;
159   
160    //check if date in range
161  15 int iDays = GetDayDiff();
162  15 if (iDays <= 0)
163  3 if ((iDays % iEvery) == 0)
164  3 bResult = true;
165   
166  15 if (IsDateOutOfEnd())
167  0 bResult = false;
168   
169  15 return bResult;
170    }
171   
 
172  1362 toggle private boolean IsDateEqualWeekly()
173    {
174  1362 boolean bResult = false;
175   
176    //check if date in range
177  1362 int iDays = GetDayDiff();
178  1362 if (iDays <= 0)
179    {
180  47 int iModValue = iEvery * 7;
181  47 if ((((iDays % iModValue) <= 0) && ((iDays % iModValue) >= -6)))
182    {
183  33 if (dvStartDate.iDayOfWeek == dvTestDate.iDayOfWeek)
184  15 bResult = true;
185    }
186    }
187   
188  1362 if (IsDateOutOfEnd())
189  0 bResult = false;
190   
191  1362 return bResult;
192    }
193   
 
194  1377 toggle private boolean IsDateEqualMonthly()
195    {
196  1377 boolean bResult = false;
197   
198    //check if date in range
199  1377 int iDays = GetDayDiff();
200  1377 if (iDays <= 0)
201    {
202  918 int iMonthDay = dvStartDate.iDay;
203   
204  918 if (iMonthDay > dvTestDate.iMaxMonthDay)
205  0 iMonthDay = dvTestDate.iMaxMonthDay;
206   
207  918 if (dvTestDate.iDay == iMonthDay)
208    {
209  103 int iMonths = GetMonthDiff();
210  103 if ((iMonths % iEvery) == 0)
211  94 bResult = true;
212    }
213    }
214   
215  1377 if (IsDateOutOfEnd())
216  98 bResult = false;
217   
218  1377 return bResult;
219    }
220   
 
221  1308 toggle private boolean IsDateEqualYearly()
222    {
223  1308 boolean bResult = false;
224   
225    //check if date in range
226  1308 int iDays = GetDayDiff();
227  1308 if (iDays <= 0)
228    {
229    //compare months
230  0 if (dvStartDate.iMonth == dvTestDate.iMonth)
231    {
232  0 int iMonthDay = dvStartDate.iDay;
233   
234  0 if (iMonthDay > dvTestDate.iMaxMonthDay)
235  0 iMonthDay = dvTestDate.iMaxMonthDay;
236   
237  0 if (dvTestDate.iDay == iMonthDay)
238  0 bResult = true;
239    }
240    }
241   
242  1308 if (IsDateOutOfEnd())
243  0 bResult = false;
244   
245  1308 return bResult;
246    }
247   
 
248  145 toggle public boolean IsDateEqual(Calendar value)
249    {
250  145 dvTestDate.getFromCalendar(value);
251   
252    //test case
253  145 switch (iRepeatType)
254    {
255  10 case 0: //None
256  10 return IsDateEqualOnce();
257  1 case 1: //Daily
258  1 return IsDateEqualDaily();
259  46 case 2: //Weekly
260  46 return IsDateEqualWeekly();
261  47 case 3: //Monthly:
262  47 return IsDateEqualMonthly();
263  41 case 4: //Yearly:
264  41 return IsDateEqualYearly();
265    }
266   
267  0 return false;
268    }
269   
 
270  4361 toggle public boolean IsDateEqual(RepeatDataValue value)
271    {
272  4361 dvTestDate = value;
273   
274    //test case
275  4361 switch (iRepeatType)
276    {
277  434 case 0: //None
278  434 return IsDateEqualOnce();
279  14 case 1: //Daily
280  14 return IsDateEqualDaily();
281  1316 case 2: //Weekly
282  1316 return IsDateEqualWeekly();
283  1330 case 3: //Monthly:
284  1330 return IsDateEqualMonthly();
285  1267 case 4: //Yearly:
286  1267 return IsDateEqualYearly();
287    }
288   
289  0 return false;
290    }
291   
292    }