1 package org.oddjob.schedules; 2 3 import java.io.Serializable ; 4 import java.util.ArrayList ; 5 import java.util.Date ; 6 import java.util.Iterator ; 7 import java.util.List ; 8 9 import org.apache.log4j.Logger; 10 11 27 28 final public class ScheduleList implements Serializable , RefineableSchedule { 29 private static final long serialVersionUID = 20051125; 30 31 private static final Logger logger = Logger.getLogger(ScheduleList.class); 32 33 34 private final List schedules = new ArrayList (); 35 36 37 private transient Interval limits; 38 39 43 public void setLimits(Interval limits) { 44 this.limits = limits; 45 } 46 47 52 public Interval getLimits() { 53 return limits; 54 } 55 56 61 public int size() { 62 return schedules.size(); 63 } 64 65 70 public void addValueSchedule(Schedule schedule) { 71 schedules.add(schedule); 72 } 73 74 78 public Interval nextDue(ScheduleContext context) { 79 Date now = context.getDate(); 80 81 logger.debug(this + ": in date " + now); 82 Interval candidate = null; 83 84 int i = 1; 85 for (Iterator it = schedules.iterator(); it.hasNext(); ++i) { 86 Schedule schedule = (Schedule)it.next(); 87 88 logger.debug(this + ": evaluating schedule " + i + " (" + schedule + ")"); 89 90 schedule.setLimits(limits); 91 Interval nextDue = schedule.nextDue(context); 92 if (nextDue != null) { 93 if (limits != null) { 94 nextDue = nextDue.limit(limits); 95 } 96 if (candidate == null || nextDue.isBefore(candidate)) { 97 candidate = nextDue; 98 } 99 } 100 } 101 logger.debug(this + ": returning " + candidate); 102 return candidate; 103 } 104 105 110 public String toString() { 111 return "ScheduleList, size=" + schedules.size(); 112 } 113 } 114 | Popular Tags |