1 17 18 21 package org.quartz.impl.calendar; 22 23 import java.io.Serializable ; 24 import java.util.Collections ; 25 import java.util.Date ; 26 import java.util.SortedSet ; 27 import java.util.TimeZone ; 28 import java.util.TreeSet ; 29 30 import org.quartz.Calendar; 31 32 47 public class HolidayCalendar extends BaseCalendar implements Calendar, 48 Serializable { 49 static final long serialVersionUID = -7590908752291814693L; 50 51 private TreeSet dates = new TreeSet (); 53 54 public HolidayCalendar() { 55 } 56 57 public HolidayCalendar(Calendar baseCalendar) { 58 super(baseCalendar); 59 } 60 61 public HolidayCalendar(TimeZone timeZone) { 62 super(timeZone); 63 } 64 65 public HolidayCalendar(Calendar baseCalendar, TimeZone timeZone) { 66 super(baseCalendar, timeZone); 67 } 68 69 79 public boolean isTimeIncluded(long timeStamp) { 80 if (super.isTimeIncluded(timeStamp) == false) { 81 return false; 82 } 83 84 Date lookFor = getStartOfDayJavaCalendar(timeStamp).getTime(); 85 86 return !(dates.contains(lookFor)); 87 } 88 89 99 public long getNextIncludedTime(long timeStamp) { 100 101 long baseTime = super.getNextIncludedTime(timeStamp); 103 if ((baseTime > 0) && (baseTime > timeStamp)) { 104 timeStamp = baseTime; 105 } 106 107 java.util.Calendar day = getStartOfDayJavaCalendar(timeStamp); 109 while (isTimeIncluded(day.getTime().getTime()) == false) { 110 day.add(java.util.Calendar.DATE, 1); 111 } 112 113 return day.getTime().getTime(); 114 } 115 116 122 public void addExcludedDate(Date excludedDate) { 123 Date date = getStartOfDayJavaCalendar(excludedDate.getTime()).getTime(); 124 128 this.dates.add(date); 129 } 130 131 public void removeExcludedDate(Date dateToRemove) { 132 Date date = getStartOfDayJavaCalendar(dateToRemove.getTime()).getTime(); 133 dates.remove(date); 134 } 135 136 143 public SortedSet getExcludedDates() { 144 return Collections.unmodifiableSortedSet(dates); 145 } 146 } 147 | Popular Tags |