Clover Coverage Report - Kuali Student 1.3.0-SNAPSHOT (Aggregated)
Coverage timestamp: Thu Apr 28 2011 05:03:32 EDT
../../../../../../../img/srcFileCovDistChart0.png 2% of files have more coverage
68   275   35   2.72
4   186   0.51   25
25     1.4  
1    
 
  Calendar       Line # 30 68 0% 35 97 0% 0.0
 
No Tests
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
14    */
15   
16    package org.kuali.student.lum.common.client.widgets;
17   
18    import java.util.Date;
19   
20    /**
21    * <dl>
22    * <dt><b>Title: </b><dd>Calendar</dd>
23    * <p>
24    * <dt><b>Description: </b><dd>java.util.Calendar replacment</dd>
25    * </dl>
26    * @author <a href="mailto:andre.freller@gmail.com">Andre Freller</a>
27    * @version $Revision: 0.1 $
28    */
29    ///////// ///////// ///////// ///////// ///////// ///////// ///////// ///////// ///////// ///////// ///////// /////////
 
30    public abstract class Calendar
31    {
32    public static final int AM = 0;
33    public static final int AM_PM = 9;
34    public static final int PM = 1;
35   
36    public static final int JANUARY = 0;
37    public static final int FEBRUARY = 1;
38    public static final int MARCH = 2;
39    public static final int APRIL = 3;
40    public static final int MAY = 4;
41    public static final int JUNE = 5;
42    public static final int JULY = 6;
43    public static final int AUGUST = 7;
44    public static final int SEPTEMBER = 8;
45    public static final int OCTOBER = 9;
46    public static final int NOVEMBER = 10;
47    public static final int DECEMBER = 11;
48    public static final int UNDECIMBER = 12;
49   
50    public static final int SUNDAY = 1;
51    public static final int MONDAY = 2;
52    public static final int TUESDAY = 3;
53    public static final int WEDNESDAY = 4;
54    public static final int THURSDAY = 5;
55    public static final int FRIDAY = 6;
56    public static final int SATURDAY = 7;
57   
58   
59    public static final int ERA = 0;
60    public static final int YEAR = 1;
61    public static final int MONTH = 2;
62    public static final int WEEK_OF_YEAR = 3;
63    public static final int WEEK_OF_MONTH = 4;
64    public static final int DATE = 5;
65    public static final int DAY_OF_MONTH = DATE;
66    public static final int DAY_OF_YEAR = 6;
67    public static final int DAY_OF_WEEK = 7;
68    public static final int DAY_OF_WEEK_IN_MONTH = 8;
69    public static final int HOUR = 10;
70    public static final int HOUR_OF_DAY = 11;
71    public static final int MINUTE = 12;
72    public static final int SECOND = 13;
73    public static final int MILLISECOND = 14;
74    public static final int ZONE_OFFSET = 15;
75    public static final int DST_OFFSET = 16;
76    public static final int FIELD_COUNT = 17;
77   
78   
79    // fields
80    protected Date date = null;
81    protected int second = -1;
82    protected int minute = -1;
83    protected int hour = -1;
84    protected int dayOfMonth = -1;
85    protected int month = -1;
86    protected int year = -1;
87    protected int amPm = -1;
88   
89    protected int firstWeekDayOfWeek = Calendar.SUNDAY;
90   
 
91  0 toggle protected Calendar() {
92  0 setTime(new Date());
93    }
94   
95    // Sets this Calendar's current time with the given Date.
 
96  0 toggle public void setTime(Date date) {
97  0 this.date = date;
98  0 computeFields();
99    }
 
100  0 toggle public void setTime(Calendar cal) {
101  0 this.date = cal.getTime();
102  0 computeFields();
103    }
104    // Sets this Calendar's current time from the given long value.
 
105  0 toggle public void setTimeInMillis(long milliSeconds) {
106  0 this.date.setTime(milliSeconds);
107  0 computeFields();
108    }
109    // Sets the values for the fields year, month, and day.
 
110  0 toggle public void set(int year, int month, int dayOfMonth) {
111  0 this.year = year;
112  0 this.month = month;
113  0 this.dayOfMonth = dayOfMonth;
114  0 computeTime();
115    }
116    // Sets the values for the fields year, month, day, hour, and minute.
 
117  0 toggle public void set(int year, int month, int dayOfMonth, int hour) {
118  0 this.year = year;
119  0 this.month = month;
120  0 this.dayOfMonth = dayOfMonth;
121  0 this.hour = hour;
122  0 computeTime();
123    }
124    // Sets the values for the fields year, month, day, hour, and minute.
 
125  0 toggle public void set(int year, int month, int dayOfMonth, int hour, int minute) {
126  0 this.year = year;
127  0 this.month = month;
128  0 this.dayOfMonth = dayOfMonth;
129  0 this.hour = hour;
130  0 this.minute = minute;
131  0 computeTime();
132    }
133    // Sets the values for the fields year, month, day, hour, minute, and second.
 
134  0 toggle public void set(int year, int month, int dayOfMonth, int hour, int minute, int second) {
135  0 this.year = year;
136  0 this.month = month;
137  0 this.dayOfMonth = dayOfMonth;
138  0 this.hour = hour;
139  0 this.minute = minute;
140  0 this.second = second;
141  0 computeTime();
142    }
143    // Sets the time field with the given value.
 
144  0 toggle public void set(int fieldCode, String value) {
145  0 set(fieldCode, Integer.parseInt(value));
146    }
147    public abstract void set(int fieldCode, int value);
148   
149    // Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
 
150  0 toggle public void setFirstWeekDayOfWeek(int firstWeekDayOfWeek) {
151  0 this.firstWeekDayOfWeek = firstWeekDayOfWeek;
152    }
153   
154   
155    // Gets this Calendar's current time.
 
156  0 toggle public Date getTime() {
157  0 return this.date;
158    }
159    // Gets this Calendar's current time as a long.
 
160  0 toggle public long getTimeInMillis() {
161  0 return this.date.getTime();
162    }
163   
164   
165    // Gets the value for a given time field.
 
166  0 toggle public int get(int fieldCode) {
167  0 switch (fieldCode) {
168  0 case Calendar.SECOND:
169  0 return this.second;
170  0 case Calendar.MINUTE:
171  0 return this.minute;
172  0 case Calendar.HOUR:
173  0 return this.hour;
174  0 case Calendar.HOUR_OF_DAY:
175  0 if (this.amPm == Calendar.PM)
176  0 return this.hour + 12;
177  0 return this.hour;
178  0 case Calendar.DATE:
179  0 return this.dayOfMonth;
180  0 case Calendar.MONTH:
181  0 return this.month;
182  0 case Calendar.YEAR:
183  0 return this.year;
184  0 case Calendar.AM_PM:
185  0 return this.amPm;
186  0 default:
187  0 return -1;
188    }
189    }
190    // Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
 
191  0 toggle public int getFirstWeekDayOfWeek() {
192  0 return this.firstWeekDayOfWeek;
193    }
194   
195   
196   
197    // Compares the time field records.
 
198  0 toggle public boolean before(Date when) {
199  0 return this.date.before(when);
200    }
 
201  0 toggle public boolean before(Calendar when) {
202  0 return this.date.before(when.getTime());
203    }
 
204  0 toggle public boolean after(Date when) {
205  0 return this.date.after(when);
206    }
 
207  0 toggle public boolean after(Calendar when) {
208  0 return this.date.after(when.getTime());
209    }
 
210  0 toggle public boolean equals(Date obj) {
211  0 return this.date.equals(obj);
212    }
 
213  0 toggle public boolean equals(Calendar obj) {
214  0 return this.date.equals(obj.getTime());
215    }
216    // Determines if the given time field has a value set.
 
217  0 toggle public boolean isSet(int fieldCode) {
218  0 return true;
219    }
220   
221   
222    // Time Field Rolling function.
 
223  0 toggle public void roll(int fieldCode, boolean up) {
224  0 if (up)
225  0 roll(fieldCode, 1);
226    else
227  0 roll(fieldCode, -1);
228    }
229   
230    // Fills in any unset fields in the time field list.
 
231  0 toggle protected void complete() {
232  0 computeFields();
233    }
234   
235    // Returns a hash code for this calendar.
 
236  0 toggle public int hashCode() {
237  0 return this.date.hashCode();
238    }
239    // Return a string representation of this calendar.
 
240  0 toggle public String toString() {
241  0 return this.date.toString();
242    }
243   
244   
245   
246    // Converts the current millisecond time value time to field values in fields[].
247    protected abstract void computeFields();
248   
249    // Converts the current field values in fields[] to the millisecond time value time.
250    protected abstract void computeTime();
251   
252   
253    // Gets the minimum value for the given time field.
254    public abstract int getMinimum(int fieldCode);
255    // Return the minimum value that this field could have, given the current date.
256    public abstract int getActualMinimum(int fieldCode);
257    // Gets the highest minimum value for the given field if varies.
258    public abstract int getGreatestMinimum(int fieldCode);
259   
260    // Gets the maximum value for the given time field.
261    public abstract int getMaximum(int fieldCode);
262    // Return the maximum value that this field could have, given the current date.
263    public abstract int getActualMaximum(int fieldCode);
264    // Gets the lowest maximum value for the given field if varies.
265    public abstract int getLeastMaximum(int fieldCode);
266   
267   
268    // Date Arithmetic function.
269    public abstract void add(int fieldCode, int amount);
270   
271    // Time Field Rolling function.
272    public abstract void roll(int fieldCode, int amount);
273   
274   
275    } // end of class Calendar