KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > schedules > schedules > IntervalSchedule


1 package org.oddjob.schedules.schedules;
2
3 import java.io.Serializable JavaDoc;
4 import java.text.ParseException JavaDoc;
5 import java.util.Date JavaDoc;
6
7 import org.oddjob.schedules.RegularSchedule;
8 import org.oddjob.util.DateHelper;
9
10 /**
11  * @oddjob.description This schedule returns an interval
12  * from the given time to the interval time later.
13  * Commonly used within a {@link TimeSchedule} schedule.
14  *
15  * @oddjob.example
16  *
17  * <pre>
18  * &lt;interval interval="00:20" /&gt;
19  * </pre>
20  *
21  * @author Rob Gordon
22  */

23
24 final public class IntervalSchedule extends RegularSchedule implements Serializable JavaDoc {
25
26     private static final long serialVersionUID = 20050226;
27     
28     /**
29      * Milliseconds for the interval.
30      */

31     private Long JavaDoc intervalMillis;
32
33     /**
34      * @oddjob.property interval
35      * @oddjob.description The interval time.
36      * @oddjob.required No but defaults to forever.
37      *
38      * @param interval The interval.
39      * @throws ParseException If the interval is not a valid date.
40      */

41     public void setInterval(String JavaDoc interval) throws ParseException JavaDoc {
42         intervalMillis = new Long JavaDoc(DateHelper.parseTime(interval));
43     }
44
45     /*
46      * (non-Javadoc)
47      * @see org.treesched.RegularSchedule#next(java.util.Date)
48      */

49     public Date JavaDoc next(Date JavaDoc from) {
50         if (intervalMillis == null) {
51             return new Date JavaDoc(Long.MAX_VALUE);
52         }
53         return new Date JavaDoc(from.getTime() + intervalMillis.longValue());
54     }
55 }
56
Popular Tags